Skip to content

Commit

Permalink
DlgAutoDJ: Feature: Display the total duration of the Auto DJ queue (…
Browse files Browse the repository at this point in the history
…accounting for transition times)
  • Loading branch information
cr7pt0gr4ph7 committed May 19, 2024
1 parent eb36266 commit 2f5f0ea
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
47 changes: 34 additions & 13 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent,
this,
&DlgAutoDJ::transitionTimeChanged);

connect(m_pAutoDJProcessor,
&AutoDJProcessor::remainingTimeChanged,
this,
&DlgAutoDJ::remainingTimeChanged);

connect(m_pAutoDJProcessor,
&AutoDJProcessor::autoDJError,
this,
Expand Down Expand Up @@ -317,6 +322,12 @@ void DlgAutoDJ::transitionSliderChanged(int value) {
m_pAutoDJProcessor->setTransitionTime(value);
}

void DlgAutoDJ::remainingTimeChanged(int numTracks, mixxx::Duration duration) {
Q_UNUSED(numTracks);
Q_UNUSED(duration);
updateSelectionInfo();
}

void DlgAutoDJ::autoDJStateChanged(AutoDJProcessor::AutoDJState state) {
if (state == AutoDJProcessor::ADJ_DISABLED) {
pushButtonAutoDJ->setChecked(false);
Expand Down Expand Up @@ -362,24 +373,34 @@ void DlgAutoDJ::slotRepeatPlaylistChanged(bool checked) {
}

void DlgAutoDJ::updateSelectionInfo() {
// Obtain the total duration of the whole remaining Auto DJ queue
// from the Auto DJ processor. The calculated time is exact and
// takes transition times, intros, outros etc. into account.
mixxx::Duration totalDuration = m_pAutoDJProcessor->getRemainingTime();
int totalTracks = m_pAutoDJTableModel->rowCount();

// Derive total duration of the selected tracks from the table model.
// This is much faster than getting the duration from individual track
// objects (but does not take transition times into account...)
QModelIndexList indices = m_pTrackTableView->selectionModel()->selectedRows();
mixxx::Duration selectedDuration = m_pAutoDJTableModel->getTotalDuration(indices);
int selectedTracks = indices.size();

// Derive total duration from the table model. This is much faster than
// getting the duration from individual track objects.
mixxx::Duration duration = m_pAutoDJTableModel->getTotalDuration(indices);

// Selected tracks
QString label;

if (!indices.isEmpty()) {
label.append(mixxx::DurationBase::formatTime(duration.toDoubleSeconds()));
label.append(QString(" (%1)").arg(indices.size()));
labelSelectionInfo->setToolTip(tr("Displays the duration and number of selected tracks."));
labelSelectionInfo->setText(label);
labelSelectionInfo->setEnabled(true);
} else {
labelSelectionInfo->setText("");
labelSelectionInfo->setEnabled(false);
label.append(mixxx::DurationBase::formatTime(selectedDuration.toDoubleSeconds()));
label.append(QString(" (%1)").arg(selectedTracks));
label.append(tr(" / "));
}

// Total tracks
label.append(mixxx::DurationBase::formatTime(totalDuration.toDoubleSeconds()));
label.append(QString(" (%1)").arg(totalTracks));

labelSelectionInfo->setToolTip(tr("Displays the duration and number of selected tracks."));
labelSelectionInfo->setText(label);
labelSelectionInfo->setEnabled(true);
}

bool DlgAutoDJ::hasFocus() const {
Expand Down
1 change: 1 addition & 0 deletions src/library/autodj/dlgautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
void autoDJError(AutoDJProcessor::AutoDJError error);
void transitionTimeChanged(int time);
void transitionSliderChanged(int value);
void remainingTimeChanged(int numTracks, mixxx::Duration duration);
void autoDJStateChanged(AutoDJProcessor::AutoDJState state);
void updateSelectionInfo();
void slotTransitionModeChanged(int comboboxIndex);
Expand Down

0 comments on commit 2f5f0ea

Please sign in to comment.