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

AutoDJProcessor: Calculate and expose the number of tracks and accurate total duration in the Auto DJ queue #13183

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
409267e
AutoDJProcessor: Feature: Add control objects for Auto DJ queue status
cr7pt0gr4ph7 Apr 27, 2024
5c6ce7a
AutoDJProcessor: Add TrackOrDeckAttributes
cr7pt0gr4ph7 Apr 27, 2024
b646631
AutoDJProcessor: Add FadeableTrackOrDeckAttributes
cr7pt0gr4ph7 Apr 27, 2024
3eba5f2
AutoDJProcessor: Add calculateTransitionImpl
cr7pt0gr4ph7 Apr 27, 2024
e02dd54
AutoDJProcessor: Feature: Accurately calculate the remaining play time
cr7pt0gr4ph7 Apr 27, 2024
322628a
AutoDJProcessor: Trigger recalculation of the remaining play time whe…
cr7pt0gr4ph7 Apr 27, 2024
6712b63
AutoDJProcessor: Expose getter methods in addition to ControlObjects …
cr7pt0gr4ph7 May 19, 2024
7324a76
AutoDJProcessor: Readability: Append "Second" suffix to variables
cr7pt0gr4ph7 May 18, 2024
8d37fb4
AutoDJProcessor: Readability: Shorten variable names
cr7pt0gr4ph7 May 18, 2024
02c1e91
AutoDJFeature: Fix spelling of 'findOrCreateAutoDjPlaylistId'
cr7pt0gr4ph7 Apr 27, 2024
eb36266
AutoDJFeature: Feature: Append the duration & track count to the Auto…
cr7pt0gr4ph7 Apr 27, 2024
2f5f0ea
DlgAutoDJ: Feature: Display the total duration of the Auto DJ queue (…
cr7pt0gr4ph7 May 19, 2024
0fd83aa
Merge remote-tracking branch 'upstream/main' into autodj-time-remaining
cr7pt0gr4ph7 Oct 4, 2024
746b5b8
AutoDJConstants: Extract common constants into AutoDJConstants.
cr7pt0gr4ph7 Oct 4, 2024
70a926d
TrackOrDeckAttributes: Move TrackOrDeckAttributes and subclasses into…
cr7pt0gr4ph7 Oct 4, 2024
503d0c6
AutoDJProcessor: Rename tracks_remaining/time_remaining COs to queue_…
cr7pt0gr4ph7 Oct 4, 2024
5c6861d
AutoDJProcessor: Avoid possible race condition: Update getQueueDurati…
cr7pt0gr4ph7 Oct 4, 2024
7a00a77
AutoDJProcessor: Fix a few spelling and grammar errors.
cr7pt0gr4ph7 Oct 4, 2024
77ea46f
AutoDJProcessor: Fix: Correctly calculate the time adjustment due to …
cr7pt0gr4ph7 Oct 4, 2024
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
73 changes: 59 additions & 14 deletions src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,43 @@ const QString kViewName = QStringLiteral("Auto DJ");
namespace {
constexpr int kMaxRetrieveAttempts = 3;

int findOrCrateAutoDjPlaylistId(PlaylistDAO& playlistDAO) {
int playlistId = playlistDAO.getPlaylistIdFromName(AUTODJ_TABLE);
// If the AutoDJ playlist does not exist yet then create it.
if (playlistId < 0) {
playlistId = playlistDAO.createPlaylist(
AUTODJ_TABLE, PlaylistDAO::PLHT_AUTO_DJ);
VERIFY_OR_DEBUG_ASSERT(playlistId >= 0) {
qWarning() << "Failed to create Auto DJ playlist!";
}
int findOrCreateAutoDjPlaylistId(PlaylistDAO& playlistDAO) {
int playlistId = playlistDAO.getPlaylistIdFromName(AUTODJ_TABLE);
// If the AutoDJ playlist does not exist yet then create it.
if (playlistId < 0) {
playlistId = playlistDAO.createPlaylist(
AUTODJ_TABLE, PlaylistDAO::PLHT_AUTO_DJ);
VERIFY_OR_DEBUG_ASSERT(playlistId >= 0) {
qWarning() << "Failed to create Auto DJ playlist!";
}
return playlistId;
}
return playlistId;
}

/// Create a title for the Auto DJ node
QString createAutoDjTitle(const QString& name,
int count,
mixxx::Duration duration,
bool showCountRemaining,
bool showTimeRemaining) {
QString result(name);

// Show duration and track count only if Auto DJ queue has tracks
if (count > 0 && showCountRemaining) {
result.append(QStringLiteral(" ("));
result.append(QString::number(count));
result.append(QStringLiteral(")"));
}

if (count > 0 && showTimeRemaining) {
result.append(QStringLiteral(" "));
result.append(mixxx::Duration::formatTime(
duration.toDoubleSeconds(),
mixxx::Duration::Precision::SECONDS));
}

return result;
}
} // anonymous namespace

AutoDJFeature::AutoDJFeature(Library* pLibrary,
Expand All @@ -48,7 +73,7 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary,
: LibraryFeature(pLibrary, pConfig, QStringLiteral("autodj")),
m_pTrackCollection(pLibrary->trackCollectionManager()->internalCollection()),
m_playlistDao(m_pTrackCollection->getPlaylistDAO()),
m_iAutoDJPlaylistId(findOrCrateAutoDjPlaylistId(m_playlistDao)),
m_iAutoDJPlaylistId(findOrCreateAutoDjPlaylistId(m_playlistDao)),
m_pAutoDJProcessor(nullptr),
m_pSidebarModel(make_parented<TreeItemModel>(this)),
m_pAutoDJView(nullptr),
Expand All @@ -68,6 +93,13 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary,
&LibraryFeature::loadTrackToPlayer,
Qt::QueuedConnection);

// Update the title of the "Auto DJ" node when the
// list of queued tracks or their properties have changed.
connect(m_pAutoDJProcessor,
&AutoDJProcessor::remainingTimeChanged,
this,
&AutoDJFeature::slotRemainingQueueDurationChanged);

m_playlistDao.setAutoDJProcessor(m_pAutoDJProcessor);

// Create the "Crates" tree-item under the root item.
Expand All @@ -94,8 +126,8 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary,
this,
&AutoDJFeature::slotCrateChanged);

// Create context-menu items to allow crates to be added to, and removed
// from, the auto-DJ queue.
// Create context menu items to allow crates to be added to,
// and removed from, the auto-DJ queue.
m_pRemoveCrateFromAutoDj = new QAction(tr("Remove Crate as Track Source"), this);
connect(m_pRemoveCrateFromAutoDj,
&QAction::triggered,
Expand All @@ -109,7 +141,20 @@ AutoDJFeature::~AutoDJFeature() {
}

QVariant AutoDJFeature::title() {
return tr("Auto DJ");
return createAutoDjTitle(tr("Auto DJ"),
m_pAutoDJProcessor->getRemainingTracks(),
m_pAutoDJProcessor->getRemainingTime(),
true,
true);
}

void AutoDJFeature::slotRemainingQueueDurationChanged(int numTracks, mixxx::Duration duration) {
Q_UNUSED(numTracks);
Q_UNUSED(duration);

// As documented by the code docs for featureIsLoading,
// it is intended to indicate when the title() has changed.
emit featureIsLoading(this, false);
}

void AutoDJFeature::bindLibraryWidget(
Expand Down
6 changes: 6 additions & 0 deletions src/library/autodj/autodjfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "library/libraryfeature.h"
#include "library/trackset/crate/crate.h"
#include "preferences/usersettings.h"
#include "util/duration.h"
#include "util/parented_ptr.h"

class DlgAutoDJ;
Expand Down Expand Up @@ -99,4 +100,9 @@ class AutoDJFeature : public LibraryFeature {
// Adds a random track from the queue upon hitting minimum number
// of tracks in the playlist
void slotRandomQueue(int numTracksToAdd);

// Updates the title of the "Auto DJ" node with the number of tracks
// and remaining duration when tracks are added to or removed from
// the Auto DJ queue.
void slotRemainingQueueDurationChanged(int len, mixxx::Duration duration);
};
Loading