Skip to content

Commit

Permalink
Don't use VisualPlayPosition in EngineBuffer/SoundDevice with Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jan 15, 2022
1 parent 66b4d16 commit 4405177
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
26 changes: 24 additions & 2 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/soundio/sounddevicenetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions src/soundio/sounddeviceportaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4405177

Please sign in to comment.