From efc66e24d4420ff9e5bad9c351fb6489576d3a96 Mon Sep 17 00:00:00 2001 From: Antonio Napolitano Date: Fri, 24 Mar 2023 00:38:55 +0100 Subject: [PATCH] Revert "Merge pull request #11162 from daschuer/waveformscale" This reverts commit cfcd265afd0ae70c0f6259b00f8fc5dd4ef38379, reversing changes made to c8fb3bbfdfbe839643f645058aad9ce0630c39d5. --- src/track/track.cpp | 2 +- src/track/track.h | 2 +- .../renderers/glslwaveformrenderersignal.cpp | 50 +++++++++---------- .../renderers/glvsynctestrenderer.cpp | 23 +++------ .../glwaveformrendererfilteredsignal.cpp | 21 +++----- .../renderers/glwaveformrendererrgb.cpp | 21 +++----- .../glwaveformrenderersimplesignal.cpp | 21 +++----- .../renderers/qtvsynctestrenderer.cpp | 13 +++-- .../qtwaveformrendererfilteredsignal.cpp | 25 +++------- .../qtwaveformrenderersimplesignal.cpp | 26 ++++------ src/waveform/renderers/waveformrenderbeat.cpp | 6 +-- .../waveformrendererfilteredsignal.cpp | 25 +++------- .../renderers/waveformrendererhsv.cpp | 30 ++++------- .../renderers/waveformrendererpreroll.cpp | 4 +- .../renderers/waveformrendererrgb.cpp | 30 ++++------- src/waveform/renderers/waveformrendermark.cpp | 12 ++--- .../renderers/waveformwidgetrenderer.cpp | 37 +++++++------- .../renderers/waveformwidgetrenderer.h | 7 +-- src/waveform/waveform.h | 6 +++ src/widget/woverview.h | 4 -- src/widget/woverviewhsv.cpp | 7 +-- src/widget/woverviewlmh.cpp | 7 +-- src/widget/woverviewrgb.cpp | 13 +++-- 23 files changed, 158 insertions(+), 234 deletions(-) diff --git a/src/track/track.cpp b/src/track/track.cpp index a8aa63f2650..f324cbb9f52 100644 --- a/src/track/track.cpp +++ b/src/track/track.cpp @@ -772,7 +772,7 @@ QString Track::getURL() const { return m_record.getUrl(); } -const ConstWaveformPointer& Track::getWaveform() const { +ConstWaveformPointer Track::getWaveform() const { return m_waveform; } diff --git a/src/track/track.h b/src/track/track.h index 8d3e11361a4..9c38e35d277 100644 --- a/src/track/track.h +++ b/src/track/track.h @@ -214,7 +214,7 @@ class Track : public QObject { /// any metadata in file tags. Otherwise just the title (even if it is empty). QString getTitleInfo() const; - const ConstWaveformPointer& getWaveform() const; + ConstWaveformPointer getWaveform() const; void setWaveform(ConstWaveformPointer pWaveform); ConstWaveformPointer getWaveformSummary() const; diff --git a/src/waveform/renderers/glslwaveformrenderersignal.cpp b/src/waveform/renderers/glslwaveformrenderersignal.cpp index 18561a8115a..b7a443cdd97 100644 --- a/src/waveform/renderers/glslwaveformrenderersignal.cpp +++ b/src/waveform/renderers/glslwaveformrenderersignal.cpp @@ -78,14 +78,18 @@ bool GLSLWaveformRendererSignal::loadShaders() { } bool GLSLWaveformRendererSignal::loadTexture() { + TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); + ConstWaveformPointer waveform; int dataSize = 0; const WaveformData* data = nullptr; - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform) { - dataSize = pWaveform->getDataSize(); - if (dataSize > 1) { - data = pWaveform->data(); + if (trackInfo) { + waveform = trackInfo->getWaveform(); + if (waveform) { + dataSize = waveform->getDataSize(); + if (dataSize > 1) { + data = waveform->data(); + } } } @@ -110,11 +114,11 @@ bool GLSLWaveformRendererSignal::loadTexture() { glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - if (pWaveform != nullptr && data != nullptr) { + if (waveform != nullptr && data != nullptr) { // Waveform ensures that getTextureSize is a multiple of // getTextureStride so there is no rounding here. - int textureWidth = pWaveform->getTextureStride(); - int textureHeight = pWaveform->getTextureSize() / pWaveform->getTextureStride(); + int textureWidth = waveform->getTextureStride(); + int textureHeight = waveform->getTextureSize() / waveform->getTextureStride(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); @@ -218,7 +222,7 @@ void GLSLWaveformRendererSignal::onSetTrack() { slotWaveformUpdated(); - const TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); + TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); if (!pTrack) { return; } @@ -252,31 +256,26 @@ void GLSLWaveformRendererSignal::slotWaveformUpdated() { } void GLSLWaveformRendererSignal::draw(QPainter* painter, QPaintEvent* /*event*/) { - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { + TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); + if (!trackInfo) { return; } - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (audioVisualRatio <= 0) { + ConstWaveformPointer waveform = trackInfo->getWaveform(); + if (waveform.isNull()) { return; } - int dataSize = pWaveform->getDataSize(); + int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return; } - const int trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { - return; - } - maybeInitializeGL(); // save the GL state set for QPainter @@ -284,7 +283,7 @@ void GLSLWaveformRendererSignal::draw(QPainter* painter, QPaintEvent* /*event*/) // NOTE(vRince): completion can change during loadTexture // do not remove currenCompletion temp variable ! - const int currentCompletion = pWaveform->getCompletion(); + const int currentCompletion = waveform->getCompletion(); if (m_textureRenderedWaveformCompletion < currentCompletion) { loadTexture(); m_textureRenderedWaveformCompletion = currentCompletion; @@ -295,10 +294,9 @@ void GLSLWaveformRendererSignal::draw(QPainter* painter, QPaintEvent* /*event*/) getGains(&allGain, &lowGain, &midGain, &highGain); const auto firstVisualIndex = static_cast( - m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / - audioVisualRatio / 2.0); + m_waveformRenderer->getFirstDisplayedPosition() * dataSize / 2.0); const auto lastVisualIndex = static_cast( - m_waveformRenderer->getLastDisplayedPosition() * trackSamples / audioVisualRatio / 2.0); + m_waveformRenderer->getLastDisplayedPosition() * dataSize / 2.0); // const int firstIndex = int(firstVisualIndex+0.5); // firstVisualIndex = firstIndex - firstIndex%2; @@ -331,8 +329,8 @@ void GLSLWaveformRendererSignal::draw(QPainter* painter, QPaintEvent* /*event*/) m_frameShaderProgram->setUniformValue("framebufferSize", QVector2D( m_framebuffer->width(), m_framebuffer->height())); m_frameShaderProgram->setUniformValue("waveformLength", dataSize); - m_frameShaderProgram->setUniformValue("textureSize", pWaveform->getTextureSize()); - m_frameShaderProgram->setUniformValue("textureStride", pWaveform->getTextureStride()); + m_frameShaderProgram->setUniformValue("textureSize", waveform->getTextureSize()); + m_frameShaderProgram->setUniformValue("textureStride", waveform->getTextureStride()); m_frameShaderProgram->setUniformValue("firstVisualIndex", firstVisualIndex); m_frameShaderProgram->setUniformValue("lastVisualIndex", lastVisualIndex); diff --git a/src/waveform/renderers/glvsynctestrenderer.cpp b/src/waveform/renderers/glvsynctestrenderer.cpp index d39e36dbb28..3a9e9a42d26 100644 --- a/src/waveform/renderers/glvsynctestrenderer.cpp +++ b/src/waveform/renderers/glvsynctestrenderer.cpp @@ -34,35 +34,28 @@ void GLVSyncTestRenderer::draw(QPainter* painter, QPaintEvent* /*event*/) { timer.start(); - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { + TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); + if (!pTrack) { return; } - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (audioVisualRatio <= 0) { + ConstWaveformPointer waveform = pTrack->getWaveform(); + if (waveform.isNull()) { return; } - const int dataSize = pWaveform->getDataSize(); + const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return; } - const int trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { - return; - } - - double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * - trackSamples / audioVisualRatio; - double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * - trackSamples / audioVisualRatio; + double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize; + double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize; const int firstIndex = int(firstVisualIndex + 0.5); firstVisualIndex = firstIndex - firstIndex % 2; diff --git a/src/waveform/renderers/glwaveformrendererfilteredsignal.cpp b/src/waveform/renderers/glwaveformrendererfilteredsignal.cpp index 75b3f39cf5f..24d9bc798c4 100644 --- a/src/waveform/renderers/glwaveformrendererfilteredsignal.cpp +++ b/src/waveform/renderers/glwaveformrendererfilteredsignal.cpp @@ -25,35 +25,30 @@ void GLWaveformRendererFilteredSignal::onSetup(const QDomNode& /*node*/) { void GLWaveformRendererFilteredSignal::draw(QPainter* painter, QPaintEvent* /*event*/) { maybeInitializeGL(); - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { + TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); + if (!pTrack) { return; } - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (audioVisualRatio <= 0) { + ConstWaveformPointer waveform = pTrack->getWaveform(); + if (waveform.isNull()) { return; } - const int dataSize = pWaveform->getDataSize(); + const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return; } - const int trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { - return; - } - auto firstVisualIndex = static_cast( - m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / audioVisualRatio); + m_waveformRenderer->getFirstDisplayedPosition() * dataSize); auto lastVisualIndex = static_cast( - m_waveformRenderer->getLastDisplayedPosition() * trackSamples / audioVisualRatio); + m_waveformRenderer->getLastDisplayedPosition() * dataSize); const auto lineWidth = static_cast( 1.0 / m_waveformRenderer->getVisualSamplePerPixel() + 1); diff --git a/src/waveform/renderers/glwaveformrendererrgb.cpp b/src/waveform/renderers/glwaveformrendererrgb.cpp index e6323a19c91..dcfe74a3e3b 100644 --- a/src/waveform/renderers/glwaveformrendererrgb.cpp +++ b/src/waveform/renderers/glwaveformrendererrgb.cpp @@ -27,35 +27,30 @@ void GLWaveformRendererRGB::onSetup(const QDomNode& /* node */) { void GLWaveformRendererRGB::draw(QPainter* painter, QPaintEvent* /*event*/) { maybeInitializeGL(); - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { + TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); + if (!pTrack) { return; } - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (audioVisualRatio <= 0) { + ConstWaveformPointer waveform = pTrack->getWaveform(); + if (waveform.isNull()) { return; } - const int dataSize = pWaveform->getDataSize(); + const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return; } - const int trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { - return; - } - auto firstVisualIndex = static_cast( - m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / audioVisualRatio); + m_waveformRenderer->getFirstDisplayedPosition() * dataSize); auto lastVisualIndex = static_cast( - m_waveformRenderer->getLastDisplayedPosition() * trackSamples / audioVisualRatio); + m_waveformRenderer->getLastDisplayedPosition() * dataSize); const auto lineWidth = static_cast( (1.0 / m_waveformRenderer->getVisualSamplePerPixel()) + 1.5); diff --git a/src/waveform/renderers/glwaveformrenderersimplesignal.cpp b/src/waveform/renderers/glwaveformrenderersimplesignal.cpp index 24ed5dcaf23..cbc3e57d40c 100644 --- a/src/waveform/renderers/glwaveformrenderersimplesignal.cpp +++ b/src/waveform/renderers/glwaveformrenderersimplesignal.cpp @@ -27,35 +27,30 @@ inline void setPoint(QPointF& point, qreal x, qreal y) { void GLWaveformRendererSimpleSignal::draw(QPainter* painter, QPaintEvent* /*event*/) { maybeInitializeGL(); - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { + TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); + if (!pTrack) { return; } - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (audioVisualRatio <= 0) { + ConstWaveformPointer waveform = pTrack->getWaveform(); + if (waveform.isNull()) { return; } - const int dataSize = pWaveform->getDataSize(); + const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return; } - const int trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { - return; - } - auto firstVisualIndex = static_cast( - m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / audioVisualRatio); + m_waveformRenderer->getFirstDisplayedPosition() * dataSize); auto lastVisualIndex = static_cast( - m_waveformRenderer->getLastDisplayedPosition() * trackSamples / audioVisualRatio); + m_waveformRenderer->getLastDisplayedPosition() * dataSize); const auto lineWidth = static_cast( 1.0 / m_waveformRenderer->getVisualSamplePerPixel() + 1); diff --git a/src/waveform/renderers/qtvsynctestrenderer.cpp b/src/waveform/renderers/qtvsynctestrenderer.cpp index d6b84441f59..c0a15292f8a 100644 --- a/src/waveform/renderers/qtvsynctestrenderer.cpp +++ b/src/waveform/renderers/qtvsynctestrenderer.cpp @@ -33,17 +33,22 @@ void QtVSyncTestRenderer::draw(QPainter* pPainter, QPaintEvent* /*event*/) { timer.start(); - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { + TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); + if (!pTrack) { return; } - const int dataSize = pWaveform->getDataSize(); + ConstWaveformPointer waveform = pTrack->getWaveform(); + if (waveform.isNull()) { + return; + } + + const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return; } diff --git a/src/waveform/renderers/qtwaveformrendererfilteredsignal.cpp b/src/waveform/renderers/qtwaveformrendererfilteredsignal.cpp index ee627b65c2c..6fc54b48274 100644 --- a/src/waveform/renderers/qtwaveformrendererfilteredsignal.cpp +++ b/src/waveform/renderers/qtwaveformrendererfilteredsignal.cpp @@ -97,37 +97,28 @@ inline void setPoint(QPointF& point, qreal x, qreal y) { int QtWaveformRendererFilteredSignal::buildPolygon() { // We have to check the track is present because it might have been unloaded // between the call to draw and the call to buildPolygon - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { + TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); + if (!pTrack) { return 0; } - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (audioVisualRatio <= 0) { + ConstWaveformPointer waveform = pTrack->getWaveform(); + if (waveform.isNull()) { return 0; } - const int dataSize = pWaveform->getDataSize(); + const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return 0; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return 0; } - const int trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { - return 0; - } - - const double firstVisualIndex = - m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / - audioVisualRatio; - const double lastVisualIndex = - m_waveformRenderer->getLastDisplayedPosition() * trackSamples / - audioVisualRatio; + const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize; + const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize; m_polygon[0].clear(); m_polygon[1].clear(); diff --git a/src/waveform/renderers/qtwaveformrenderersimplesignal.cpp b/src/waveform/renderers/qtwaveformrenderersimplesignal.cpp index 5cdce479b3b..1e0327d8ff0 100644 --- a/src/waveform/renderers/qtwaveformrenderersimplesignal.cpp +++ b/src/waveform/renderers/qtwaveformrenderersimplesignal.cpp @@ -38,31 +38,27 @@ inline void setPoint(QPointF& point, qreal x, qreal y) { } void QtWaveformRendererSimpleSignal::draw(QPainter* painter, QPaintEvent* /*event*/) { - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { + + TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); + if (!pTrack) { return; } - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (audioVisualRatio <= 0) { + ConstWaveformPointer waveform = pTrack->getWaveform(); + if (waveform.isNull()) { return; } - const int dataSize = pWaveform->getDataSize(); + const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return; } - const int trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { - return; - } - PainterScope PainterScope(painter); painter->setRenderHint(QPainter::Antialiasing); @@ -94,12 +90,8 @@ void QtWaveformRendererSimpleSignal::draw(QPainter* painter, QPaintEvent* /*even painter->drawLine(0,0,m_waveformRenderer->getLength(),0); } - const double firstVisualIndex = - m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / - audioVisualRatio; - const double lastVisualIndex = - m_waveformRenderer->getLastDisplayedPosition() * trackSamples / - audioVisualRatio; + const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize; + const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize; m_polygon.clear(); m_polygon.reserve(2 * m_waveformRenderer->getLength() + 2); m_polygon.append(QPointF(0.0, 0.0)); diff --git a/src/waveform/renderers/waveformrenderbeat.cpp b/src/waveform/renderers/waveformrenderbeat.cpp index 52b97de2864..e9b3227caf5 100644 --- a/src/waveform/renderers/waveformrenderbeat.cpp +++ b/src/waveform/renderers/waveformrenderbeat.cpp @@ -25,13 +25,13 @@ void WaveformRenderBeat::setup(const QDomNode& node, const SkinContext& context) } void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* /*event*/) { - TrackPointer pTrackInfo = m_waveformRenderer->getTrackInfo(); + TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); - if (!pTrackInfo) { + if (!trackInfo) { return; } - mixxx::BeatsPointer trackBeats = pTrackInfo->getBeats(); + mixxx::BeatsPointer trackBeats = trackInfo->getBeats(); if (!trackBeats) { return; } diff --git a/src/waveform/renderers/waveformrendererfilteredsignal.cpp b/src/waveform/renderers/waveformrendererfilteredsignal.cpp index c0c4db9ccd2..d36b56e289c 100644 --- a/src/waveform/renderers/waveformrendererfilteredsignal.cpp +++ b/src/waveform/renderers/waveformrendererfilteredsignal.cpp @@ -30,31 +30,26 @@ void WaveformRendererFilteredSignal::onSetup(const QDomNode& node) { void WaveformRendererFilteredSignal::draw(QPainter* painter, QPaintEvent* /*event*/) { - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { + const TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); + if (!trackInfo) { return; } - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (audioVisualRatio <= 0) { + ConstWaveformPointer waveform = trackInfo->getWaveform(); + if (waveform.isNull()) { return; } - const int dataSize = pWaveform->getDataSize(); + const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return; } - const int trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { - return; - } - PainterScope PainterScope(painter); painter->setRenderHints(QPainter::Antialiasing, false); @@ -67,12 +62,8 @@ void WaveformRendererFilteredSignal::draw(QPainter* painter, painter->setTransform(QTransform(0, 1, 1, 0, 0, 0)); } - const double firstVisualIndex = - m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / - audioVisualRatio; - const double lastVisualIndex = - m_waveformRenderer->getLastDisplayedPosition() * trackSamples / - audioVisualRatio; + const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize; + const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize; // Represents the # of waveform data points per horizontal pixel. const double gain = (lastVisualIndex - firstVisualIndex) / diff --git a/src/waveform/renderers/waveformrendererhsv.cpp b/src/waveform/renderers/waveformrendererhsv.cpp index f468b03e998..e4e979f812a 100644 --- a/src/waveform/renderers/waveformrendererhsv.cpp +++ b/src/waveform/renderers/waveformrendererhsv.cpp @@ -21,34 +21,28 @@ void WaveformRendererHSV::onSetup(const QDomNode& node) { Q_UNUSED(node); } -void WaveformRendererHSV::draw( - QPainter* painter, - QPaintEvent* /*event*/) { - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { +void WaveformRendererHSV::draw(QPainter* painter, + QPaintEvent* /*event*/) { + const TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); + if (!trackInfo) { return; } - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (audioVisualRatio <= 0) { + ConstWaveformPointer waveform = trackInfo->getWaveform(); + if (waveform.isNull()) { return; } - const int dataSize = pWaveform->getDataSize(); + const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return; } - const int trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { - return; - } - PainterScope PainterScope(painter); painter->setRenderHints(QPainter::Antialiasing, false); @@ -61,12 +55,8 @@ void WaveformRendererHSV::draw( painter->setTransform(QTransform(0, 1, 1, 0, 0, 0)); } - const double firstVisualIndex = - m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / - audioVisualRatio; - const double lastVisualIndex = - m_waveformRenderer->getLastDisplayedPosition() * trackSamples / - audioVisualRatio; + const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize; + const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize; const double offset = firstVisualIndex; diff --git a/src/waveform/renderers/waveformrendererpreroll.cpp b/src/waveform/renderers/waveformrendererpreroll.cpp index 1c0a4abb839..5338dbf0d10 100644 --- a/src/waveform/renderers/waveformrendererpreroll.cpp +++ b/src/waveform/renderers/waveformrendererpreroll.cpp @@ -27,8 +27,8 @@ void WaveformRendererPreroll::setup( void WaveformRendererPreroll::draw(QPainter* painter, QPaintEvent* event) { Q_UNUSED(event); - const TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); - if (!pTrack) { + const TrackPointer track = m_waveformRenderer->getTrackInfo(); + if (!track) { return; } diff --git a/src/waveform/renderers/waveformrendererrgb.cpp b/src/waveform/renderers/waveformrendererrgb.cpp index 3fe23ffc39a..1f30325e529 100644 --- a/src/waveform/renderers/waveformrendererrgb.cpp +++ b/src/waveform/renderers/waveformrendererrgb.cpp @@ -20,34 +20,28 @@ WaveformRendererRGB::~WaveformRendererRGB() { void WaveformRendererRGB::onSetup(const QDomNode& /* node */) { } -void WaveformRendererRGB::draw( - QPainter* painter, - QPaintEvent* /*event*/) { - ConstWaveformPointer pWaveform = m_waveformRenderer->getWaveform(); - if (pWaveform.isNull()) { +void WaveformRendererRGB::draw(QPainter* painter, + QPaintEvent* /*event*/) { + const TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); + if (!trackInfo) { return; } - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (audioVisualRatio <= 0) { + ConstWaveformPointer waveform = trackInfo->getWaveform(); + if (waveform.isNull()) { return; } - const int dataSize = pWaveform->getDataSize(); + const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { return; } - const WaveformData* data = pWaveform->data(); + const WaveformData* data = waveform->data(); if (data == nullptr) { return; } - const int trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { - return; - } - PainterScope PainterScope(painter); painter->setRenderHints(QPainter::Antialiasing, false); @@ -60,12 +54,8 @@ void WaveformRendererRGB::draw( painter->setTransform(QTransform(0, 1, 1, 0, 0, 0)); } - const double firstVisualIndex = - m_waveformRenderer->getFirstDisplayedPosition() * trackSamples / - audioVisualRatio; - const double lastVisualIndex = - m_waveformRenderer->getLastDisplayedPosition() * trackSamples / - audioVisualRatio; + const double firstVisualIndex = m_waveformRenderer->getFirstDisplayedPosition() * dataSize; + const double lastVisualIndex = m_waveformRenderer->getLastDisplayedPosition() * dataSize; const double offset = firstVisualIndex; diff --git a/src/waveform/renderers/waveformrendermark.cpp b/src/waveform/renderers/waveformrendermark.cpp index 1444d09d6c4..cea1e7a062c 100644 --- a/src/waveform/renderers/waveformrendermark.cpp +++ b/src/waveform/renderers/waveformrendermark.cpp @@ -102,23 +102,23 @@ void WaveformRenderMark::onResize() { void WaveformRenderMark::onSetTrack() { slotCuesUpdated(); - const TrackPointer pTrackInfo = m_waveformRenderer->getTrackInfo(); - if (!pTrackInfo) { + TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); + if (!trackInfo) { return; } - connect(pTrackInfo.get(), + connect(trackInfo.get(), &Track::cuesUpdated, this, &WaveformRenderMark::slotCuesUpdated); } void WaveformRenderMark::slotCuesUpdated() { - const TrackPointer pTrackInfo = m_waveformRenderer->getTrackInfo(); - if (!pTrackInfo) { + TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); + if (!trackInfo) { return; } - QList loadedCues = pTrackInfo->getCuePoints(); + QList loadedCues = trackInfo->getCuePoints(); for (const CuePointer& pCue : loadedCues) { int hotCue = pCue->getHotCue(); if (hotCue == Cue::kNoHotCue) { diff --git a/src/waveform/renderers/waveformwidgetrenderer.cpp b/src/waveform/renderers/waveformwidgetrenderer.cpp index 95e6d394385..5b2b0912308 100644 --- a/src/waveform/renderers/waveformwidgetrenderer.cpp +++ b/src/waveform/renderers/waveformwidgetrenderer.cpp @@ -36,16 +36,18 @@ WaveformWidgetRenderer::WaveformWidgetRenderer(const QString& group) m_zoomFactor(1.0), m_visualSamplePerPixel(1.0), m_audioSamplePerPixel(1.0), + m_audioVisualRatio(1.0), m_alphaBeatGrid(90), // Really create some to manage those; m_visualPlayPosition(nullptr), m_playPosVSample(0), m_totalVSamples(0), m_pRateRatioCO(nullptr), + m_rateRatio(1.0), m_pGainControlObject(nullptr), m_gain(1.0), m_pTrackSamplesControlObject(nullptr), - m_trackSamples(0), + m_trackSamples(0.0), m_scaleFactor(1.0), m_playMarkerPosition(s_defaultPlayMarkerPosition), m_playPos(-1) { @@ -109,7 +111,7 @@ void WaveformWidgetRenderer::onPreRender(VSyncThread* vsyncThread) { } //Fetch parameters before rendering in order the display all sub-renderers with the same values - double rateRatio = m_pRateRatioCO->get(); + m_rateRatio = m_pRateRatioCO->get(); // This gain adjustment compensates for an arbitrary /2 gain chop in // EnginePregain. See the comment there. @@ -119,17 +121,19 @@ void WaveformWidgetRenderer::onPreRender(VSyncThread* vsyncThread) { // Allow waveform to spread one visual sample across a hundred pixels // NOTE: The hundred pixel limit is totally arbitrary. Theoretically, // there should be no limit to how far the waveforms can be zoomed in. - double visualSamplePerPixel = m_zoomFactor * rateRatio / m_scaleFactor; + double visualSamplePerPixel = m_zoomFactor * m_rateRatio / m_scaleFactor; m_visualSamplePerPixel = math_max(0.01, visualSamplePerPixel); TrackPointer pTrack = m_pTrack; if (pTrack) { ConstWaveformPointer pWaveform = pTrack->getWaveform(); if (pWaveform) { - m_audioSamplePerPixel = m_visualSamplePerPixel * pWaveform->getAudioVisualRatio(); + m_audioVisualRatio = pWaveform->getAudioVisualRatio(); } } + m_audioSamplePerPixel = m_visualSamplePerPixel * m_audioVisualRatio; + double truePlayPos = m_visualPlayPosition->getAtNextVSync(vsyncThread); // truePlayPos = -1 happens, when a new track is in buffer but m_visualPlayPosition was not updated @@ -162,12 +166,12 @@ void WaveformWidgetRenderer::onPreRender(VSyncThread* vsyncThread) { m_playPos = -1; // disable renderers } - // qDebug() << "WaveformWidgetRenderer::onPreRender" << - // "m_group" << m_group << - // "m_trackSamples" << m_trackSamples << - // "m_playPos" << m_playPos << - // "rateRatio" << rateRatio << - // "m_gain" << m_gain; + //qDebug() << "WaveformWidgetRenderer::onPreRender" << + // "m_group" << m_group << + // "m_trackSamples" << m_trackSamples << + // "m_playPos" << m_playPos << + // "m_rateRatio" << m_rate << + // "m_gain" << m_gain; } void WaveformWidgetRenderer::draw(QPainter* painter, QPaintEvent* event) { @@ -181,7 +185,7 @@ void WaveformWidgetRenderer::draw(QPainter* painter, QPaintEvent* event) { // not ready to display need to wait until track initialization is done // draw only first is stack (background) int stackSize = m_rendererStack.size(); - if (m_trackSamples <= 0 || m_playPos == -1) { + if (m_trackSamples <= 0.0 || m_playPos == -1) { if (stackSize) { m_rendererStack.at(0)->draw(painter, event); } @@ -218,7 +222,7 @@ void WaveformWidgetRenderer::draw(QPainter* painter, QPaintEvent* event) { QString::number(m_playPos) + " [" + QString::number(m_firstDisplayedPosition) + "-" + QString::number(m_lastDisplayedPosition) + "]" + - QString::number(rateRatio) + " | " + QString::number(m_gain) + + QString::number(m_rate) + " | " + QString::number(m_gain) + " | " + QString::number(m_rateDir) + " | " + QString::number(m_zoomFactor)); @@ -348,20 +352,13 @@ void WaveformWidgetRenderer::setDisplayBeatGridAlpha(int alpha) { void WaveformWidgetRenderer::setTrack(TrackPointer track) { m_pTrack = track; //used to postpone first display until track sample is actually available - m_trackSamples = -1; + m_trackSamples = -1.0; for (int i = 0; i < m_rendererStack.size(); ++i) { m_rendererStack[i]->onSetTrack(); } } -ConstWaveformPointer WaveformWidgetRenderer::getWaveform() const { - if (m_pTrack) { - return m_pTrack->getWaveform(); - } - return {}; -} - WaveformMarkPointer WaveformWidgetRenderer::getCueMarkAtPoint(QPoint point) const { for (auto it = m_markPositions.constBegin(); it != m_markPositions.constEnd(); ++it) { WaveformMarkPointer pMark = it.key(); diff --git a/src/waveform/renderers/waveformwidgetrenderer.h b/src/waveform/renderers/waveformwidgetrenderer.h index 23cc2ca98fb..4bc406da47b 100644 --- a/src/waveform/renderers/waveformwidgetrenderer.h +++ b/src/waveform/renderers/waveformwidgetrenderer.h @@ -11,7 +11,6 @@ #include "waveform/renderers/waveformmark.h" #include "waveform/renderers/waveformrendererabstract.h" #include "waveform/renderers/waveformsignalcolors.h" -#include "waveform/waveform.h" //#define WAVEFORMWIDGETRENDERER_DEBUG @@ -40,13 +39,9 @@ class WaveformWidgetRenderer { const QString& getGroup() const { return m_group; } - const TrackPointer& getTrackInfo() const { return m_pTrack; } - - ConstWaveformPointer getWaveform() const; - /// Get cue mark at a point on the waveform widget. WaveformMarkPointer getCueMarkAtPoint(QPoint point) const; @@ -175,6 +170,7 @@ class WaveformWidgetRenderer { double m_zoomFactor; double m_visualSamplePerPixel; double m_audioSamplePerPixel; + double m_audioVisualRatio; int m_alphaBeatGrid; @@ -184,6 +180,7 @@ class WaveformWidgetRenderer { int m_playPosVSample; int m_totalVSamples; ControlProxy* m_pRateRatioCO; + double m_rateRatio; ControlProxy* m_pGainControlObject; double m_gain; ControlProxy* m_pTrackSamplesControlObject; diff --git a/src/waveform/waveform.h b/src/waveform/waveform.h index eaa587b6558..c266f46332a 100644 --- a/src/waveform/waveform.h +++ b/src/waveform/waveform.h @@ -74,6 +74,12 @@ class Waveform { QByteArray toByteArray() const; + // We do not lock the mutex since m_dataSize and m_visualSampleRate are not + // changed after the constructor runs. + bool isValid() const { + return getDataSize() > 0 && getVisualSampleRate() > 0; + } + SaveState saveState() const { return m_saveState; } diff --git a/src/widget/woverview.h b/src/widget/woverview.h index b0d80660b08..5e61249853a 100644 --- a/src/widget/woverview.h +++ b/src/widget/woverview.h @@ -77,10 +77,6 @@ class WOverview : public WWidget, public TrackDropTarget { return m_pWaveform; } - double getTrackSamples() const { - return m_trackSamplesControl->get(); - } - QImage m_waveformSourceImage; QImage m_waveformImageScaled; diff --git a/src/widget/woverviewhsv.cpp b/src/widget/woverviewhsv.cpp index 9d7be49199f..55d69c4479c 100644 --- a/src/widget/woverviewhsv.cpp +++ b/src/widget/woverviewhsv.cpp @@ -28,8 +28,7 @@ bool WOverviewHSV::drawNextPixmapPart() { } const int dataSize = pWaveform->getDataSize(); - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (dataSize <= 0 || audioVisualRatio <= 0) { + if (dataSize == 0) { return false; } @@ -37,9 +36,7 @@ bool WOverviewHSV::drawNextPixmapPart() { // Waveform pixmap twice the height of the viewport to be scalable // by total_gain // We keep full range waveform data to scale it on paint - m_waveformSourceImage = QImage( - static_cast(getTrackSamples() / audioVisualRatio / 2), - 2 * 255, + m_waveformSourceImage = QImage(dataSize / 2, 2 * 255, QImage::Format_ARGB32_Premultiplied); m_waveformSourceImage.fill(QColor(0, 0, 0, 0).value()); } diff --git a/src/widget/woverviewlmh.cpp b/src/widget/woverviewlmh.cpp index 0a453576587..d0b5e4c77c6 100644 --- a/src/widget/woverviewlmh.cpp +++ b/src/widget/woverviewlmh.cpp @@ -29,8 +29,7 @@ bool WOverviewLMH::drawNextPixmapPart() { } const int dataSize = pWaveform->getDataSize(); - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (dataSize <= 0 || audioVisualRatio <= 0) { + if (dataSize == 0) { return false; } @@ -38,9 +37,7 @@ bool WOverviewLMH::drawNextPixmapPart() { // Waveform pixmap twice the height of the viewport to be scalable // by total_gain // We keep full range waveform data to scale it on paint - m_waveformSourceImage = QImage( - static_cast(getTrackSamples() / audioVisualRatio / 2), - 2 * 255, + m_waveformSourceImage = QImage(dataSize / 2, 2 * 255, QImage::Format_ARGB32_Premultiplied); m_waveformSourceImage.fill(QColor(0, 0, 0, 0).value()); } diff --git a/src/widget/woverviewrgb.cpp b/src/widget/woverviewrgb.cpp index fdc68789c55..4dc351a1bb3 100644 --- a/src/widget/woverviewrgb.cpp +++ b/src/widget/woverviewrgb.cpp @@ -27,8 +27,7 @@ bool WOverviewRGB::drawNextPixmapPart() { } const int dataSize = pWaveform->getDataSize(); - const double audioVisualRatio = pWaveform->getAudioVisualRatio(); - if (dataSize <= 0 || audioVisualRatio <= 0) { + if (dataSize == 0) { return false; } @@ -37,8 +36,8 @@ bool WOverviewRGB::drawNextPixmapPart() { // by total_gain // We keep full range waveform data to scale it on paint m_waveformSourceImage = QImage( - static_cast(getTrackSamples() / audioVisualRatio / 2), - 2 * 255, + dataSize / 2, + static_cast(2 * 255 * m_devicePixelRatio), QImage::Format_ARGB32_Premultiplied); m_waveformSourceImage.fill(QColor(0, 0, 0, 0).value()); } @@ -97,8 +96,8 @@ bool WOverviewRGB::drawNextPixmapPart() { if (max > 0.0) { color.setRgbF(red / max, green / max, blue / max); painter.setPen(color); - painter.drawLine(QPointF(currentCompletion / 2, -left), - QPointF(currentCompletion / 2, 0)); + painter.drawLine(QPointF(currentCompletion / 2, -left * m_devicePixelRatio), + QPointF(currentCompletion / 2, 0)); } // Retrieve "raw" LMH values from waveform @@ -117,7 +116,7 @@ bool WOverviewRGB::drawNextPixmapPart() { color.setRgbF(red / max, green / max, blue / max); painter.setPen(color); painter.drawLine(QPointF(currentCompletion / 2, 0), - QPointF(currentCompletion / 2, right)); + QPointF(currentCompletion / 2, right * m_devicePixelRatio)); } }