From 630b6da8995eeff7aeeed02cb4f2a8fed5910675 Mon Sep 17 00:00:00 2001 From: Lukas Waslowski Date: Sat, 27 Apr 2024 19:34:01 +0000 Subject: [PATCH] AutoDJProcessor: Trigger recalculation of the remaining play time when relevant The following data points are used as inputs for the "remaining time" calculation, and should therefore trigger a recalculation: * The list of tracks in the Auto DJ playlist (both the set of tracks and their order are important). We subscribe to PlaylistTableModel::tracksChanged to receive the relevant notifications. * The AutoDJ transition mode and transition time settings. We will be notified via ::setTransitionMode and ::setTransitionTime, respectively. * The Intro, Outro & N60dBSound cues of all tracks that are contained in the Auto DJ queue. We subscribe to TrackCollection::tracksChanged and TrackCollection::multipleTracksChanged to receive notifications about possible changes. As of now, we do not filter the notifications, and simply trigger a recalculation when ANY track has changed. --- src/library/autodj/autodjprocessor.cpp | 55 ++++++++++++++++++++++++++ src/library/autodj/autodjprocessor.h | 4 ++ 2 files changed, 59 insertions(+) diff --git a/src/library/autodj/autodjprocessor.cpp b/src/library/autodj/autodjprocessor.cpp index c2110e68080..ef121f30c8e 100644 --- a/src/library/autodj/autodjprocessor.cpp +++ b/src/library/autodj/autodjprocessor.cpp @@ -4,6 +4,8 @@ #include "control/controlpushbutton.h" #include "engine/channels/enginedeck.h" #include "library/playlisttablemodel.h" +#include "library/trackcollection.h" +#include "library/trackcollectionmanager.h" #include "mixer/basetrackplayer.h" #include "mixer/playermanager.h" #include "moc_autodjprocessor.cpp" @@ -235,6 +237,14 @@ AutoDJProcessor::AutoDJProcessor( &PlaylistTableModel::tracksChanged, this, &AutoDJProcessor::playlistTracksChanged); + connect(pTrackCollectionManager->internalCollection(), + &TrackCollection::tracksChanged, + this, + &AutoDJProcessor::tracksChanged); + connect(pTrackCollectionManager->internalCollection(), + &TrackCollection::multipleTracksChanged, + this, + &AutoDJProcessor::multipleTracksChanged); // TODO(rryan) listen to signals from PlayerManager and add/remove as decks // are created. @@ -299,6 +309,43 @@ void AutoDJProcessor::setCrossfader(double value) { void AutoDJProcessor::playlistTracksChanged() { m_pTracksRemaining->set(m_pAutoDJTableModel->rowCount()); + updateRemainingTime(); +} + +void AutoDJProcessor::tracksChanged(const QSet& tracks) { + Q_UNUSED(tracks); + updateRemainingTime(); +} + +void AutoDJProcessor::multipleTracksChanged() { + updateRemainingTime(); +} + +void AutoDJProcessor::updateRemainingTime() { + // The following data points are used as inputs for the "remaining time" + // calculation, and should therefore trigger a recalculation: + // + // * The list of tracks in the Auto DJ playlist (both + // the set of tracks and their order are important). + // + // We subscribe to PlaylistTableModel::tracksChanged + // to receive the relevant notifications. + // + // * The AutoDJ transition mode and transition time settings. + // We will be notified via ::setTransitionMode + // and ::setTransitionTime, respectively. + // + // * The Intro, Outro & N60dBSound cues of all tracks + // that are contained in the Auto DJ queue. + // + // We subscribe to TrackCollection::tracksChanged + // and TrackCollection::multipleTracksChanged to + // receive notifications about possible changes. + // + // As of now, we do not filter the notifications, + // and simply trigger a recalculation when ANY + // track has changed. + // m_pTimeRemaining->set(calculateRemainingTime().toDoubleSeconds()); } @@ -1856,6 +1903,10 @@ void AutoDJProcessor::setTransitionTime(int time) { calculateTransition(pRightDeck, pLeftDeck, false); } } + + // Recalculate the duration of the Auto DJ playlist, + // which may have been affected by the transition time change + updateRemainingTime(); } void AutoDJProcessor::setTransitionMode(TransitionMode newMode) { @@ -1897,6 +1948,10 @@ void AutoDJProcessor::setTransitionMode(TransitionMode newMode) { // user has manually started the other deck or stopped both. // don't know what to do. } + + // Recalculate the duration of the Auto DJ playlist, + // which may have been affected by the transition mode change + updateRemainingTime(); } DeckAttributes* AutoDJProcessor::getLeftDeck() { diff --git a/src/library/autodj/autodjprocessor.h b/src/library/autodj/autodjprocessor.h index e50f46b70e8..bd9e7ff2d0b 100644 --- a/src/library/autodj/autodjprocessor.h +++ b/src/library/autodj/autodjprocessor.h @@ -8,6 +8,7 @@ #include "engine/channels/enginechannel.h" #include "preferences/usersettings.h" #include "track/track_decl.h" +#include "track/trackid.h" #include "util/class.h" #include "util/duration.h" @@ -277,6 +278,9 @@ class AutoDJProcessor : public QObject { void playerRateChanged(DeckAttributes* pDeck); void playlistTracksChanged(); + void tracksChanged(const QSet& tracks); + void multipleTracksChanged(); + void updateRemainingTime(); void controlEnableChangeRequest(double value); void controlFadeNow(double value);