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

AutoDJ: Show total track time #4846

Draft
wants to merge 26 commits into
base: 2.4
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f0b4f6d
DlgAutoDJ: Show total track time
ninomp Jul 5, 2022
a29f375
Introduce PlaylistStorage
ninomp Jul 10, 2022
7f94c69
Fix build on macOS 11
ninomp Dec 2, 2022
f059b36
Use PlaylistStorage to retrieve summary of AutoDJ playlist
ninomp Dec 2, 2022
865a429
DlgAutoDJ: Rename updateInfo() to updateTotalInfo()
ninomp Dec 2, 2022
4a110a9
DlgAutoDJ: Rename labelInfo to labelTotalInfo
ninomp Dec 2, 2022
4555fe8
PlaylistStorage: Introduce readAutoDJPlaylistSummary()
ninomp Dec 3, 2022
8850afb
Show total AutoDJ track time in sidebar
ninomp Dec 4, 2022
7cc0230
Resolve code formatting issue
ninomp Dec 10, 2022
1798e32
Show AutoDJ track count in sidebar also
ninomp Dec 21, 2022
9fadb20
Sidebar: Cache AutoDJ feature title
ninomp Dec 21, 2022
fe7b602
Replace QString with QStringLiteral where possible
ninomp Dec 21, 2022
5f588b0
DlgAutoDJ: Add null checks for accessing PlaylistDAO and PlaylistStorage
ninomp Jan 16, 2023
6861456
Remove unnecessary ASCII Art from playliststorage.h
ninomp Jan 16, 2023
86c9577
Fix regression caused by fe7b602e653ae177ed11c9f6f2ba24d23680584b
ninomp Feb 17, 2023
ef6a67c
Merge commit '7c70ceed718471bb5b8bebd216b661f7af7819f4' into autodj_t…
ninomp Feb 18, 2023
ea0e42d
Merge commit '302b40eefe6948a7080d1ee87bedafdf48624f69' into autodj_t…
ninomp Feb 19, 2023
18dd4cb
AutoDJ: Indicate that total track length is (over)estimated
ninomp Feb 19, 2023
85aedee
PlaylistFeature: Address MSVC warning
ninomp Apr 28, 2023
310c57d
Merge commit '271903bcb43826e0d9f55f0b38c1b4768b5f5999' into autodj_t…
ninomp Nov 18, 2023
bae8706
Merge commit '468ee176d0cc434ebcfa80e9aaab969f91497333' into autodj_t…
ninomp Nov 18, 2023
767e6d6
Merge commit 'a09236f12a7d7a0f6e45d91101c96f3640ba5f68' into autodj_t…
ninomp Nov 18, 2023
9f901aa
Merge commit 'e66e177158fd4e2beb3edc4149d6ff7b79675983' into autodj_t…
ninomp Nov 19, 2023
4c0ccae
Fix build
ninomp Dec 20, 2023
e6a954a
Address code style issue detected by pre-commit
ninomp Dec 22, 2023
dea1a7c
AutoDJ: Left align selection/total time
ninomp Dec 25, 2023
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/library/trackset/crate/cratestorage.cpp
src/library/trackset/crate/cratetablemodel.cpp
src/library/trackset/playlistfeature.cpp
src/library/trackset/playlist/playliststorage.cpp
src/library/trackset/setlogfeature.cpp
src/library/trackset/tracksettablemodel.cpp
src/library/traktor/traktorfeature.cpp
Expand Down
1 change: 1 addition & 0 deletions res/skins/LateNight/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ QLabel#labelTransitionAppendix {
margin-left: 3px;
}
QLabel#labelProgress, /* Analysis progress */
QLabel#labelTotalInfo, /* AutoDJ track total info */
QLabel#labelSelectionInfo /* AutoDJ track selection info */ {
margin: 2px 5px 5px 1px;
}
Expand Down
1 change: 1 addition & 0 deletions res/skins/LateNight/style_palemoon.qss
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,7 @@ WSearchLineEdit {
margin: 6px 3px 4px 3px;
}
QLabel#labelProgress, /* Analysis progress */
QLabel#labelTotalInfo, /* AutoDJ track total info */
QLabel#labelSelectionInfo /* AutoDJ track selection info */ {
margin: 4px 5px 5px 1px;
}
Expand Down
3 changes: 3 additions & 0 deletions res/skins/Tango/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -2844,6 +2844,7 @@ Library features and their buttons:
QPushButton#pushButtonFadeNow
QSpinBox#spinBoxTransition
QLabel#labelSelectionInfo
QLabel#labelTotalInfo
DlgAnalysis
+ some small margin to maximize and cover art button
+ make radio buttons blue like active keylock button
Expand Down Expand Up @@ -2984,6 +2985,8 @@ QPushButton#pushButtonRepeatPlaylist:!checked {
/* Push labels away from buttons at the right */
/* AutoDJ selection info */
QLabel#labelSelectionInfo,
/* AutoDJ total info */
QLabel#labelTotalInfo,
/* Analysis progress info */
QLabel#labelProgress {
margin: 0px 4px 5px 2px;
Expand Down
33 changes: 32 additions & 1 deletion src/library/autodj/autodjfeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,21 @@ AutoDJFeature::AutoDJFeature(Library* pLibrary,
this,
&AutoDJFeature::slotCrateChanged);

// Be notified when tracks are added/removed to/from playlist(s).
connect(&m_playlistDao,
&PlaylistDAO::tracksChanged,
this,
&AutoDJFeature::slotPlaylistsChanged);

// 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,
this,
&AutoDJFeature::slotRemoveCrateFromAutoDj);

updateTitle();
}

AutoDJFeature::~AutoDJFeature() {
Expand All @@ -107,7 +115,22 @@ AutoDJFeature::~AutoDJFeature() {
}

QVariant AutoDJFeature::title() {
return tr("Auto DJ");
return m_title;
}

void AutoDJFeature::updateTitle() {
QString title = tr("Auto DJ");

PlaylistSummary summary;
if (m_pTrackCollection->playlists().readAutoDJPlaylistSummary(&summary) &&
summary.getTrackCount() > 0) {
title.append(QStringLiteral(" (%1) <%2")
.arg(QString::number(summary.getTrackCount()),
summary.getTrackDurationText()));
}

m_title = title;
emit featureIsLoading(this, false);
}

void AutoDJFeature::bindLibraryWidget(
Expand Down Expand Up @@ -320,3 +343,11 @@ void AutoDJFeature::slotRandomQueue(int numTracksToAdd) {
slotAddRandomTrack();
}
}

void AutoDJFeature::slotPlaylistsChanged(const QSet<int>& playlistIds) {
if (playlistIds.contains(m_iAutoDJPlaylistId)) {
// If AutoDJ playlist was changed, notify that feature title has changed
// since it contains duration of the AutoDJ playlist.
updateTitle();
}
}
6 changes: 6 additions & 0 deletions src/library/autodj/autodjfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class AutoDJFeature : public LibraryFeature {

QPointer<WLibrarySidebar> m_pSidebarWidget;

QString m_title;

void updateTitle();

private slots:
// Add a crate to the auto-DJ queue.
void slotAddCrateToAutoDj(CrateId crateId);
Expand All @@ -96,4 +100,6 @@ class AutoDJFeature : public LibraryFeature {
// Adds a random track from the queue upon hitting minimum number
// of tracks in the playlist
void slotRandomQueue(int numTracksToAdd);

void slotPlaylistsChanged(const QSet<int>& playlistIds);
};
36 changes: 30 additions & 6 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "controllers/keyboard/keyboardeventfilter.h"
#include "library/library.h"
#include "library/playlisttablemodel.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "moc_dlgautodj.cpp"
#include "track/track.h"
#include "util/assert.h"
Expand Down Expand Up @@ -34,7 +36,13 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent,
parent->getTrackTableBackgroundColorOpacity(),
/*no sorting*/ false)),
m_bShowButtonText(parent->getShowButtonText()),
m_pAutoDJTableModel(nullptr) {
m_pAutoDJTableModel(nullptr),
m_pTrackCollection(nullptr) {
TrackCollectionManager* pTrackCollectionManager = pLibrary->trackCollectionManager();
DEBUG_ASSERT(pTrackCollectionManager != nullptr);
m_pTrackCollection = pTrackCollectionManager->internalCollection();
DEBUG_ASSERT(m_pTrackCollection != nullptr);

setupUi(this);

m_pTrackTableView->installEventFilter(pKeyboard);
Expand All @@ -56,6 +64,11 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent,
this,
&DlgAutoDJ::updateSelectionInfo);

connect(&m_pTrackCollection->getPlaylistDAO(),
&PlaylistDAO::tracksChanged,
this,
&DlgAutoDJ::updateTotalInfo);

connect(pLibrary,
&Library::setTrackTableFont,
m_pTrackTableView,
Expand Down Expand Up @@ -219,6 +232,7 @@ DlgAutoDJ::DlgAutoDJ(WLibrary* parent,
autoDJStateChanged(m_pAutoDJProcessor->getState());

updateSelectionInfo();
updateTotalInfo();
}

DlgAutoDJ::~DlgAutoDJ() {
Expand Down Expand Up @@ -374,20 +388,30 @@ void DlgAutoDJ::updateSelectionInfo() {
}
}

QString label;

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

void DlgAutoDJ::updateTotalInfo() {
PlaylistSummary summary;
if (!m_pTrackCollection->playlists().readAutoDJPlaylistSummary(&summary)) {
return;
}

labelTotalInfo->setText(QStringLiteral("<%1 (%2)")
.arg(summary.getTrackDurationText(),
QString::number(summary.getTrackCount())));
}

bool DlgAutoDJ::hasFocus() const {
return m_pTrackTableView->hasFocus();
}
Expand Down
3 changes: 3 additions & 0 deletions src/library/autodj/dlgautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class WLibrary;
class WTrackTableView;
class Library;
class KeyboardEventFilter;
class TrackCollection;

class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
Q_OBJECT
Expand Down Expand Up @@ -45,6 +46,7 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
void transitionSliderChanged(int value);
void autoDJStateChanged(AutoDJProcessor::AutoDJState state);
void updateSelectionInfo();
void updateTotalInfo();
void slotTransitionModeChanged(int comboboxIndex);
void slotRepeatPlaylistChanged(int checkedState);

Expand All @@ -67,6 +69,7 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
const bool m_bShowButtonText;

PlaylistTableModel* m_pAutoDJTableModel;
TrackCollection* m_pTrackCollection;

QString m_enableBtnTooltip;
QString m_disableBtnTooltip;
Expand Down
23 changes: 15 additions & 8 deletions src/library/autodj/dlgautodj.ui
Original file line number Diff line number Diff line change
Expand Up @@ -199,26 +199,33 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelSelectionInfo">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelTotalInfo">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All other features have the text left aligned. I think we should do it here as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider this comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, labelSelectionInfo does not have text alignment set, so I'm slightly confused why labelTotalInfo would be different.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because in the analysis view the spacer is on the very right.
grafik
I have no strong preferences for one of the options but they should be the same.

<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="labelSelectionInfo">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
3 changes: 3 additions & 0 deletions src/library/trackcollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void TrackCollection::repairDatabase(const QSqlDatabase& database) {

kLogger.info() << "Repairing database";
m_crates.repairDatabase(database);
m_playlists.repairDatabase(database);
}

void TrackCollection::connectDatabase(const QSqlDatabase& database) {
Expand All @@ -83,6 +84,7 @@ void TrackCollection::connectDatabase(const QSqlDatabase& database) {
m_analysisDao.initialize(database);
m_libraryHashDao.initialize(database);
m_crates.connectDatabase(database);
m_playlists.connectDatabase(database);
}

void TrackCollection::disconnectDatabase() {
Expand All @@ -92,6 +94,7 @@ void TrackCollection::disconnectDatabase() {
m_database = QSqlDatabase();
m_trackDao.finish();
m_crates.disconnectDatabase();
m_playlists.disconnectDatabase();
}

void TrackCollection::connectTrackSource(QSharedPointer<BaseTrackCache> pTrackSource) {
Expand Down
7 changes: 7 additions & 0 deletions src/library/trackcollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "library/dao/playlistdao.h"
#include "library/dao/trackdao.h"
#include "library/trackset/crate/cratestorage.h"
#include "library/trackset/playlist/playliststorage.h"
#include "preferences/usersettings.h"
#include "util/thread_affinity.h"

Expand Down Expand Up @@ -51,6 +52,11 @@ class TrackCollection : public QObject,
return m_crates;
}

const PlaylistStorage& playlists() const {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
return m_playlists;
}

TrackDAO& getTrackDAO() {
DEBUG_ASSERT_QOBJECT_THREAD_AFFINITY(this);
return m_trackDao;
Expand Down Expand Up @@ -169,6 +175,7 @@ class TrackCollection : public QObject,

PlaylistDAO m_playlistDao;
CrateStorage m_crates;
PlaylistStorage m_playlists;
CueDAO m_cueDao;
DirectoryDAO m_directoryDao;
AnalysisDao m_analysisDao;
Expand Down
5 changes: 0 additions & 5 deletions src/library/trackset/baseplaylistfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ class BasePlaylistFeature : public BaseTrackSetFeature {
void slotAnalyzePlaylist();

protected:
struct IdAndLabel {
int id;
QString label;
};

virtual void updateChildModel(const QSet<int>& playlistIds);
virtual void clearChildModel();
virtual QString fetchPlaylistLabel(int playlistId) = 0;
Expand Down
12 changes: 12 additions & 0 deletions src/library/trackset/playlist/playlist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "library/trackset/playlist/playlistid.h"
#include "util/db/dbnamedentity.h"

class Playlist : public DbNamedEntity<PlaylistId> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this new class used? Can this be just a typedef? The name is IMHO ambiguous.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, PlaylistSummary class is derived from this class.

Well, I was trying to follow and replicate how CrateStorage is implemented. The idea is that one day PlaylistStorage, which is introduced with this PR, will replace PlaylistDAO, just like CrateStorage replaced CrateDAO.

public:
explicit Playlist(PlaylistId id = PlaylistId())
: DbNamedEntity(id) {
}
~Playlist() override = default;
};
12 changes: 12 additions & 0 deletions src/library/trackset/playlist/playlistid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include "util/db/dbid.h"

class PlaylistId : public DbId {
public:
// Inherit constructors from base class
using DbId::DbId;
};

Q_DECLARE_TYPEINFO(PlaylistId, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(PlaylistId)
Loading