Skip to content

Commit

Permalink
Merge pull request #4074 from Holzhaus/frame-refactor-analyzer
Browse files Browse the repository at this point in the history
AnalyzerSilence: Use mixxx::audio::FramePos in storeResults()
  • Loading branch information
uklotzde authored Jul 8, 2021
2 parents 4aba92d + f61c710 commit efbf9e2
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/analyzer/analyzersilence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,58 +90,60 @@ 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
// the track is loaded again. In this case, adjust the AudibleSound Cue's
// 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);
if (pOutroCue == nullptr) {
pOutroCue = pTrack->createAndAddCue(
mixxx::CueType::Outro,
Cue::kNoHotCue,
Cue::kNoPosition,
lastSound);
mixxx::audio::kInvalidFramePos,
lastSoundPosition);
}
}

0 comments on commit efbf9e2

Please sign in to comment.