Skip to content

Commit

Permalink
AutoDJProcessor: Trigger recalculation of the remaining play time whe…
Browse files Browse the repository at this point in the history
…n 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.
  • Loading branch information
cr7pt0gr4ph7 committed Apr 27, 2024
1 parent 393641a commit 630b6da
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/library/autodj/autodjprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -235,6 +237,14 @@ AutoDJProcessor::AutoDJProcessor(
&PlaylistTableModel::tracksChanged,

Check failure on line 237 in src/library/autodj/autodjprocessor.cpp

View workflow job for this annotation

GitHub Actions / clazy

'tracksChanged' is a private member of 'BaseSqlTableModel'

Check failure on line 237 in src/library/autodj/autodjprocessor.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

‘void BaseSqlTableModel::tracksChanged(const QSet<TrackId>&)’ is private within this context

Check failure on line 237 in src/library/autodj/autodjprocessor.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy

'tracksChanged' is a private member of 'BaseSqlTableModel' [clang-diagnostic-error]

Check failure on line 237 in src/library/autodj/autodjprocessor.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 x64

'tracksChanged' is a private member of 'BaseSqlTableModel'

Check failure on line 237 in src/library/autodj/autodjprocessor.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 arm64

'tracksChanged' is a private member of 'BaseSqlTableModel'

Check failure on line 237 in src/library/autodj/autodjprocessor.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘void BaseSqlTableModel::tracksChanged(const QSet<TrackId>&)’ is private within this context

Check failure on line 237 in src/library/autodj/autodjprocessor.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'BaseSqlTableModel::tracksChanged': cannot access private member declared in class 'BaseSqlTableModel'
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.
Expand Down Expand Up @@ -299,6 +309,43 @@ void AutoDJProcessor::setCrossfader(double value) {

void AutoDJProcessor::playlistTracksChanged() {
m_pTracksRemaining->set(m_pAutoDJTableModel->rowCount());
updateRemainingTime();
}

void AutoDJProcessor::tracksChanged(const QSet<TrackId>& 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());
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 4 additions & 0 deletions src/library/autodj/autodjprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -277,6 +278,9 @@ class AutoDJProcessor : public QObject {
void playerRateChanged(DeckAttributes* pDeck);

void playlistTracksChanged();
void tracksChanged(const QSet<TrackId>& tracks);
void multipleTracksChanged();
void updateRemainingTime();

void controlEnableChangeRequest(double value);
void controlFadeNow(double value);
Expand Down

0 comments on commit 630b6da

Please sign in to comment.