diff --git a/src/library/autodj/autodjprocessor.cpp b/src/library/autodj/autodjprocessor.cpp index 61cf31d2a27..068cdec09cf 100644 --- a/src/library/autodj/autodjprocessor.cpp +++ b/src/library/autodj/autodjprocessor.cpp @@ -17,8 +17,6 @@ const char* kTransitionModePreferenceName = "TransitionMode"; const double kTransitionPreferenceDefault = 10.0; const double kKeepPosition = -1.0; -const mixxx::audio::ChannelCount kChannelCount = mixxx::kEngineChannelCount; - static const bool sDebug = false; } // anonymous namespace @@ -1057,43 +1055,44 @@ void AutoDJProcessor::playerOutroEndChanged(DeckAttributes* pAttributes, double } double AutoDJProcessor::getIntroStartSecond(DeckAttributes* pDeck) { - double introStartSample = pDeck->introStartPosition(); - if (introStartSample == Cue::kNoPosition) { + const mixxx::audio::FramePos introStartPosition = pDeck->introStartPosition(); + if (!introStartPosition.isValid()) { return getFirstSoundSecond(pDeck); } - return samplePositionToSeconds(introStartSample, pDeck); + return framePositionToSeconds(introStartPosition, pDeck); } double AutoDJProcessor::getIntroEndSecond(DeckAttributes* pDeck) { - double introEndSample = pDeck->introEndPosition(); - if (introEndSample == Cue::kNoPosition) { + const mixxx::audio::FramePos introEndPosition = pDeck->introEndPosition(); + if (!introEndPosition.isValid()) { // Assume a zero length intro if introEnd is not set. // The introStart is automatically placed by AnalyzerSilence, so use // that as a fallback if the user has not placed outroStart. If it has // not been placed, getIntroStartPosition will return 0:00. return getIntroStartSecond(pDeck); } - return samplePositionToSeconds(introEndSample, pDeck); + return framePositionToSeconds(introEndPosition, pDeck); } double AutoDJProcessor::getOutroStartSecond(DeckAttributes* pDeck) { - double outroStartSample = pDeck->outroStartPosition(); - if (outroStartSample == Cue::kNoPosition) { + const mixxx::audio::FramePos outroStartPosition = pDeck->outroStartPosition(); + if (!outroStartPosition.isValid()) { // Assume a zero length outro if outroStart is not set. // The outroEnd is automatically placed by AnalyzerSilence, so use // that as a fallback if the user has not placed outroStart. If it has // not been placed, getOutroEndPosition will return the end of the track. return getOutroEndSecond(pDeck); } - return samplePositionToSeconds(outroStartSample, pDeck); + return framePositionToSeconds(outroStartPosition, pDeck); } double AutoDJProcessor::getOutroEndSecond(DeckAttributes* pDeck) { - double outroEndSample = pDeck->outroEndPosition(); - if (outroEndSample == Cue::kNoPosition) { + const mixxx::audio::FramePos outroEndPosition = pDeck->outroEndPosition(); + if (!outroEndPosition.isValid()) { return getLastSoundSecond(pDeck); } - return samplePositionToSeconds(outroEndSample, pDeck);; + return framePositionToSeconds(outroEndPosition, pDeck); + ; } double AutoDJProcessor::getFirstSoundSecond(DeckAttributes* pDeck) { @@ -1104,9 +1103,9 @@ double AutoDJProcessor::getFirstSoundSecond(DeckAttributes* pDeck) { CuePointer pFromTrackAudibleSound = pTrack->findCueByType(mixxx::CueType::AudibleSound); if (pFromTrackAudibleSound) { - double firstSound = pFromTrackAudibleSound->getPosition().toEngineSamplePosMaybeInvalid(); - if (firstSound > 0.0) { - return samplePositionToSeconds(firstSound, pDeck); + const mixxx::audio::FramePos firstSound = pFromTrackAudibleSound->getPosition(); + if (firstSound.isValid()) { + return framePositionToSeconds(firstSound, pDeck); } } return 0.0; @@ -1123,7 +1122,7 @@ double AutoDJProcessor::getLastSoundSecond(DeckAttributes* pDeck) { Cue::StartAndEndPositions pos = pFromTrackAudibleSound->getStartAndEndPosition(); if (pos.endPosition > mixxx::audio::kStartFramePos && (pos.endPosition - pos.startPosition) > 0) { - return samplePositionToSeconds(pos.endPosition.toEngineSamplePosMaybeInvalid(), pDeck); + return framePositionToSeconds(pos.endPosition, pDeck); } } return getEndSecond(pDeck); @@ -1135,17 +1134,18 @@ double AutoDJProcessor::getEndSecond(DeckAttributes* pDeck) { return 0.0; } - double endSamplePosition = pDeck->trackSamples(); - return samplePositionToSeconds(endSamplePosition, pDeck); + mixxx::audio::FramePos trackEndPosition = pDeck->trackEndPosition(); + return framePositionToSeconds(trackEndPosition, pDeck); } -double AutoDJProcessor::samplePositionToSeconds(double samplePosition, DeckAttributes* pDeck) { - samplePosition /= kChannelCount; +double AutoDJProcessor::framePositionToSeconds( + mixxx::audio::FramePos position, DeckAttributes* pDeck) { mixxx::audio::SampleRate sampleRate = pDeck->sampleRate(); - if (!sampleRate.isValid()) { + if (!sampleRate.isValid() || !position.isValid()) { return 0.0; } - return samplePosition / sampleRate / pDeck->rateRatio(); + + return position.value() / sampleRate / pDeck->rateRatio(); } void AutoDJProcessor::calculateTransition(DeckAttributes* pFromDeck, diff --git a/src/library/autodj/autodjprocessor.h b/src/library/autodj/autodjprocessor.h index 1504d9c62fc..2aa8e2f9662 100644 --- a/src/library/autodj/autodjprocessor.h +++ b/src/library/autodj/autodjprocessor.h @@ -61,28 +61,28 @@ class DeckAttributes : public QObject { m_repeat.set(enabled ? 1.0 : 0.0); } - double introStartPosition() const { - return m_introStartPos.get(); + mixxx::audio::FramePos introStartPosition() const { + return mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(m_introStartPos.get()); } - double introEndPosition() const { - return m_introEndPos.get(); + mixxx::audio::FramePos introEndPosition() const { + return mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(m_introEndPos.get()); } - double outroStartPosition() const { - return m_outroStartPos.get(); + mixxx::audio::FramePos outroStartPosition() const { + return mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(m_outroStartPos.get()); } - double outroEndPosition() const { - return m_outroEndPos.get(); + mixxx::audio::FramePos outroEndPosition() const { + return mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(m_outroEndPos.get()); } mixxx::audio::SampleRate sampleRate() const { return mixxx::audio::SampleRate::fromDouble(m_sampleRate.get()); } - double trackSamples() const { - return m_trackSamples.get(); + mixxx::audio::FramePos trackEndPosition() const { + return mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(m_trackSamples.get()); } double rateRatio() const { @@ -252,7 +252,7 @@ class AutoDJProcessor : public QObject { double getFirstSoundSecond(DeckAttributes* pDeck); double getLastSoundSecond(DeckAttributes* pDeck); double getEndSecond(DeckAttributes* pDeck); - double samplePositionToSeconds(double samplePosition, DeckAttributes* pDeck); + double framePositionToSeconds(mixxx::audio::FramePos position, DeckAttributes* pDeck); TrackPointer getNextTrackFromQueue(); bool loadNextTrackFromQueue(const DeckAttributes& pDeck, bool play = false);