From f61c710f6a896febb356567198356bc5d00aef45 Mon Sep 17 00:00:00 2001 From: Jan Holthuis Date: Tue, 6 Jul 2021 15:44:06 +0200 Subject: AnalyzerSilence: Use mixxx::audio::FramePos in storeResults() --- src/analyzer/analyzersilence.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/analyzer') diff --git a/src/analyzer/analyzersilence.cpp b/src/analyzer/analyzersilence.cpp index 11f53ec631..1ded54a610 100644 --- a/src/analyzer/analyzersilence.cpp +++ b/src/analyzer/analyzersilence.cpp @@ -90,16 +90,16 @@ void AnalyzerSilence::storeResults(TrackPointer pTrack) { m_iSignalEnd = m_iFramesProcessed; } - double firstSound = mixxx::kAnalysisChannels * m_iSignalStart; - double lastSound = mixxx::kAnalysisChannels * m_iSignalEnd; + const auto firstSoundPosition = mixxx::audio::FramePos(m_iSignalStart); + const auto lastSoundPosition = mixxx::audio::FramePos(m_iSignalEnd); CuePointer pAudibleSound = pTrack->findCueByType(mixxx::CueType::AudibleSound); if (pAudibleSound == nullptr) { pAudibleSound = pTrack->createAndAddCue( mixxx::CueType::AudibleSound, Cue::kNoHotCue, - firstSound, - lastSound); + firstSoundPosition, + lastSoundPosition); } else { // The user has no way to directly edit the AudibleSound cue. If the user // has deleted the Intro or Outro Cue, this analysis will be rerun when @@ -107,33 +107,35 @@ void AnalyzerSilence::storeResults(TrackPointer pTrack) { // positions. This could be helpful, for example, when the track length // is changed in a different program, or the silence detection threshold // is changed. - pAudibleSound->setStartAndEndPosition(firstSound, lastSound); + pAudibleSound->setStartAndEndPosition(firstSoundPosition, lastSoundPosition); } CuePointer pIntroCue = pTrack->findCueByType(mixxx::CueType::Intro); - double mainCue = pTrack->getCuePoint().getPosition(); - double introStart = firstSound; + mixxx::audio::FramePos mainCuePosition = pTrack->getMainCuePosition(); + mixxx::audio::FramePos introStartPosition = firstSoundPosition; // Before Mixxx 2.3, the default position for the main cue was 0.0. In this // case, move the main cue point to the first sound. This case can be // distinguished from a user intentionally setting the main cue position // to 0.0 at a later time after analysis because in that case the intro cue // would have already been created by this analyzer. - bool upgradingWithMainCueAtDefault = (mainCue == 0.0 && pIntroCue == nullptr); - if (mainCue == Cue::kNoPosition || upgradingWithMainCueAtDefault) { - pTrack->setCuePoint(CuePosition(firstSound)); + bool upgradingWithMainCueAtDefault = + (mainCuePosition == mixxx::audio::kStartFramePos && + pIntroCue == nullptr); + if (!mainCuePosition.isValid() || upgradingWithMainCueAtDefault) { + pTrack->setMainCuePosition(firstSoundPosition); // NOTE: the actual default for this ConfigValue is set in DlgPrefDeck. } else if (m_pConfig->getValue(ConfigKey("[Controls]", "SetIntroStartAtMainCue"), false) && pIntroCue == nullptr) { - introStart = mainCue; + introStartPosition = mainCuePosition; } if (pIntroCue == nullptr) { pIntroCue = pTrack->createAndAddCue( mixxx::CueType::Intro, Cue::kNoHotCue, - introStart, - Cue::kNoPosition); + introStartPosition, + mixxx::audio::kInvalidFramePos); } CuePointer pOutroCue = pTrack->findCueByType(mixxx::CueType::Outro); @@ -141,7 +143,7 @@ void AnalyzerSilence::storeResults(TrackPointer pTrack) { pOutroCue = pTrack->createAndAddCue( mixxx::CueType::Outro, Cue::kNoHotCue, - Cue::kNoPosition, - lastSound); + mixxx::audio::kInvalidFramePos, + lastSoundPosition); } } -- cgit v1.2.3