-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
wtrackmenu.cpp
2558 lines (2250 loc) · 91.8 KB
/
wtrackmenu.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "widget/wtrackmenu.h"
#include <QCheckBox>
#include <QDialogButtonBox>
#include <QInputDialog>
#include <QList>
#include <QListWidget>
#include <QModelIndex>
#include <QVBoxLayout>
#include "analyzer/analyzerscheduledtrack.h"
#include "analyzer/analyzersilence.h"
#include "analyzer/analyzertrack.h"
#include "control/controlobject.h"
#include "library/coverartutils.h"
#include "library/dao/trackschema.h"
#include "library/dlgtagfetcher.h"
#include "library/dlgtrackinfo.h"
#include "library/dlgtrackmetadataexport.h"
#include "library/externaltrackcollection.h"
#include "library/library.h"
#include "library/trackcollection.h"
#include "library/trackcollectionmanager.h"
#include "library/trackmodel.h"
#include "library/trackmodeliterator.h"
#include "library/trackprocessing.h"
#include "library/trackset/crate/crate.h"
#include "library/trackset/crate/cratefeaturehelper.h"
#include "library/trackset/crate/cratesummary.h"
#include "mixer/playermanager.h"
#include "moc_wtrackmenu.cpp"
#include "preferences/colorpalettesettings.h"
#include "preferences/configobject.h"
#include "preferences/dialog/dlgprefdeck.h"
#include "sources/soundsourceproxy.h"
#include "track/track.h"
#include "util/defs.h"
#include "util/desktophelper.h"
#include "util/parented_ptr.h"
#include "util/qt.h"
#include "util/widgethelper.h"
#include "widget/findonwebmenufactory.h"
#include "widget/wcolorpickeraction.h"
#include "widget/wcoverartlabel.h"
#include "widget/wcoverartmenu.h"
#include "widget/wfindonwebmenu.h"
#include "widget/wsearchrelatedtracksmenu.h"
#include "widget/wstarrating.h"
constexpr WTrackMenu::Features WTrackMenu::kDeckTrackMenuFeatures;
namespace {
const QString kAppGroup = QStringLiteral("[App]");
const QString samplerTrString(int i) {
return QObject::tr("Sampler %1").arg(i);
}
const char* kOrigTrTextProperty = "origTrText";
const char* kBpmScaleProperty = "bpmScale";
void appendBpmPreviewtoBpmAction(QAction* pAction, const double bpm) {
QString text = pAction->property(kOrigTrTextProperty).toString();
bool ok = false;
const double scale = pAction->property(kBpmScaleProperty).toDouble(&ok);
if (ok && !text.isEmpty()) {
QString scaledBpm = QString::number(bpm * scale, 'f', 2);
// This is claimed to be the most performant way to get
// * 2 decimals for floating point values and
// * no trailing zero or dot for even numbers
// https://stackoverflow.com/a/65789182
while (scaledBpm.back() == '0') {
scaledBpm.chop(1);
}
if (scaledBpm.back() == '.') {
scaledBpm.chop(1);
}
text.append(QStringLiteral(" | %1 BPM").arg(scaledBpm));
pAction->setText(text);
}
}
void storeActionTextAndScaleInProperties(QAction* pAction, const double scale) {
VERIFY_OR_DEBUG_ASSERT(pAction && scale != 0.0) {
return;
}
pAction->setProperty(kOrigTrTextProperty, QVariant::fromValue(pAction->text()));
pAction->setProperty(kBpmScaleProperty, QVariant(scale));
}
} // namespace
WTrackMenu::WTrackMenu(
QWidget* parent,
UserSettingsPointer pConfig,
Library* pLibrary,
Features flags,
TrackModel* trackModel)
: QMenu(parent),
m_pTrackModel(trackModel),
m_pConfig(pConfig),
m_pLibrary(pLibrary),
m_pNumSamplers(kAppGroup, QStringLiteral("num_samplers")),
m_pNumDecks(kAppGroup, QStringLiteral("num_decks")),
m_pNumPreviewDecks(kAppGroup, QStringLiteral("num_preview_decks")),
m_bPlaylistMenuLoaded(false),
m_bCrateMenuLoaded(false),
m_eActiveFeatures(flags),
m_eTrackModelFeatures(Feature::TrackModelFeatures) {
// Warn if any of the chosen features depend on a TrackModel
VERIFY_OR_DEBUG_ASSERT(trackModel || (m_eTrackModelFeatures & flags) == 0) {
// Remove unsupported features
m_eActiveFeatures &= !m_eTrackModelFeatures;
}
createMenus();
createActions();
setupActions();
}
WTrackMenu::~WTrackMenu() {
// ~QPointer() needs the definition of the wrapped type
// upon deletion! Otherwise the behavior is undefined.
// The wrapped types of some QPointer members are only
// forward declared in the header file.
}
int WTrackMenu::getTrackCount() const {
if (m_pTrackModel) {
return m_trackIndexList.size();
} else {
return m_pTrack ? 1 : 0;
}
}
const QString WTrackMenu::getDeckGroup() const {
return m_deckGroup;
}
void WTrackMenu::closeEvent(QCloseEvent* event) {
// Unfortunately, trackMenuVisible(false) is emitted before the menu is effectively
// closed, which causes issues in WTrackProperty::slotShowTrackMenuChangeRequest.
// Explicitly hide() to avoid this.
hide();
// Actually the event is accepted by default. doing it explicitly doesn't hurt.
// If it's not accepted the menu remains open and entire GUI will be blocked!
event->accept();
emit trackMenuVisible(false);
}
void WTrackMenu::popup(const QPoint& pos, QAction* at) {
if (isEmpty()) {
return;
}
QMenu::popup(pos, at);
emit trackMenuVisible(true);
}
void WTrackMenu::createMenus() {
if (featureIsEnabled(Feature::LoadTo)) {
m_pLoadToMenu = new QMenu(this);
m_pLoadToMenu->setTitle(tr("Load to"));
m_pDeckMenu = new QMenu(m_pLoadToMenu);
m_pDeckMenu->setTitle(tr("Deck"));
m_pSamplerMenu = new QMenu(m_pLoadToMenu);
m_pSamplerMenu->setTitle(tr("Sampler"));
}
if (featureIsEnabled(Feature::Playlist)) {
m_pPlaylistMenu = new QMenu(this);
m_pPlaylistMenu->setTitle(tr("Add to Playlist"));
connect(m_pPlaylistMenu, &QMenu::aboutToShow, this, &WTrackMenu::slotPopulatePlaylistMenu);
}
if (featureIsEnabled(Feature::Crate)) {
m_pCrateMenu = new QMenu(this);
m_pCrateMenu->setTitle(tr("Crates"));
m_pCrateMenu->setObjectName("CratesMenu");
connect(m_pCrateMenu, &QMenu::aboutToShow, this, &WTrackMenu::slotPopulateCrateMenu);
}
if (featureIsEnabled(Feature::Metadata)) {
m_pMetadataMenu = new QMenu(this);
m_pMetadataMenu->setTitle(tr("Metadata"));
m_pMetadataUpdateExternalCollectionsMenu = new QMenu(m_pMetadataMenu);
m_pMetadataUpdateExternalCollectionsMenu->setTitle(tr("Update external collections"));
m_pCoverMenu = new WCoverArtMenu(m_pMetadataMenu);
m_pCoverMenu->setTitle(tr("Cover Art"));
connect(m_pCoverMenu, &WCoverArtMenu::coverInfoSelected, this, &WTrackMenu::slotCoverInfoSelected);
connect(m_pCoverMenu, &WCoverArtMenu::reloadCoverArt, this, &WTrackMenu::slotReloadCoverArt);
}
if (featureIsEnabled(Feature::BPM)) {
m_pBPMMenu = new QMenu(this);
m_pBPMMenu->setTitle(tr("Adjust BPM"));
}
if (featureIsEnabled(Feature::Color)) {
m_pColorMenu = new QMenu(this);
m_pColorMenu->setTitle(tr("Select Color"));
}
if (featureIsEnabled(Feature::Reset)) {
m_pClearMetadataMenu = new QMenu(this);
//: Reset metadata in right click track context menu in library
m_pClearMetadataMenu->setTitle(tr("Clear"));
}
if (featureIsEnabled(Feature::Analyze)) {
m_pAnalyzeMenu = new QMenu(this);
m_pAnalyzeMenu->setTitle(tr("Analyze"));
}
if (featureIsEnabled(Feature::SearchRelated)) {
DEBUG_ASSERT(!m_pSearchRelatedMenu);
m_pSearchRelatedMenu =
make_parented<WSearchRelatedTracksMenu>(this);
connect(m_pSearchRelatedMenu,
&QMenu::aboutToShow,
this,
[this] {
m_pSearchRelatedMenu->clear();
const auto pTrack = getFirstTrackPointer();
if (pTrack) {
m_pSearchRelatedMenu->addActionsForTrack(*pTrack);
}
m_pSearchRelatedMenu->setEnabled(
!m_pSearchRelatedMenu->isEmpty());
});
connect(m_pSearchRelatedMenu,
&WSearchRelatedTracksMenu::triggerSearch,
this,
[this](const QString& searchQuery) {
m_pLibrary->searchTracksInCollection(searchQuery);
});
}
if (featureIsEnabled(Feature::FindOnWeb)) {
DEBUG_ASSERT(!m_pFindOnWebMenu);
m_pFindOnWebMenu = make_parented<WFindOnWebMenu>(this);
connect(m_pFindOnWebMenu,
&QMenu::aboutToShow,
this,
[this] {
m_pFindOnWebMenu->clear();
const auto pTrack = getFirstTrackPointer();
if (pTrack) {
mixxx::library::createFindOnWebSubmenus(
m_pFindOnWebMenu,
*pTrack);
}
m_pFindOnWebMenu->setEnabled(
!m_pFindOnWebMenu->isEmpty());
});
}
if (featureIsEnabled(Feature::RemoveFromDisk)) {
// Qt added QFile::MoveToTrash() in 5.15. If that's not available we
// permanently delete files, put the action into a submenu for safety
// reasons and display different messages in the delete dialogs.
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
m_pRemoveFromDiskMenu = new QMenu(this);
m_pRemoveFromDiskMenu->setTitle(tr("Delete Track Files"));
#endif
}
}
void WTrackMenu::createActions() {
const auto hideRemoveKeySequence =
// TODO(XXX): Qt6 replace enum | with QKeyCombination
QKeySequence(static_cast<int>(kHideRemoveShortcutModifier) |
kHideRemoveShortcutKey);
if (featureIsEnabled(Feature::AutoDJ)) {
m_pAutoDJBottomAct = new QAction(tr("Add to Auto DJ Queue (bottom)"), this);
connect(m_pAutoDJBottomAct, &QAction::triggered, this, &WTrackMenu::slotAddToAutoDJBottom);
m_pAutoDJTopAct = new QAction(tr("Add to Auto DJ Queue (top)"), this);
connect(m_pAutoDJTopAct, &QAction::triggered, this, &WTrackMenu::slotAddToAutoDJTop);
m_pAutoDJReplaceAct = new QAction(tr("Add to Auto DJ Queue (replace)"), this);
connect(m_pAutoDJReplaceAct, &QAction::triggered, this, &WTrackMenu::slotAddToAutoDJReplace);
}
if (featureIsEnabled(Feature::LoadTo)) {
m_pAddToPreviewDeck = new QAction(tr("Preview Deck"), m_pLoadToMenu);
// currently there is only one preview deck so just map it here.
QString previewDeckGroup = PlayerManager::groupForPreviewDeck(0);
connect(m_pAddToPreviewDeck, &QAction::triggered, this, [this, previewDeckGroup] { loadSelectionToGroup(previewDeckGroup); });
}
if (featureIsEnabled(Feature::Remove)) {
// Keyboard shortcuts are set here just to have them displayed in the menu.
// Actual keypress is handled in WTrackTableView::keyPressEvent().
m_pRemoveAct = new QAction(tr("Remove"), this);
m_pRemoveAct->setShortcut(hideRemoveKeySequence);
connect(m_pRemoveAct, &QAction::triggered, this, &WTrackMenu::slotRemove);
m_pRemovePlaylistAct = new QAction(tr("Remove from Playlist"), this);
m_pRemovePlaylistAct->setShortcut(hideRemoveKeySequence);
connect(m_pRemovePlaylistAct, &QAction::triggered, this, &WTrackMenu::slotRemove);
m_pRemoveCrateAct = new QAction(tr("Remove from Crate"), this);
m_pRemoveCrateAct->setShortcut(hideRemoveKeySequence);
connect(m_pRemoveCrateAct, &QAction::triggered, this, &WTrackMenu::slotRemove);
}
if (featureIsEnabled(Feature::HideUnhidePurge)) {
m_pHideAct = new QAction(tr("Hide from Library"), this);
// This is just for having the shortcut displayed next to the action in the menu.
// The actual keypress is handled in WTrackTableView::keyPressEvent().
m_pHideAct->setShortcut(hideRemoveKeySequence);
connect(m_pHideAct, &QAction::triggered, this, &WTrackMenu::slotHide);
m_pUnhideAct = new QAction(tr("Unhide from Library"), this);
connect(m_pUnhideAct, &QAction::triggered, this, &WTrackMenu::slotUnhide);
m_pPurgeAct = new QAction(tr("Purge from Library"), this);
connect(m_pPurgeAct, &QAction::triggered, this, &WTrackMenu::slotPurge);
}
if (featureIsEnabled(Feature::RemoveFromDisk)) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
m_pRemoveFromDiskAct = new QAction(tr("Move Track File(s) to Trash"), this);
#else
m_pRemoveFromDiskAct = new QAction(tr("Delete Files from Disk"), m_pRemoveFromDiskMenu);
#endif
connect(m_pRemoveFromDiskAct,
&QAction::triggered,
this,
&WTrackMenu::slotRemoveFromDisk);
}
if (featureIsEnabled(Feature::Properties)) {
m_pPropertiesAct = new QAction(tr("Properties"), this);
// This is just for having the shortcut displayed next to the action
// when the menu is invoked from the tracks table.
// The keypress is caught in WTrackTableView::keyPressEvent
if (m_pTrackModel) {
m_pPropertiesAct->setShortcut(
// TODO(XXX): Qt6 replace enum | with QKeyCombination
QKeySequence(
static_cast<int>(kPropertiesShortcutModifier) |
kPropertiesShortcutKey));
}
connect(m_pPropertiesAct, &QAction::triggered, this, &WTrackMenu::slotShowDlgTrackInfo);
}
if (featureIsEnabled(Feature::FileBrowser)) {
m_pFileBrowserAct = new QAction(tr("Open in File Browser"), this);
connect(m_pFileBrowserAct, &QAction::triggered, this, &WTrackMenu::slotOpenInFileBrowser);
}
if (featureIsEnabled(Feature::SelectInLibrary)) {
m_pSelectInLibraryAct = new QAction(tr("Select in Library"), this);
connect(m_pSelectInLibraryAct, &QAction::triggered, this, &WTrackMenu::slotSelectInLibrary);
}
if (featureIsEnabled(Feature::Metadata)) {
m_pImportMetadataFromFileAct =
new QAction(tr("Import From File Tags"), m_pMetadataMenu);
connect(m_pImportMetadataFromFileAct,
&QAction::triggered,
this,
&WTrackMenu::slotImportMetadataFromFileTags);
m_pImportMetadataFromMusicBrainzAct =
new QAction(tr("Import From MusicBrainz"), m_pMetadataMenu);
connect(m_pImportMetadataFromMusicBrainzAct,
&QAction::triggered,
this,
&WTrackMenu::slotShowDlgTagFetcher);
m_pExportMetadataAct =
new QAction(tr("Export To File Tags"), m_pMetadataMenu);
connect(m_pExportMetadataAct,
&QAction::triggered,
this,
&WTrackMenu::slotExportMetadataIntoFileTags);
m_updateInExternalTrackCollections.reserve(
m_pLibrary->trackCollectionManager()->externalCollections().size());
for (auto* const pExternalTrackCollection :
m_pLibrary->trackCollectionManager()->externalCollections()) {
UpdateExternalTrackCollection updateInExternalTrackCollection;
updateInExternalTrackCollection.externalTrackCollection = pExternalTrackCollection;
updateInExternalTrackCollection.action = new QAction(
pExternalTrackCollection->name(), m_pMetadataMenu);
updateInExternalTrackCollection.action->setToolTip(
pExternalTrackCollection->description());
m_updateInExternalTrackCollections += updateInExternalTrackCollection;
connect(updateInExternalTrackCollection.action,
&QAction::triggered,
this,
[this, pExternalTrackCollection] {
slotUpdateExternalTrackCollection(pExternalTrackCollection);
});
}
}
if (featureIsEnabled(Feature::Reset)) {
// Clear metadata actions
m_pClearBeatsAction = new QAction(tr("BPM and Beatgrid"), m_pClearMetadataMenu);
connect(m_pClearBeatsAction, &QAction::triggered, this, &WTrackMenu::slotClearBeats);
m_pClearPlayCountAction = new QAction(tr("Play Count"), m_pClearMetadataMenu);
connect(m_pClearPlayCountAction, &QAction::triggered, this, &WTrackMenu::slotClearPlayCount);
m_pClearRatingAction = new QAction(tr("Rating"), m_pClearMetadataMenu);
connect(m_pClearRatingAction, &QAction::triggered, this, &WTrackMenu::slotClearRating);
m_pClearMainCueAction = new QAction(tr("Cue Point"), m_pClearMetadataMenu);
connect(m_pClearMainCueAction, &QAction::triggered, this, &WTrackMenu::slotResetMainCue);
m_pClearHotCuesAction = new QAction(tr("Hotcues"), m_pClearMetadataMenu);
connect(m_pClearHotCuesAction, &QAction::triggered, this, &WTrackMenu::slotClearHotCues);
m_pClearIntroCueAction = new QAction(tr("Intro"), m_pClearMetadataMenu);
connect(m_pClearIntroCueAction, &QAction::triggered, this, &WTrackMenu::slotResetIntroCue);
m_pClearOutroCueAction = new QAction(tr("Outro"), m_pClearMetadataMenu);
connect(m_pClearOutroCueAction, &QAction::triggered, this, &WTrackMenu::slotResetOutroCue);
m_pClearLoopsAction = new QAction(tr("Loops"), m_pClearMetadataMenu);
connect(m_pClearLoopsAction, &QAction::triggered, this, &WTrackMenu::slotClearLoops);
m_pClearKeyAction = new QAction(tr("Key"), m_pClearMetadataMenu);
connect(m_pClearKeyAction, &QAction::triggered, this, &WTrackMenu::slotClearKey);
m_pClearReplayGainAction = new QAction(tr("ReplayGain"), m_pClearMetadataMenu);
connect(m_pClearReplayGainAction, &QAction::triggered, this, &WTrackMenu::slotClearReplayGain);
m_pClearWaveformAction = new QAction(tr("Waveform"), m_pClearMetadataMenu);
connect(m_pClearWaveformAction, &QAction::triggered, this, &WTrackMenu::slotClearWaveform);
m_pClearCommentAction = new QAction(tr("Comment"), m_pClearMetadataMenu);
connect(m_pClearCommentAction, &QAction::triggered, this, &WTrackMenu::slotClearComment);
m_pClearAllMetadataAction = new QAction(tr("All"), m_pClearMetadataMenu);
connect(m_pClearAllMetadataAction, &QAction::triggered, this, &WTrackMenu::slotClearAllMetadata);
}
if (featureIsEnabled(Feature::BPM)) {
m_pBpmLockAction = new QAction(tr("Lock BPM"), m_pBPMMenu);
m_pBpmUnlockAction = new QAction(tr("Unlock BPM"), m_pBPMMenu);
connect(m_pBpmLockAction, &QAction::triggered, this, &WTrackMenu::slotLockBpm);
connect(m_pBpmUnlockAction, &QAction::triggered, this, &WTrackMenu::slotUnlockBpm);
//BPM edit actions
m_pBpmDoubleAction = new QAction(tr("Double BPM"), m_pBPMMenu);
storeActionTextAndScaleInProperties(m_pBpmDoubleAction, 2.0);
m_pBpmHalveAction = new QAction(tr("Halve BPM"), m_pBPMMenu);
storeActionTextAndScaleInProperties(m_pBpmHalveAction, 0.5);
m_pBpmTwoThirdsAction = new QAction(tr("2/3 BPM"), m_pBPMMenu);
storeActionTextAndScaleInProperties(m_pBpmTwoThirdsAction, 2.0 / 3.0);
m_pBpmThreeFourthsAction = new QAction(tr("3/4 BPM"), m_pBPMMenu);
storeActionTextAndScaleInProperties(m_pBpmThreeFourthsAction, 3.0 / 4.0);
m_pBpmFourThirdsAction = new QAction(tr("4/3 BPM"), m_pBPMMenu);
storeActionTextAndScaleInProperties(m_pBpmFourThirdsAction, 4.0 / 3.0);
m_pBpmThreeHalvesAction = new QAction(tr("3/2 BPM"), m_pBPMMenu);
storeActionTextAndScaleInProperties(m_pBpmThreeHalvesAction, 3.0 / 2.0);
connect(m_pBpmDoubleAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::BpmScale::Double);
});
connect(m_pBpmHalveAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::BpmScale::Halve);
});
connect(m_pBpmTwoThirdsAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::BpmScale::TwoThirds);
});
connect(m_pBpmThreeFourthsAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::BpmScale::ThreeFourths);
});
connect(m_pBpmFourThirdsAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::BpmScale::FourThirds);
});
connect(m_pBpmThreeHalvesAction, &QAction::triggered, this, [this] {
slotScaleBpm(mixxx::Beats::BpmScale::ThreeHalves);
});
m_pBpmResetAction = new QAction(tr("Clear BPM and Beatgrid"), m_pBPMMenu);
connect(m_pBpmResetAction,
&QAction::triggered,
this,
&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);
m_pReanalyzeConstBpmAction = new QAction(tr("Reanalyze (constant BPM)"), this);
connect(m_pReanalyzeConstBpmAction,
&QAction::triggered,
this,
&WTrackMenu::slotReanalyzeWithFixedTempo);
m_pReanalyzeVarBpmAction = new QAction(tr("Reanalyze (variable BPM)"), this);
connect(m_pReanalyzeVarBpmAction,
&QAction::triggered,
this,
&WTrackMenu::slotReanalyzeWithVariableTempo);
}
// 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.
if (!m_pTrackModel && featureIsEnabled(Feature::UpdateReplayGainFromPregain)) {
m_pUpdateReplayGainAct =
new QAction(tr("Update ReplayGain from Deck Gain"), m_pClearMetadataMenu);
connect(m_pUpdateReplayGainAct,
&QAction::triggered,
this,
&WTrackMenu::slotUpdateReplayGainFromPregain);
}
if (featureIsEnabled(Feature::Color)) {
ColorPaletteSettings colorPaletteSettings(m_pConfig);
m_pColorPickerAction = new WColorPickerAction(WColorPicker::Option::AllowNoColor,
colorPaletteSettings.getTrackColorPalette(),
m_pColorMenu);
m_pColorPickerAction->setObjectName("TrackColorPickerAction");
connect(m_pColorPickerAction,
&WColorPickerAction::colorPicked,
this,
&WTrackMenu::slotColorPicked);
}
}
void WTrackMenu::setupActions() {
if (featureIsEnabled(Feature::SearchRelated)) {
addMenu(m_pSearchRelatedMenu);
}
if (featureIsEnabled(Feature::SelectInLibrary)) {
addAction(m_pSelectInLibraryAct);
}
if (featureIsEnabled(Feature::SearchRelated) ||
featureIsEnabled(Feature::SelectInLibrary)) {
addSeparator();
}
if (featureIsEnabled(Feature::AutoDJ)) {
addAction(m_pAutoDJBottomAct);
addAction(m_pAutoDJTopAct);
addAction(m_pAutoDJReplaceAct);
addSeparator();
}
if (featureIsEnabled(Feature::LoadTo)) {
m_pLoadToMenu->addMenu(m_pDeckMenu);
m_pLoadToMenu->addMenu(m_pSamplerMenu);
if (m_pNumPreviewDecks.get() > 0.0) {
m_pLoadToMenu->addAction(m_pAddToPreviewDeck);
}
addMenu(m_pLoadToMenu);
addSeparator();
}
if (featureIsEnabled(Feature::Playlist)) {
addMenu(m_pPlaylistMenu);
}
if (featureIsEnabled(Feature::Crate)) {
addMenu(m_pCrateMenu);
}
if (featureIsEnabled(Feature::Remove)) {
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::Remove)) {
addAction(m_pRemoveAct);
}
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::RemovePlaylist)) {
addAction(m_pRemovePlaylistAct);
}
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::RemoveCrate)) {
addAction(m_pRemoveCrateAct);
}
}
addSeparator();
if (featureIsEnabled(Feature::BPM)) {
m_pBPMMenu->addAction(m_pBpmHalveAction);
m_pBPMMenu->addAction(m_pBpmTwoThirdsAction);
m_pBPMMenu->addAction(m_pBpmThreeFourthsAction);
m_pBPMMenu->addAction(m_pBpmFourThirdsAction);
m_pBPMMenu->addAction(m_pBpmThreeHalvesAction);
m_pBPMMenu->addAction(m_pBpmDoubleAction);
m_pBPMMenu->addSeparator();
m_pBPMMenu->addAction(m_pBpmLockAction);
m_pBPMMenu->addAction(m_pBpmUnlockAction);
m_pBPMMenu->addSeparator();
m_pBPMMenu->addAction(m_pBpmResetAction);
m_pBPMMenu->addSeparator();
addMenu(m_pBPMMenu);
}
if (featureIsEnabled(Feature::Color)) {
m_pColorMenu->addAction(m_pColorPickerAction);
addMenu(m_pColorMenu);
}
if (featureIsEnabled(Feature::Metadata)) {
m_pMetadataMenu->addAction(m_pImportMetadataFromFileAct);
m_pMetadataMenu->addAction(m_pImportMetadataFromMusicBrainzAct);
m_pMetadataMenu->addAction(m_pExportMetadataAct);
for (const auto& updateInExternalTrackCollection :
std::as_const(m_updateInExternalTrackCollections)) {
m_pMetadataUpdateExternalCollectionsMenu->addAction(
updateInExternalTrackCollection.action);
}
if (!m_pMetadataUpdateExternalCollectionsMenu->isEmpty()) {
m_pMetadataMenu->addMenu(m_pMetadataUpdateExternalCollectionsMenu);
// Enable/disable entries depending on the connection status
// that may change at runtime.
connect(m_pMetadataUpdateExternalCollectionsMenu,
&QMenu::aboutToShow,
this,
[this] {
for (const auto& updateInExternalTrackCollection :
std::as_const(m_updateInExternalTrackCollections)) {
updateInExternalTrackCollection.action->setEnabled(
updateInExternalTrackCollection
.externalTrackCollection
->isConnected());
}
});
}
m_pMetadataMenu->addMenu(m_pCoverMenu);
if (featureIsEnabled(Feature::FindOnWeb)) {
m_pMetadataMenu->addMenu(m_pFindOnWebMenu);
}
addSeparator();
addMenu(m_pMetadataMenu);
}
if (featureIsEnabled(Feature::Reset)) {
m_pClearMetadataMenu->addAction(m_pClearBeatsAction);
m_pClearMetadataMenu->addAction(m_pClearPlayCountAction);
m_pClearMetadataMenu->addAction(m_pClearRatingAction);
m_pClearMetadataMenu->addAction(m_pClearCommentAction);
m_pClearMetadataMenu->addAction(m_pClearMainCueAction);
m_pClearMetadataMenu->addAction(m_pClearHotCuesAction);
m_pClearMetadataMenu->addAction(m_pClearIntroCueAction);
m_pClearMetadataMenu->addAction(m_pClearOutroCueAction);
m_pClearMetadataMenu->addAction(m_pClearLoopsAction);
m_pClearMetadataMenu->addAction(m_pClearKeyAction);
m_pClearMetadataMenu->addAction(m_pClearReplayGainAction);
m_pClearMetadataMenu->addAction(m_pClearWaveformAction);
m_pClearMetadataMenu->addSeparator();
m_pClearMetadataMenu->addAction(m_pClearAllMetadataAction);
addMenu(m_pClearMetadataMenu);
}
if (featureIsEnabled(Feature::Analyze)) {
m_pAnalyzeMenu->addAction(m_pAnalyzeAction);
m_pAnalyzeMenu->addAction(m_pReanalyzeAction);
m_pAnalyzeMenu->addAction(m_pReanalyzeConstBpmAction);
m_pAnalyzeMenu->addAction(m_pReanalyzeVarBpmAction);
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) {
addAction(m_pUpdateReplayGainAct);
}
addSeparator();
if (featureIsEnabled(Feature::HideUnhidePurge)) {
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::Hide)) {
addAction(m_pHideAct);
}
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::Unhide)) {
addAction(m_pUnhideAct);
}
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::Purge)) {
addAction(m_pPurgeAct);
}
}
if (featureIsEnabled(Feature::RemoveFromDisk)) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
addAction(m_pRemoveFromDiskAct);
#else
m_pRemoveFromDiskMenu->addAction(m_pRemoveFromDiskAct);
addMenu(m_pRemoveFromDiskMenu);
#endif
}
if (featureIsEnabled(Feature::FileBrowser)) {
addAction(m_pFileBrowserAct);
}
if (featureIsEnabled(Feature::Properties)) {
addSeparator();
addAction(m_pPropertiesAct);
}
}
std::pair<bool, bool> WTrackMenu::getTrackBpmLockStates() const {
bool anyBpmLocked = false;
bool anyBpmNotLocked = false;
if (m_pTrackModel) {
const int column = m_pTrackModel->fieldIndex(LIBRARYTABLE_BPM_LOCK);
for (const auto& trackIndex : m_trackIndexList) {
QModelIndex bpmLockedIndex = trackIndex.sibling(trackIndex.row(), column);
if (bpmLockedIndex.data().toBool()) {
anyBpmLocked = true;
} else {
anyBpmNotLocked = true;
}
if (anyBpmLocked && anyBpmNotLocked) {
break;
}
}
} else {
if (m_pTrack) {
anyBpmLocked = m_pTrack->isBpmLocked();
anyBpmNotLocked = !anyBpmLocked;
}
}
return std::pair<bool, bool>(anyBpmLocked, anyBpmNotLocked);
}
std::optional<std::optional<mixxx::RgbColor>> WTrackMenu::getCommonTrackColor() const {
VERIFY_OR_DEBUG_ASSERT(!isEmpty()) {
return std::nullopt;
}
std::optional<mixxx::RgbColor> commonColor;
if (m_pTrackModel) {
const int column =
m_pTrackModel->fieldIndex(LIBRARYTABLE_COLOR);
commonColor = mixxx::RgbColor::fromQVariant(
m_trackIndexList.first().sibling(m_trackIndexList.first().row(), column).data());
for (const auto& trackIndex : m_trackIndexList) {
const auto otherColor = mixxx::RgbColor::fromQVariant(
trackIndex.sibling(trackIndex.row(), column).data());
if (commonColor != otherColor) {
// Multiple, different colors
return std::nullopt;
}
}
} else {
if (!m_pTrack) {
return std::nullopt;
}
commonColor = m_pTrack->getColor();
}
return make_optional(commonColor);
}
CoverInfo WTrackMenu::getCoverInfoOfLastTrack() const {
VERIFY_OR_DEBUG_ASSERT(!isEmpty()) {
return CoverInfo();
}
if (m_pTrackModel) {
const QModelIndex lastIndex = m_trackIndexList.last();
CoverInfo coverInfo;
coverInfo.source = static_cast<CoverInfo::Source>(
lastIndex
.sibling(
lastIndex.row(),
m_pTrackModel->fieldIndex(LIBRARYTABLE_COVERART_SOURCE))
.data()
.toInt());
coverInfo.type = static_cast<CoverInfo::Type>(
lastIndex
.sibling(
lastIndex.row(),
m_pTrackModel->fieldIndex(LIBRARYTABLE_COVERART_TYPE))
.data()
.toInt());
coverInfo.color = mixxx::RgbColor::fromQVariant(
lastIndex
.sibling(
lastIndex.row(),
m_pTrackModel->fieldIndex(LIBRARYTABLE_COVERART_COLOR))
.data());
const auto imageDigest =
lastIndex
.sibling(
lastIndex.row(),
m_pTrackModel->fieldIndex(LIBRARYTABLE_COVERART_DIGEST))
.data()
.toByteArray();
const auto legacyHash =
lastIndex
.sibling(
lastIndex.row(),
m_pTrackModel->fieldIndex(LIBRARYTABLE_COVERART_HASH))
.data()
.toUInt();
coverInfo.setImageDigest(imageDigest, legacyHash);
coverInfo.coverLocation =
lastIndex
.sibling(
lastIndex.row(),
m_pTrackModel->fieldIndex(LIBRARYTABLE_COVERART_LOCATION))
.data()
.toString();
coverInfo.trackLocation =
lastIndex
.sibling(
lastIndex.row(),
m_pTrackModel->fieldIndex(TRACKLOCATIONSTABLE_LOCATION))
.data()
.toString();
return coverInfo;
} else {
return m_pTrack->getCoverInfoWithLocation();
}
}
void WTrackMenu::updateMenus() {
if (isEmpty()) {
return;
}
// Gray out some stuff if multiple songs were selected.
const bool singleTrackSelected = getTrackCount() == 1;
if (featureIsEnabled(Feature::LoadTo)) {
int iNumDecks = static_cast<int>(m_pNumDecks.get());
m_pDeckMenu->clear();
if (iNumDecks > 0) {
for (int i = 1; i <= iNumDecks; ++i) {
// PlayerManager::groupForDeck is 0-indexed.
QString deckGroup = PlayerManager::groupForDeck(i - 1);
bool deckPlaying = ControlObject::get(
ConfigKey(deckGroup, "play")) > 0.0;
bool allowLoadTrackIntoPlayingDeck = false;
if (m_pConfig->exists(kConfigKeyLoadWhenDeckPlaying)) {
int loadWhenDeckPlaying =
m_pConfig->getValueString(kConfigKeyLoadWhenDeckPlaying).toInt();
switch (static_cast<LoadWhenDeckPlaying>(loadWhenDeckPlaying)) {
case LoadWhenDeckPlaying::Allow:
case LoadWhenDeckPlaying::AllowButStopDeck:
allowLoadTrackIntoPlayingDeck = true;
break;
case LoadWhenDeckPlaying::Reject:
break;
}
} else {
// support older version of this flag
allowLoadTrackIntoPlayingDeck = m_pConfig->getValue<bool>(
ConfigKey("[Controls]", "AllowTrackLoadToPlayingDeck"));
}
bool deckEnabled =
(!deckPlaying || allowLoadTrackIntoPlayingDeck) &&
singleTrackSelected;
QAction* pAction = new QAction(tr("Deck %1").arg(i), this);
pAction->setEnabled(deckEnabled);
m_pDeckMenu->addAction(pAction);
connect(pAction, &QAction::triggered, this, [this, deckGroup] { loadSelectionToGroup(deckGroup); });
}
}
int iNumSamplers = static_cast<int>(m_pNumSamplers.get());
const int maxSamplersPerMenu = 16;
if (iNumSamplers > 0) {
m_pSamplerMenu->clear();
QMenu* pMenu = m_pSamplerMenu;
int samplersInMenu = 0;
for (int i = 1; i <= iNumSamplers; ++i) {
if (samplersInMenu == maxSamplersPerMenu) {
samplersInMenu = 0;
int limit = iNumSamplers > i + 15 ? i + 15 : iNumSamplers;
const QString label = samplerTrString(i) + QStringLiteral("- %1").arg(limit);
pMenu = new QMenu(label, m_pSamplerMenu);
m_pSamplerMenu->addMenu(pMenu);
}
samplersInMenu++;
// PlayerManager::groupForSampler is 0-indexed.
QString samplerGroup = PlayerManager::groupForSampler(i - 1);
bool samplerPlaying = ControlObject::get(
ConfigKey(samplerGroup, "play")) > 0.0;
bool samplerEnabled = !samplerPlaying && singleTrackSelected;
QAction* pAction = new QAction(samplerTrString(i), pMenu);
pAction->setEnabled(samplerEnabled);
pMenu->addAction(pAction);
connect(pAction,
&QAction::triggered,
this,
[this, samplerGroup] {
loadSelectionToGroup(samplerGroup);
});
}
}
}
if (featureIsEnabled(Feature::Playlist)) {
// Playlist menu is lazy loaded on hover by slotPopulatePlaylistMenu
// to avoid unnecessary database queries
m_bPlaylistMenuLoaded = false;
}
if (featureIsEnabled(Feature::Crate)) {
// Crate menu is lazy loaded on hover by slotPopulateCrateMenu
// to avoid unnecessary database queries
m_bCrateMenuLoaded = false;
}
if (featureIsEnabled(Feature::Remove)) {
bool locked = m_pTrackModel->hasCapabilities(TrackModel::Capability::Locked);
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::Remove)) {
m_pRemoveAct->setEnabled(!locked);
}
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::RemovePlaylist)) {
m_pRemovePlaylistAct->setEnabled(!locked);
}
if (m_pTrackModel->hasCapabilities(TrackModel::Capability::RemoveCrate)) {
m_pRemoveCrateAct->setEnabled(!locked);
}
}
if (featureIsEnabled(Feature::Metadata)) {
m_pImportMetadataFromMusicBrainzAct->setEnabled(singleTrackSelected);
// We use the last selected track for the cover art context to be
// consistent with selectionChanged above.
m_pCoverMenu->setCoverArt(getCoverInfoOfLastTrack());
m_pMetadataMenu->addMenu(m_pCoverMenu);
}
if (featureIsEnabled(Feature::Analyze)) {
bool useFixedTempo = m_pConfig->getValue<bool>(
ConfigKey("[BPM]", "BeatDetectionFixedTempoAssumption"));
// Since we already have a 'Reanalyze' action that uses the configured
// default, we hide the redundant menu as per suggestion:
// https://github.com/mixxxdj/mixxx/pull/10931#issuecomment-1262559750
m_pReanalyzeConstBpmAction->setVisible(!useFixedTempo);
m_pReanalyzeVarBpmAction->setVisible(useFixedTempo);
}
if (featureIsEnabled(Feature::Reset) ||
featureIsEnabled(Feature::BPM)) {
bool anyBpmLocked;
bool anyBpmNotLocked;
std::tie(anyBpmLocked, anyBpmNotLocked) = getTrackBpmLockStates();
if (featureIsEnabled(Feature::Reset)) {
m_pClearBeatsAction->setEnabled(!anyBpmLocked);
}
if (featureIsEnabled(Feature::BPM)) {
m_pBpmUnlockAction->setEnabled(anyBpmLocked);
m_pBpmLockAction->setEnabled(anyBpmNotLocked);
m_pBpmDoubleAction->setEnabled(!anyBpmLocked);
m_pBpmHalveAction->setEnabled(!anyBpmLocked);
m_pBpmTwoThirdsAction->setEnabled(!anyBpmLocked);
m_pBpmThreeFourthsAction->setEnabled(!anyBpmLocked);
m_pBpmFourThirdsAction->setEnabled(!anyBpmLocked);
m_pBpmThreeHalvesAction->setEnabled(!anyBpmLocked);
m_pBpmResetAction->setEnabled(!anyBpmLocked);
// Append scaled BPM preview for single selection
if (singleTrackSelected) {
TrackPointer pTrack;
if (m_pTrackModel) {
pTrack = getFirstTrackPointer();
} else if (m_pTrack) {
pTrack = m_pTrack;
}
const double bpm = pTrack->getBpm();
appendBpmPreviewtoBpmAction(m_pBpmDoubleAction, bpm);
appendBpmPreviewtoBpmAction(m_pBpmHalveAction, bpm);
appendBpmPreviewtoBpmAction(m_pBpmTwoThirdsAction, bpm);
appendBpmPreviewtoBpmAction(m_pBpmThreeFourthsAction, bpm);
appendBpmPreviewtoBpmAction(m_pBpmFourThirdsAction, bpm);
appendBpmPreviewtoBpmAction(m_pBpmThreeHalvesAction, bpm);
}
}
}
// This action is created only for menus instantiated by deck widgets (e.g.
// WTrackProperty) and if UpdateReplayGainFromPregain is supported.
// Disable it if no deck group was set.
if (m_pUpdateReplayGainAct) {
m_pUpdateReplayGainAct->setEnabled(!m_deckGroup.isEmpty());
}
if (featureIsEnabled(Feature::Color)) {
m_pColorPickerAction->setColorPalette(
ColorPaletteSettings(m_pConfig).getTrackColorPalette());
// Resize Menu to fit changed palette
QResizeEvent resizeEvent(QSize(), m_pColorMenu->size());