Commit f1a9ebdf authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Restore audio normalise feature in track thumbnail

parent ad132601
Pipeline #62848 passed with stage
in 8 minutes and 22 seconds
......@@ -1796,6 +1796,23 @@ void ProjectClip::setRating(uint rating)
pCore->currentDoc()->setModified(true);
}
int ProjectClip::getAudioMax(int stream)
{
const QString key = QString("kdenlive:audio_max%1").arg(stream);
if (m_masterProducer->property_exists(key.toUtf8().constData())) {
return m_masterProducer->get_int(key.toUtf8().constData());
}
// Process audio max for the stream
const QString key2 = QString("_kdenlive:audio%1").arg(stream);
const QVector <uint8_t> audioData = *static_cast<QVector<uint8_t> *>(m_masterProducer->get_data(key2.toUtf8().constData()));
if (audioData.isEmpty()) {
return 0;
}
uint max = *std::max_element(audioData.constBegin(), audioData.constEnd());
m_masterProducer->set(key.toUtf8().constData(), int(max));
return int(max);
}
const QVector <uint8_t> ProjectClip::audioFrameCache(int stream)
{
QVector <uint8_t> audioLevels;
......@@ -1806,7 +1823,7 @@ const QVector <uint8_t> ProjectClip::audioFrameCache(int stream)
return audioLevels;
}
}
QString key = QString("_kdenlive:audio%1").arg(stream);
const QString key = QString("_kdenlive:audio%1").arg(stream);
if (m_masterProducer->get_data(key.toUtf8().constData())) {
const QVector <uint8_t> audioData = *static_cast<QVector<uint8_t> *>(m_masterProducer->get_data(key.toUtf8().constData()));
return audioData;
......
......@@ -245,6 +245,8 @@ public:
/** @brief If a clip is invalid on load, mark it as such so we don't try to re-insert it on undo/redo. */
void setInvalid();
int getRecordTime();
/** @brief Return maximum audio level for a stream. */
int getAudioMax(int stream);
protected:
friend class ClipModel;
......
......@@ -408,14 +408,16 @@ const QVector<uint8_t> ProjectItemModel::getAudioLevelsByBinID(const QString &bi
return QVector<uint8_t>();
}
double ProjectItemModel::getAudioMaxLevel(const QString &binId)
double ProjectItemModel::getAudioMaxLevel(const QString &binId, int stream)
{
READ_LOCK();
for (const auto &clip : m_allItems) {
auto c = std::static_pointer_cast<AbstractProjectItem>(clip.second.lock());
if (c->itemType() == AbstractProjectItem::ClipItem && c->clipId() == binId) {
int volume = std::static_pointer_cast<ProjectClip>(c)->getProducerIntProperty(QStringLiteral("kdenlive:audio_max"));
return volume > 1 ? qSqrt(volume) : volume;
auto clip = std::static_pointer_cast<ProjectClip>(c);
if (clip) {
return clip->getAudioMax(stream);
}
}
}
return 0;
......
......@@ -71,7 +71,7 @@ public:
std::shared_ptr<ProjectClip> getClipByBinID(const QString &binId);
/** @brief Returns audio levels for a clip from its id */
const QVector <uint8_t>getAudioLevelsByBinID(const QString &binId, int stream);
double getAudioMaxLevel(const QString &binId);
double getAudioMaxLevel(const QString &binId, int stream);
/** @brief Returns a list of clips using the given url */
QStringList getClipByUrl(const QFileInfo &url) const;
......
......@@ -214,6 +214,8 @@ void AudioLevelsTask::run()
QVector <uint8_t>* levelsCopy = new QVector <uint8_t>(mltLevels);
producer->lock();
QString key = QString("_kdenlive:audio%1").arg(stream);
QString key2 = QString("kdenlive:audio_max%1").arg(stream);
producer->set(key2.toUtf8().constData(), int(maxLevel));
producer->set(key.toUtf8().constData(), levelsCopy, 0, (mlt_destructor) deleteQVariantList);
producer->unlock();
qDebug()<<"=== FINISHED PRODUCING AUDIO FOR: "<<key<<", SIZE: "<<levelsCopy->size();
......
......@@ -118,7 +118,7 @@ public:
}
});
connect(this, &TimelineWaveform::propertyChanged, [&]() {
m_audioMax = KdenliveSettings::normalizechannels() ? 0 : pCore->projectItemModel()->getAudioMaxLevel(m_binId);
m_audioMax = KdenliveSettings::normalizechannels() ? pCore->projectItemModel()->getAudioMaxLevel(m_binId, m_stream) : 0;
update();
});
}
......@@ -145,10 +145,10 @@ public:
}
if (m_audioLevels.isEmpty() && m_stream >= 0) {
m_audioLevels = pCore->projectItemModel()->getAudioLevelsByBinID(m_binId, m_stream);
m_audioMax = KdenliveSettings::normalizechannels() ? 0 : pCore->projectItemModel()->getAudioMaxLevel(m_binId);
if (m_audioLevels.isEmpty()) {
return;
}
m_audioMax = KdenliveSettings::normalizechannels() ? pCore->projectItemModel()->getAudioMaxLevel(m_binId, m_stream) : 0;
}
if (m_outPoint == m_inPoint) {
......@@ -172,7 +172,7 @@ public:
painter->setPen(pen);
double scaleFactor = 255;
if (m_audioMax > 1) {
scaleFactor *= m_audioMax;
scaleFactor = m_audioMax;
}
int startPos = int(m_inPoint / indicesPrPixel);
if (!KdenliveSettings::displayallchannels()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment