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

WTrackMenu: Add menu entry for (re)analyzing tracks #4806

Merged
merged 6 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ Library::Library(
&CrateFeature::analyzeTracks,
m_pAnalysisFeature,
&AnalysisFeature::analyzeTracks);
connect(this,
&Library::analyzeTracks,
m_pAnalysisFeature,
&AnalysisFeature::analyzeTracks);
addFeature(m_pAnalysisFeature);
// Suspend a batch analysis while an ad-hoc analysis of
// loaded tracks is in progress and resume it afterwards.
Expand Down
1 change: 1 addition & 0 deletions src/library/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class Library: public QObject {
void enableCoverArtDisplay(bool);
void selectTrack(const TrackId&);
void trackSelected(TrackPointer pTrack);
void analyzeTracks(const QList<TrackId>& trackIds);
#ifdef __ENGINEPRIME__
void exportLibrary();
void exportCrate(CrateId crateId);
Expand Down
3 changes: 2 additions & 1 deletion src/library/librarytablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ TrackModel::Capabilities LibraryTableModel::getCapabilities() const {
Capability::LoadToPreviewDeck |
Capability::Hide |
Capability::ResetPlayed |
Capability::RemoveFromDisk;
Capability::RemoveFromDisk |
Capability::Analyze;
}
3 changes: 2 additions & 1 deletion src/library/playlisttablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ TrackModel::Capabilities PlaylistTableModel::getCapabilities() const {
Capability::LoadToDeck |
Capability::LoadToSampler |
Capability::LoadToPreviewDeck |
Capability::ResetPlayed;
Capability::ResetPlayed |
Capability::Analyze;

if (m_iPlaylistId !=
m_pTrackCollectionManager->internalCollection()
Expand Down
1 change: 1 addition & 0 deletions src/library/trackmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class TrackModel {
RemovePlaylist = 1u << 14u,
RemoveCrate = 1u << 15u,
RemoveFromDisk = 1u << 16u,
Analyze = 1u << 17u,
};
Q_DECLARE_FLAGS(Capabilities, Capability)

Expand Down
3 changes: 2 additions & 1 deletion src/library/trackset/crate/cratetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ TrackModel::Capabilities CrateTableModel::getCapabilities() const {
Capability::LoadToPreviewDeck |
Capability::RemoveCrate |
Capability::ResetPlayed |
Capability::RemoveFromDisk;
Capability::RemoveFromDisk |
Capability::Analyze;

if (m_selectedCrate.isValid()) {
Crate crate;
Expand Down
48 changes: 47 additions & 1 deletion src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ void WTrackMenu::createMenus() {
m_pClearMetadataMenu->setTitle(tr("Reset"));
}

if (featureIsEnabled(Feature::Analyze)) {
m_pAnalyzeMenu = new QMenu(this);
m_pAnalyzeMenu->setTitle(tr("Analyze"));
}

if (featureIsEnabled(Feature::SearchRelated)) {
DEBUG_ASSERT(!m_pSearchRelatedMenu);
m_pSearchRelatedMenu =
Expand Down Expand Up @@ -392,6 +397,14 @@ void WTrackMenu::createActions() {
&WTrackMenu::slotClearBeats);
}

if (featureIsEnabled(Feature::Analyze)) {
m_pAnalyzeAction = new QAction(tr("Analyze"), this);
connect(m_pAnalyzeAction, &QAction::triggered, this, &WTrackMenu::slotAnalyze);

m_pReanalyzeAction = new QAction(tr("Reanalyze"), this);
connect(m_pReanalyzeAction, &QAction::triggered, this, &WTrackMenu::slotReanalyze);
}

// This action is only usable when m_deckGroup is set. That is true only
// for WTrackmenu instantiated by WTrackProperty and other deck widgets, thus
// don't create it if a track model is set.
Expand Down Expand Up @@ -545,6 +558,12 @@ void WTrackMenu::setupActions() {
addMenu(m_pClearMetadataMenu);
}

if (featureIsEnabled(Feature::Analyze)) {
m_pAnalyzeMenu->addAction(m_pAnalyzeAction);
m_pAnalyzeMenu->addAction(m_pReanalyzeAction);
addMenu(m_pAnalyzeMenu);
}

// This action is created only for menus instantiated by deck widgets (e.g.
// WTrackProperty) and if UpdateReplayGainFromPregain is supported.
if (m_pUpdateReplayGainAct) {
Expand Down Expand Up @@ -1303,6 +1322,25 @@ void WTrackMenu::addSelectionToNewCrate() {
}
}

void WTrackMenu::addToAnalysis() {
const TrackIdList trackIds = getTrackIds();
if (trackIds.empty()) {
qWarning() << "No tracks selected for analysis";
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably use qInfo() for all these kind of log messages. I am aware that you simply copied it from existing code.

return;
}

emit m_pLibrary->analyzeTracks(trackIds);
}

void WTrackMenu::slotAnalyze() {
addToAnalysis();
}

void WTrackMenu::slotReanalyze() {
clearBeats();
addToAnalysis();
}

void WTrackMenu::slotLockBpm() {
lockBpm(true);
}
Expand Down Expand Up @@ -1470,7 +1508,7 @@ class ResetBeatsTrackPointerOperation : public mixxx::TrackPointerOperation {

} // anonymous namespace

void WTrackMenu::slotClearBeats() {
void WTrackMenu::clearBeats() {
const auto progressLabelText =
tr("Resetting beats of %n track(s)", "", getTrackCount());
const auto trackOperator =
Expand All @@ -1480,6 +1518,10 @@ void WTrackMenu::slotClearBeats() {
&trackOperator);
}

void WTrackMenu::slotClearBeats() {
clearBeats();
}

namespace {

class ResetRatingTrackPointerOperation : public mixxx::TrackPointerOperation {
Expand Down Expand Up @@ -2140,6 +2182,10 @@ bool WTrackMenu::featureIsEnabled(Feature flag) const {
TrackModel::Capability::RemoveCrate);
case Feature::Metadata:
return m_pTrackModel->hasCapabilities(TrackModel::Capability::EditMetadata);
case Feature::Analyze:
return m_pTrackModel->hasCapabilities(
TrackModel::Capability::EditMetadata |
TrackModel::Capability::Analyze);
case Feature::Reset:
return m_pTrackModel->hasCapabilities(
TrackModel::Capability::EditMetadata |
Expand Down
14 changes: 13 additions & 1 deletion src/widget/wtrackmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ class WTrackMenu : public QMenu {
SearchRelated = 1 << 13,
UpdateReplayGainFromPregain = 1 << 14,
SelectInLibrary = 1 << 15,
Analyze = 1 << 16,
TrackModelFeatures = Remove | HideUnhidePurge,
All = AutoDJ | LoadTo | Playlist | Crate | Remove | Metadata | Reset |
All = AutoDJ | LoadTo | Playlist | Crate | Remove | Metadata | Reset | Analyze |
BPM | Color | HideUnhidePurge | RemoveFromDisk | FileBrowser |
Properties | SearchRelated | UpdateReplayGainFromPregain | SelectInLibrary
};
Expand Down Expand Up @@ -109,6 +110,10 @@ class WTrackMenu : public QMenu {
void slotClearWaveform();
void slotClearAllMetadata();

// Analysis
void slotAnalyze();
void slotReanalyze();

// BPM
void slotLockBpm();
void slotUnlockBpm();
Expand Down Expand Up @@ -180,7 +185,9 @@ class WTrackMenu : public QMenu {
void updateSelectionCrates(QWidget* pWidget);

void addToAutoDJ(PlaylistDAO::AutoDJSendLoc loc);
void addToAnalysis();

void clearBeats();
void lockBpm(bool lock);

void loadSelectionToGroup(const QString& group, bool play = false);
Expand Down Expand Up @@ -216,6 +223,7 @@ class WTrackMenu : public QMenu {
QMenu* m_pMetadataMenu{};
QMenu* m_pMetadataUpdateExternalCollectionsMenu{};
QMenu* m_pClearMetadataMenu{};
QMenu* m_pAnalyzeMenu{};
QMenu* m_pBPMMenu{};
QMenu* m_pColorMenu{};
WCoverArtMenu* m_pCoverMenu{};
Expand Down Expand Up @@ -272,6 +280,10 @@ class WTrackMenu : public QMenu {
// Track color
WColorPickerAction* m_pColorPickerAction{};

// Analysis actions
QAction* m_pAnalyzeAction{};
QAction* m_pReanalyzeAction{};

// Clear track metadata actions
QAction* m_pClearBeatsAction{};
QAction* m_pClearPlayCountAction{};
Expand Down
1 change: 1 addition & 0 deletions src/widget/wtrackproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ constexpr WTrackMenu::Features kTrackMenuFeatures =
WTrackMenu::Feature::Crate |
WTrackMenu::Feature::Metadata |
WTrackMenu::Feature::Reset |
WTrackMenu::Feature::Analyze |
WTrackMenu::Feature::BPM |
WTrackMenu::Feature::Color |
WTrackMenu::Feature::RemoveFromDisk |
Expand Down
1 change: 1 addition & 0 deletions src/widget/wtracktext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ constexpr WTrackMenu::Features kTrackMenuFeatures =
WTrackMenu::Feature::Crate |
WTrackMenu::Feature::Metadata |
WTrackMenu::Feature::Reset |
WTrackMenu::Feature::Analyze |
WTrackMenu::Feature::BPM |
WTrackMenu::Feature::Color |
WTrackMenu::Feature::FileBrowser |
Expand Down
1 change: 1 addition & 0 deletions src/widget/wtrackwidgetgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ constexpr WTrackMenu::Features kTrackMenuFeatures =
WTrackMenu::Feature::Crate |
WTrackMenu::Feature::Metadata |
WTrackMenu::Feature::Reset |
WTrackMenu::Feature::Analyze |
WTrackMenu::Feature::BPM |
WTrackMenu::Feature::Color |
WTrackMenu::Feature::FileBrowser |
Expand Down