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

Fix reset Main/Intro/Outro behaviour #11482

Merged
merged 4 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion src/analyzer/analyzersilence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ void AnalyzerSilence::storeResults(TrackPointer pTrack) {
pAudibleSound->setStartPosition(firstSound);
pAudibleSound->setEndPosition(lastSound);

setupMainAndIntroCue(pTrack.get(), firstSound, m_pConfig.get());
setupOutroCue(pTrack.get(), lastSound);
}

// static
void AnalyzerSilence::setupMainAndIntroCue(
Track* pTrack, double firstSound, UserSettings* pConfig) {
CuePointer pIntroCue = pTrack->findCueByType(mixxx::CueType::Intro);

double mainCue = pTrack->getCuePoint().getPosition();
Expand All @@ -120,7 +127,7 @@ void AnalyzerSilence::storeResults(TrackPointer pTrack) {
if (mainCue == Cue::kNoPosition || upgradingWithMainCueAtDefault) {
pTrack->setCuePoint(CuePosition(firstSound));
// NOTE: the actual default for this ConfigValue is set in DlgPrefDeck.
} else if (m_pConfig->getValue(ConfigKey("[Controls]", "SetIntroStartAtMainCue"), false) &&
} else if (pConfig->getValue(ConfigKey("[Controls]", "SetIntroStartAtMainCue"), false) &&
pIntroCue == nullptr) {
introStart = mainCue;
}
Expand All @@ -131,7 +138,10 @@ void AnalyzerSilence::storeResults(TrackPointer pTrack) {
pIntroCue->setStartPosition(introStart);
pIntroCue->setEndPosition(Cue::kNoPosition);
}
}

// static
void AnalyzerSilence::setupOutroCue(Track* pTrack, double lastSound) {
CuePointer pOutroCue = pTrack->findCueByType(mixxx::CueType::Outro);
if (pOutroCue == nullptr) {
pOutroCue = pTrack->createAndAddCue();
Expand Down
3 changes: 3 additions & 0 deletions src/analyzer/analyzersilence.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class AnalyzerSilence : public Analyzer {
void storeResults(TrackPointer pTrack) override;
void cleanup() override;

static void setupMainAndIntroCue(Track* pTrack, double firstSound, UserSettings* pConfig);
static void setupOutroCue(Track* pTrack, double lastSound);

private:
UserSettingsPointer m_pConfig;
CSAMPLE m_fThreshold;
Expand Down
8 changes: 4 additions & 4 deletions src/track/track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ void Track::removeCue(const CuePointer& pCue) {
disconnect(pCue.get(), nullptr, this, nullptr);
m_cuePoints.removeOne(pCue);
if (pCue->getType() == mixxx::CueType::MainCue) {
m_record.setCuePoint(CuePosition());
m_record.setCuePoint(Cue::kNoPosition);
}
pCue->setTrackId(TrackId());
markDirtyAndUnlock(&lock);
Expand All @@ -927,12 +927,12 @@ void Track::removeCuesOfType(mixxx::CueType type) {
disconnect(pCue.get(), nullptr, this, nullptr);
pCue->setTrackId(TrackId());
it.remove();
if (type == mixxx::CueType::MainCue) {
m_record.setCuePoint(Cue::kNoPosition);
}
dirty = true;
}
}
if (compareAndSet(m_record.ptrCuePoint(), CuePosition())) {
dirty = true;
}
if (dirty) {
markDirtyAndUnlock(&lock);
emit cuesUpdated();
Expand Down
90 changes: 79 additions & 11 deletions src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QInputDialog>
#include <QModelIndex>

#include "analyzer/analyzersilence.h"
#include "control/controlobject.h"
#include "control/controlproxy.h"
#include "library/coverartutils.h"
Expand Down Expand Up @@ -240,16 +241,16 @@ void WTrackMenu::createActions() {
connect(m_pClearRatingAction, &QAction::triggered, this, &WTrackMenu::slotClearRating);

m_pClearMainCueAction = new QAction(tr("Cue Point"), m_pClearMetadataMenu);
connect(m_pClearMainCueAction, &QAction::triggered, this, &WTrackMenu::slotClearMainCue);
connect(m_pClearMainCueAction, &QAction::triggered, this, &WTrackMenu::slotResetMainCue);

m_pClearHotCuesAction = new QAction(tr("Hotcues"), m_pClearMetadataMenu);
connect(m_pClearHotCuesAction, &QAction::triggered, this, &WTrackMenu::slotClearHotCues);

m_pClearIntroCueAction = new QAction(tr("Intro"), m_pClearMetadataMenu);
connect(m_pClearIntroCueAction, &QAction::triggered, this, &WTrackMenu::slotClearIntroCue);
connect(m_pClearIntroCueAction, &QAction::triggered, this, &WTrackMenu::slotResetIntroCue);

m_pClearOutroCueAction = new QAction(tr("Outro"), m_pClearMetadataMenu);
connect(m_pClearOutroCueAction, &QAction::triggered, this, &WTrackMenu::slotClearOutroCue);
connect(m_pClearOutroCueAction, &QAction::triggered, this, &WTrackMenu::slotResetOutroCue);

m_pClearLoopAction = new QAction(tr("Loop"), m_pClearMetadataMenu);
connect(m_pClearLoopAction, &QAction::triggered, this, &WTrackMenu::slotClearLoop);
Expand Down Expand Up @@ -1322,33 +1323,96 @@ class RemoveCuesOfTypeTrackPointerOperation : public mixxx::TrackPointerOperatio
const mixxx::CueType m_cueType;
};

class ResetMainCueTrackPointerOperation : public mixxx::TrackPointerOperation {
public:
explicit ResetMainCueTrackPointerOperation(UserSettingsPointer pConfig)
: m_pConfig(pConfig) {
}

private:
void doApply(
const TrackPointer& pTrack) const override {
pTrack->removeCuesOfType(mixxx::CueType::MainCue);
CuePointer pAudibleSound = pTrack->findCueByType(mixxx::CueType::AudibleSound);
if (pAudibleSound) {
double firstSound = pAudibleSound->getPosition();
if (firstSound != Cue::kNoPosition) {
AnalyzerSilence::setupMainAndIntroCue(pTrack.get(), firstSound, m_pConfig.get());
}
}
}

UserSettingsPointer m_pConfig;
};

class ResetIntroTrackPointerOperation : public mixxx::TrackPointerOperation {
public:
explicit ResetIntroTrackPointerOperation(UserSettingsPointer pConfig)
: m_pConfig(pConfig) {
}

private:
void doApply(
const TrackPointer& pTrack) const override {
pTrack->removeCuesOfType(mixxx::CueType::Intro);
CuePointer pAudibleSound = pTrack->findCueByType(mixxx::CueType::AudibleSound);
if (pAudibleSound) {
double firstSound = pAudibleSound->getPosition();
if (firstSound != Cue::kNoPosition) {
AnalyzerSilence::setupMainAndIntroCue(pTrack.get(), firstSound, m_pConfig.get());
}
}
}

UserSettingsPointer m_pConfig;
};

class ResetOutroTrackPointerOperation : public mixxx::TrackPointerOperation {
public:
explicit ResetOutroTrackPointerOperation() {
}

private:
void doApply(
const TrackPointer& pTrack) const override {
pTrack->removeCuesOfType(mixxx::CueType::Outro);
CuePointer pAudibleSound = pTrack->findCueByType(mixxx::CueType::AudibleSound);
if (pAudibleSound) {
double lastSound = pAudibleSound->getEndPosition();
if (lastSound != Cue::kNoPosition) {
AnalyzerSilence::setupOutroCue(pTrack.get(), lastSound);
}
}
}
};

} // anonymous namespace

void WTrackMenu::slotClearMainCue() {
void WTrackMenu::slotResetMainCue() {
const auto progressLabelText =
tr("Removing main cue from %n track(s)", "", getTrackCount());
const auto trackOperator =
RemoveCuesOfTypeTrackPointerOperation(mixxx::CueType::MainCue);
ResetMainCueTrackPointerOperation(m_pConfig);
applyTrackPointerOperation(
progressLabelText,
&trackOperator);
}

void WTrackMenu::slotClearOutroCue() {
void WTrackMenu::slotResetOutroCue() {
const auto progressLabelText =
tr("Removing outro cue from %n track(s)", "", getTrackCount());
const auto trackOperator =
RemoveCuesOfTypeTrackPointerOperation(mixxx::CueType::Outro);
ResetOutroTrackPointerOperation();
applyTrackPointerOperation(
progressLabelText,
&trackOperator);
}

void WTrackMenu::slotClearIntroCue() {
void WTrackMenu::slotResetIntroCue() {
const auto progressLabelText =
tr("Removing intro cue from %n track(s)", "", getTrackCount());
const auto trackOperator =
RemoveCuesOfTypeTrackPointerOperation(mixxx::CueType::Intro);
ResetIntroTrackPointerOperation(m_pConfig);
applyTrackPointerOperation(
progressLabelText,
&trackOperator);
Expand Down Expand Up @@ -1432,6 +1496,10 @@ class ResetWaveformTrackPointerOperation : public mixxx::TrackPointerOperation {
m_analysisDao.deleteAnalysesForTrack(pTrack->getId());
pTrack->setWaveform(WaveformPointer());
pTrack->setWaveformSummary(WaveformPointer());
// We Remove the invisible AudibleSound cue here as well, because the
// same reasons that apply for reanalyze of the waveforms applies also
// for the AudibleSound cue.
pTrack->removeCuesOfType(mixxx::CueType::AudibleSound);
}

AnalysisDao& m_analysisDao;
Expand Down Expand Up @@ -1470,14 +1538,14 @@ class ClearAllPerformanceMetadataTrackPointerOperation : public mixxx::TrackPoin
m_resetBeats.apply(pTrack);
m_resetPlayCounter.apply(pTrack);
m_removeMainCue.apply(pTrack);
m_removeIntroCue.apply(pTrack);
m_removeOutroCue.apply(pTrack);
m_removeHotCues.apply(pTrack);
m_removeLoopCues.apply(pTrack);
m_resetKeys.apply(pTrack);
m_resetReplayGain.apply(pTrack);
m_resetWaveform.apply(pTrack);
m_resetRating.apply(pTrack);
m_removeIntroCue.apply(pTrack);
m_removeOutroCue.apply(pTrack);
}

const ResetBeatsTrackPointerOperation m_resetBeats;
Expand Down
6 changes: 3 additions & 3 deletions src/widget/wtrackmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ class WTrackMenu : public QMenu {
void slotClearBeats();
void slotClearPlayCount();
void slotClearRating();
void slotClearMainCue();
void slotResetMainCue();
void slotClearHotCues();
void slotClearIntroCue();
void slotClearOutroCue();
void slotResetIntroCue();
void slotResetOutroCue();
void slotClearLoop();
void slotClearKey();
void slotClearReplayGain();
Expand Down