Skip to content

Commit

Permalink
Add Reanalyze action to WTrackMenu
Browse files Browse the repository at this point in the history
The reanalyze action automatically clears the beatgrid and adds the
selected tracks to the analysis queue.
  • Loading branch information
fwcd committed Jun 16, 2022
1 parent 78d2103 commit 9f14d5c
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/library/browse/browsetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ TrackModel::Capabilities BrowseTableModel::getCapabilities() const {
Capability::LoadToDeck |
Capability::LoadToPreviewDeck |
Capability::LoadToSampler |
Capability::RemoveFromDisk;
Capability::RemoveFromDisk |
Capability::Analyze;
}

QString BrowseTableModel::modelKey(bool noSearch) const {
Expand Down
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;
}
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
36 changes: 35 additions & 1 deletion src/widget/wtrackmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ void WTrackMenu::createActions() {
&WTrackMenu::slotClearBeats);
}

if (featureIsEnabled(Feature::Reanalyze)) {
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 +550,10 @@ void WTrackMenu::setupActions() {
addMenu(m_pClearMetadataMenu);
}

if (m_pReanalyzeAction) {
addAction(m_pReanalyzeAction);
}

// 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 +1312,21 @@ void WTrackMenu::addSelectionToNewCrate() {
}
}

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

emit m_pLibrary->analyzeTracks(trackIds);
}

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

void WTrackMenu::slotLockBpm() {
lockBpm(true);
}
Expand Down Expand Up @@ -1470,7 +1494,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 +1504,10 @@ void WTrackMenu::slotClearBeats() {
&trackOperator);
}

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

namespace {

class ResetRatingTrackPointerOperation : public mixxx::TrackPointerOperation {
Expand Down Expand Up @@ -2140,6 +2168,12 @@ bool WTrackMenu::featureIsEnabled(Feature flag) const {
TrackModel::Capability::RemoveCrate);
case Feature::Metadata:
return m_pTrackModel->hasCapabilities(TrackModel::Capability::EditMetadata);
case Feature::Reanalyze:
// TODO: Do we actually need the EditMetadata capability here?
// (We do reset the beatgrid before reanalyzing)
return m_pTrackModel->hasCapabilities(
TrackModel::Capability::EditMetadata |
TrackModel::Capability::Analyze);
case Feature::Reset:
return m_pTrackModel->hasCapabilities(
TrackModel::Capability::EditMetadata |
Expand Down
11 changes: 10 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,
Reanalyze = 1 << 16,
TrackModelFeatures = Remove | HideUnhidePurge,
All = AutoDJ | LoadTo | Playlist | Crate | Remove | Metadata | Reset |
All = AutoDJ | LoadTo | Playlist | Crate | Remove | Metadata | Reset | Reanalyze |
BPM | Color | HideUnhidePurge | RemoveFromDisk | FileBrowser |
Properties | SearchRelated | UpdateReplayGainFromPregain | SelectInLibrary
};
Expand Down Expand Up @@ -109,6 +110,9 @@ class WTrackMenu : public QMenu {
void slotClearWaveform();
void slotClearAllMetadata();

// Analyze
void slotReanalyze();

// BPM
void slotLockBpm();
void slotUnlockBpm();
Expand Down Expand Up @@ -180,7 +184,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 @@ -272,6 +278,9 @@ class WTrackMenu : public QMenu {
// Track color
WColorPickerAction* m_pColorPickerAction{};

// Reset beats and analyze track action
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::Reanalyze |
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::Reanalyze |
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::Reanalyze |
WTrackMenu::Feature::BPM |
WTrackMenu::Feature::Color |
WTrackMenu::Feature::FileBrowser |
Expand Down

0 comments on commit 9f14d5c

Please sign in to comment.