Skip to content

Commit

Permalink
AutoDJProcessor: Feature: Accurately calculate the remaining play time
Browse files Browse the repository at this point in the history
  • Loading branch information
cr7pt0gr4ph7 committed Apr 27, 2024
1 parent c6ee283 commit 393641a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
45 changes: 44 additions & 1 deletion src/library/autodj/autodjprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,50 @@ void AutoDJProcessor::setCrossfader(double value) {

void AutoDJProcessor::playlistTracksChanged() {
m_pTracksRemaining->set(m_pAutoDJTableModel->rowCount());
m_pTimeRemaining->set(m_pAutoDJTableModel->getTotalDuration().toDoubleSeconds());
m_pTimeRemaining->set(calculateRemainingTime().toDoubleSeconds());
}

mixxx::Duration AutoDJProcessor::calculateRemainingTime() {
if (m_transitionMode == TransitionMode::FullIntroOutro ||
m_transitionMode == TransitionMode::FadeAtOutroStart ||
m_transitionMode == TransitionMode::FixedSkipSilence) {
// The transition time between two tracks depends on both
// tracks for some transition modes
TrackPointer previousTrack;

double durationTotal = 0.0;
const int numOfTracks = m_pAutoDJTableModel->rowCount();
for (int i = 0; i < numOfTracks; i++) {
TrackPointer track = m_pAutoDJTableModel->getTrack(m_pAutoDJTableModel->index(i, 0));
if (previousTrack) {
TrackAttributes fromTrack(previousTrack);
TrackAttributes toTrack(track);
calculateTransitionImpl(fromTrack, toTrack, true);
durationTotal += track->getDuration() - fromTrack.fadeDurationSeconds;
} else {
// TODO: Take the transition between an already playing deck
// and the top of the Auto DJ queue into account?
durationTotal += track->getDuration();
}
previousTrack = track;
}

return mixxx::Duration::fromSeconds(durationTotal);
} else {
// This is the simplest case of the tracks' actual play time
// being equal to their duration minus the fixed fade time.
// No fade time is applied to the last track.
int numTracks = m_pAutoDJTableModel->rowCount();
if (numTracks >= 2) {
// A negative transition time causes silence to be inserted
// between the tracks, which is accurately reflected here
// as an increase of the total playtime.
return m_pAutoDJTableModel->getTotalDuration() -
mixxx::Duration::fromSeconds((numTracks - 1) * m_transitionTime);
} else {
return m_pAutoDJTableModel->getTotalDuration();
}
}
}

AutoDJProcessor::AutoDJError AutoDJProcessor::shufflePlaylist(
Expand Down
5 changes: 5 additions & 0 deletions src/library/autodj/autodjprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "preferences/usersettings.h"
#include "track/track_decl.h"
#include "util/class.h"
#include "util/duration.h"

class ControlPushButton;
class TrackCollectionManager;
Expand Down Expand Up @@ -333,6 +334,10 @@ class AutoDJProcessor : public QObject {
DeckAttributes* getOtherDeck(const DeckAttributes* pThisDeck);
DeckAttributes* getFromDeck();

/// Calculates the total remaining duration of tracks in the AutoDJ playlist,
/// excluding the track that is currently playing already.
mixxx::Duration calculateRemainingTime();

// Removes the track loaded to the player group from the top of the AutoDJ
// queue if it is present.
bool removeLoadedTrackFromTopOfQueue(const DeckAttributes& deck);
Expand Down

0 comments on commit 393641a

Please sign in to comment.