From 18236e6a802b916041f834aa63c2862afc4ec70f Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Sat, 15 Jan 2022 01:59:15 +0100 Subject: [PATCH] Don't use VisualPlayPosition in EngineBuffer/SoundDevice with Qt6 --- src/engine/enginebuffer.cpp | 26 ++++++++++++++++++++++++-- src/soundio/sounddevicenetwork.cpp | 4 +++- src/soundio/sounddeviceportaudio.cpp | 2 ++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/engine/enginebuffer.cpp b/src/engine/enginebuffer.cpp index f5727ca7635..ff1dcf4ff74 100644 --- a/src/engine/enginebuffer.cpp +++ b/src/engine/enginebuffer.cpp @@ -165,8 +165,10 @@ EngineBuffer::EngineBuffer(const QString& group, this, &EngineBuffer::slotControlSeek, Qt::DirectConnection); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // Control used to communicate ratio playpos to GUI thread m_visualPlayPos = VisualPlayPosition::getVisualPlayPosition(m_group); +#endif m_pRepeat = new ControlPushButton(ConfigKey(m_group, "repeat")); m_pRepeat->setButtonMode(ControlPushButton::TOGGLE); @@ -551,7 +553,9 @@ void EngineBuffer::slotTrackLoaded(TrackPointer pTrack, TrackPointer pOldTrack = m_pCurrentTrack; m_pause.lock(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) m_visualPlayPos->setInvalid(); +#endif m_playPosition = kInitialPlayPosition; // for execute seeks to 0.0 m_pCurrentTrack = pTrack; m_pTrackSamples->set(iTrackNumSamples); @@ -593,7 +597,9 @@ void EngineBuffer::ejectTrack() { TrackPointer pOldTrack = m_pCurrentTrack; m_pause.lock(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) m_visualPlayPos->set(0.0, 0.0, 0.0, 0.0, 0.0); +#endif doSeekPlayPos(mixxx::audio::kStartFramePos, SEEK_EXACT); m_pCurrentTrack.reset(); @@ -1348,8 +1354,6 @@ void EngineBuffer::updateIndicators(double speed, int iBufferSize) { const double fFractionalPlaypos = fractionalPlayposFromAbsolute(m_playPosition); - const double tempoTrackSeconds = m_trackEndPositionOld.value() / - m_trackSampleRateOld / m_tempo_ratio_old; if(speed > 0 && fFractionalPlaypos == 1.0) { // At Track end speed = 0; @@ -1370,6 +1374,10 @@ void EngineBuffer::updateIndicators(double speed, int iBufferSize) { m_pCueControl->updateIndicators(); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + const double tempoTrackSeconds = m_trackEndPositionOld.value() / + m_trackSampleRateOld / m_tempo_ratio_old; + // Update visual control object, this needs to be done more often than the // playpos slider m_visualPlayPos->set(fFractionalPlaypos, @@ -1378,6 +1386,7 @@ void EngineBuffer::updateIndicators(double speed, int iBufferSize) { m_trackEndPositionOld.toEngineSamplePos(), fractionalPlayposFromAbsolute(m_slipPosition), tempoTrackSeconds); +#endif // TODO: Especially with long audio buffers, jitter is visible. This can be fixed by moving the // ClockControl::updateIndicators into the waveform update loop which is synced with the display refresh rate. @@ -1452,14 +1461,27 @@ void EngineBuffer::slotEjectTrack(double v) { } mixxx::audio::FramePos EngineBuffer::getExactPlayPos() const { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + const mixxx::audio::FramePos trackEndPosition = getTrackEndPosition(); + if (!trackEndPosition.isValid()) { + return mixxx::audio::kStartFramePos; + } + + return trackEndPosition * getVisualPlayPos(); +#else if (!m_visualPlayPos->isValid()) { return mixxx::audio::kStartFramePos; } return getTrackEndPosition() * m_visualPlayPos->getEnginePlayPos(); +#endif } double EngineBuffer::getVisualPlayPos() const { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return m_playposSlider->get(); +#else return m_visualPlayPos->getEnginePlayPos(); +#endif } mixxx::audio::FramePos EngineBuffer::getTrackEndPosition() const { diff --git a/src/soundio/sounddevicenetwork.cpp b/src/soundio/sounddevicenetwork.cpp index 0f4b1a1a781..b3239c60539 100644 --- a/src/soundio/sounddevicenetwork.cpp +++ b/src/soundio/sounddevicenetwork.cpp @@ -479,12 +479,14 @@ void SoundDeviceNetwork::callbackProcessClkRef() { void SoundDeviceNetwork::updateCallbackEntryToDacTime() { m_clkRefTimer.start(); - qint64 currentTime = m_pNetworkStream->getInputStreamTimeUs(); m_targetTime += m_audioBufferTime.toIntegerMicros(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + qint64 currentTime = m_pNetworkStream->getInputStreamTimeUs(); double callbackEntrytoDacSecs = (m_targetTime - currentTime) / 1000000.0; callbackEntrytoDacSecs = math_max(callbackEntrytoDacSecs, 0.0001); VisualPlayPosition::setCallbackEntryToDacSecs(callbackEntrytoDacSecs, m_clkRefTimer); //qDebug() << callbackEntrytoDacSecs << timeSinceLastCbSecs; +#endif } void SoundDeviceNetwork::updateAudioLatencyUsage() { diff --git a/src/soundio/sounddeviceportaudio.cpp b/src/soundio/sounddeviceportaudio.cpp index 6cfc94710e0..25c96957a14 100644 --- a/src/soundio/sounddeviceportaudio.cpp +++ b/src/soundio/sounddeviceportaudio.cpp @@ -1052,7 +1052,9 @@ void SoundDevicePortAudio::updateCallbackEntryToDacTime( callbackEntrytoDacSecs = math_clamp(callbackEntrytoDacSecs, 0.0, bufferSizeSec * 2); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) VisualPlayPosition::setCallbackEntryToDacSecs(callbackEntrytoDacSecs, m_clkRefTimer); +#endif m_lastCallbackEntrytoDacSecs = callbackEntrytoDacSecs; //qDebug() << callbackEntrytoDacSecs << timeSinceLastCbSecs;