diff --git a/src/timeline2/view/qml/timelineitems.cpp b/src/timeline2/view/qml/timelineitems.cpp --- a/src/timeline2/view/qml/timelineitems.cpp +++ b/src/timeline2/view/qml/timelineitems.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include const QStringList chanelNames{"L", "R", "C", "LFE", "BL", "BR"}; @@ -96,13 +97,13 @@ //setRenderTarget(QQuickPaintedItem::FramebufferObject); //setMipmap(true); setTextureSize(QSize(1, 1)); - connect(this, &TimelineWaveform::levelsChanged, [&]() { + connect(this, &TimelineWaveform::levelsChanged, [this]() { if (!m_binId.isEmpty() && m_audioLevels.isEmpty()) { - m_audioLevels = pCore->projectItemModel()->getAudioLevelsByBinID(m_binId); + updateAudioLevels(); update(); } }); - connect(this, &TimelineWaveform::propertyChanged, [&]() { + connect(this, &TimelineWaveform::propertyChanged, [this]() { update(); }); } @@ -129,7 +130,7 @@ return; } if (m_audioLevels.isEmpty()) { - m_audioLevels = pCore->projectItemModel()->getAudioLevelsByBinID(m_binId); + updateAudioLevels(); if (m_audioLevels.isEmpty()) { return; } @@ -156,9 +157,9 @@ continue; } lastIdx = idx; - level = m_audioLevels.at(idx) / 256; + level = m_audioLevels.at(idx); for (int j = 1; j < m_channels; j++) { - level = qMax(level, m_audioLevels.at(idx + j) / 256); + level = qMax(level, m_audioLevels.at(idx + j)); } path.lineTo(i, height() - level * height()); } @@ -220,6 +221,17 @@ void audioChannelsChanged(); private: + void updateAudioLevels() + { + m_audioLevels = pCore->projectItemModel()->getAudioLevelsByBinID(m_binId); + if (m_audioLevels.isEmpty()) { + return; + } + + const double maxLevel = *std::max_element(m_audioLevels.begin(), m_audioLevels.end()); + for (double &v : m_audioLevels) v /= maxLevel; + } + QVector m_audioLevels; int m_inPoint; int m_outPoint;