diff --git a/src/widget/woverview.cpp b/src/widget/woverview.cpp index 9fc37bdf4c3..805ecf52546 100644 --- a/src/widget/woverview.cpp +++ b/src/widget/woverview.cpp @@ -250,7 +250,7 @@ void WOverview::onConnectedControlChanged(double dParameter, double dValue) { // least once per second, regardless of m_iPos which depends on the length // of the widget. int oldPositionSeconds = m_iPosSeconds; - m_iPosSeconds = static_cast(dParameter * m_trackSamplesControl->get()); + m_iPosSeconds = static_cast(dParameter * getTrackSamples()); if ((m_bTimeRulerActive || m_pHoveredMark != nullptr) && oldPositionSeconds != m_iPosSeconds) { redraw = true; } @@ -320,6 +320,10 @@ void WOverview::slotLoadingTrack(TrackPointer pNewTrack, TrackPointer pOldTrack) &Track::waveformSummaryUpdated, this, &WOverview::slotWaveformSummaryUpdated); + disconnect(m_pCurrentTrack.get(), + &Track::cuesUpdated, + this, + &WOverview::receiveCuesUpdated); } m_waveformSourceImage = QImage(); @@ -327,6 +331,9 @@ void WOverview::slotLoadingTrack(TrackPointer pNewTrack, TrackPointer pOldTrack) m_actualCompletion = 0; m_waveformPeak = -1.0; m_pixmapDone = false; + // Note: Here we already have the new track, but the engine and it's + // Control Objects may still have the old one until the slotTrackLoaded() + // signal has been received. m_trackLoaded = false; m_endOfTrack = false; @@ -492,7 +499,8 @@ void WOverview::mouseReleaseEvent(QMouseEvent* e) { void WOverview::mousePressEvent(QMouseEvent* e) { //qDebug() << "WOverview::mousePressEvent" << e->pos(); mouseMoveEvent(e); - if (m_pCurrentTrack == nullptr) { + double trackSamples = getTrackSamples(); + if (m_pCurrentTrack == nullptr || trackSamples <= 0) { return; } if (e->button() == Qt::LeftButton) { @@ -503,7 +511,7 @@ void WOverview::mousePressEvent(QMouseEvent* e) { } if (m_pHoveredMark != nullptr) { - double dValue = m_pHoveredMark->getSamplePosition() / m_trackSamplesControl->get(); + double dValue = m_pHoveredMark->getSamplePosition() / trackSamples; m_iPickupPos = valueToPosition(dValue); m_iPlayPos = m_iPickupPos; setControlParameterUp(dValue); @@ -585,11 +593,11 @@ void WOverview::paintEvent(QPaintEvent* pEvent) { drawEndOfTrackFrame(&painter); drawAnalyzerProgress(&painter); - double trackSamples = m_trackSamplesControl->get(); - if (m_trackLoaded && trackSamples > 0) { + double trackSamples = getTrackSamples(); + if (trackSamples > 0) { const float offset = 1.0f; const auto gain = static_cast(length() - 2) / - static_cast(m_trackSamplesControl->get()); + static_cast(trackSamples); drawRangeMarks(&painter, offset, gain); drawMarks(&painter, offset, gain); @@ -940,7 +948,7 @@ void WOverview::drawMarks(QPainter* pPainter, const float offset, const float ga } double markSamples = pMark->getSamplePosition(); - double trackSamples = m_trackSamplesControl->get(); + double trackSamples = getTrackSamples(); double currentPositionSamples = m_playpositionControl->get() * trackSamples; double markTime = samplePositionToSeconds(markSamples); double markTimeRemaining = samplePositionToSeconds(trackSamples - markSamples); @@ -1051,7 +1059,7 @@ void WOverview::drawTimeRuler(QPainter* pPainter) { textPointDistance.setX(0); widgetPositionFraction = m_timeRulerPos.y() / height(); } - qreal trackSamples = m_trackSamplesControl->get(); + qreal trackSamples = getTrackSamples(); qreal timePosition = samplePositionToSeconds( widgetPositionFraction * trackSamples); qreal timePositionTillEnd = samplePositionToSeconds( diff --git a/src/widget/woverview.h b/src/widget/woverview.h index b0d80660b08..479e6634755 100644 --- a/src/widget/woverview.h +++ b/src/widget/woverview.h @@ -78,7 +78,13 @@ class WOverview : public WWidget, public TrackDropTarget { } double getTrackSamples() const { - return m_trackSamplesControl->get(); + if (m_trackLoaded) { + return m_trackSamplesControl->get(); + } else { + // Ignore the value, because the engine can still have the old track + // during loading + return 0.0; + } } QImage m_waveformSourceImage; diff --git a/src/widget/woverviewhsv.cpp b/src/widget/woverviewhsv.cpp index 133d82e7ddb..d0825640260 100644 --- a/src/widget/woverviewhsv.cpp +++ b/src/widget/woverviewhsv.cpp @@ -39,10 +39,14 @@ bool WOverviewHSV::drawNextPixmapPart() { // by total_gain // We keep full range waveform data to scale it on paint m_waveformSourceImage = QImage( - static_cast(trackSamples / audioVisualRatio / 2), + static_cast(trackSamples / audioVisualRatio / 2) + 1, 2 * 255, QImage::Format_ARGB32_Premultiplied); m_waveformSourceImage.fill(QColor(0, 0, 0, 0).value()); + if (dataSize / 2 != m_waveformSourceImage.width()) { + qWarning() << "Track duration has changed since last analysis" + << m_waveformSourceImage.width() << "!=" << dataSize / 2; + } } DEBUG_ASSERT(!m_waveformSourceImage.isNull()); diff --git a/src/widget/woverviewlmh.cpp b/src/widget/woverviewlmh.cpp index e4d91d5ade8..3134e9c3180 100644 --- a/src/widget/woverviewlmh.cpp +++ b/src/widget/woverviewlmh.cpp @@ -40,10 +40,14 @@ bool WOverviewLMH::drawNextPixmapPart() { // by total_gain // We keep full range waveform data to scale it on paint m_waveformSourceImage = QImage( - static_cast(trackSamples / audioVisualRatio / 2), + static_cast(trackSamples / audioVisualRatio / 2) + 1, 2 * 255, QImage::Format_ARGB32_Premultiplied); m_waveformSourceImage.fill(QColor(0, 0, 0, 0).value()); + if (dataSize / 2 != m_waveformSourceImage.width()) { + qWarning() << "Track duration has changed since last analysis" + << m_waveformSourceImage.width() << "!=" << dataSize / 2; + } } DEBUG_ASSERT(!m_waveformSourceImage.isNull()); diff --git a/src/widget/woverviewrgb.cpp b/src/widget/woverviewrgb.cpp index 3582c1553bd..542405195d5 100644 --- a/src/widget/woverviewrgb.cpp +++ b/src/widget/woverviewrgb.cpp @@ -38,10 +38,14 @@ bool WOverviewRGB::drawNextPixmapPart() { // by total_gain // We keep full range waveform data to scale it on paint m_waveformSourceImage = QImage( - static_cast(trackSamples / audioVisualRatio / 2), + static_cast(trackSamples / audioVisualRatio / 2) + 1, 2 * 255, QImage::Format_ARGB32_Premultiplied); m_waveformSourceImage.fill(QColor(0, 0, 0, 0).value()); + if (dataSize / 2 != m_waveformSourceImage.width()) { + qWarning() << "Track duration has changed since last analysis" + << m_waveformSourceImage.width() << "!=" << dataSize / 2; + } } DEBUG_ASSERT(!m_waveformSourceImage.isNull());