Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnalyzerSilence: Use mixxx::audio::FramePos in storeResults() #4074

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}