-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathcuecontrol.cpp
2597 lines (2268 loc) · 89 KB
/
cuecontrol.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 "engine/controls/cuecontrol.h"
#include <QMutexLocker>
#include "control/controlindicator.h"
#include "control/controlobject.h"
#include "control/controlpushbutton.h"
#include "engine/enginebuffer.h"
#include "moc_cuecontrol.cpp"
#include "preferences/colorpalettesettings.h"
#include "track/track.h"
#include "util/color/color.h"
#include "util/color/predefinedcolorpalettes.h"
#include "util/sample.h"
#include "vinylcontrol/defs_vinylcontrol.h"
namespace {
// TODO: Convert these doubles to a standard enum
// and convert elseif logic to switch statements
constexpr double CUE_MODE_MIXXX = 0.0;
constexpr double CUE_MODE_PIONEER = 1.0;
constexpr double CUE_MODE_DENON = 2.0;
constexpr double CUE_MODE_NUMARK = 3.0;
constexpr double CUE_MODE_MIXXX_NO_BLINK = 4.0;
constexpr double CUE_MODE_CUP = 5.0;
/// This is the position of a fresh loaded tack without any seek
constexpr double kDefaultLoadPosition = 0.0;
constexpr int kNoHotCueNumber = 0;
/// Used for a common tracking of the previewing Hotcue in m_currentlyPreviewingIndex
constexpr int kMainCueIndex = NUM_HOT_CUES;
// Helper function to convert control values (i.e. doubles) into RgbColor
// instances (or nullopt if value < 0). This happens by using the integer
// component as RGB color codes (e.g. 0xFF0000).
inline mixxx::RgbColor::optional_t doubleToRgbColor(double value) {
if (value < 0) {
return std::nullopt;
}
auto colorCode = static_cast<mixxx::RgbColor::code_t>(value);
if (value != mixxx::RgbColor::validateCode(colorCode)) {
return std::nullopt;
}
return mixxx::RgbColor::optional(colorCode);
}
/// Convert hot cue index to 1-based number
///
/// Works independent of if the hot cue index is either 0-based
/// or 1..n-based.
inline int hotcueIndexToHotcueNumber(int hotcueIndex) {
if (hotcueIndex >= mixxx::kFirstHotCueIndex) {
DEBUG_ASSERT(hotcueIndex != Cue::kNoHotCue);
return (hotcueIndex - mixxx::kFirstHotCueIndex) + 1; // to 1-based numbering
} else {
DEBUG_ASSERT(hotcueIndex == Cue::kNoHotCue);
return kNoHotCueNumber;
}
}
/// Convert 1-based hot cue number to hot cue index.
///
/// Works independent of if the hot cue index is either 0-based
/// or 1..n-based.
inline int hotcueNumberToHotcueIndex(int hotcueNumber) {
if (hotcueNumber >= 1) {
DEBUG_ASSERT(hotcueNumber != kNoHotCueNumber);
return mixxx::kFirstHotCueIndex + (hotcueNumber - 1); // from 1-based numbering
} else {
DEBUG_ASSERT(hotcueNumber == kNoHotCueNumber);
return Cue::kNoHotCue;
}
}
} // namespace
CueControl::CueControl(const QString& group,
UserSettingsPointer pConfig)
: EngineControl(group, pConfig),
m_pConfig(pConfig),
m_colorPaletteSettings(ColorPaletteSettings(pConfig)),
m_currentlyPreviewingIndex(Cue::kNoHotCue),
m_pPlay(ControlObject::getControl(ConfigKey(group, "play"))),
m_pStopButton(ControlObject::getControl(ConfigKey(group, "stop"))),
m_bypassCueSetByPlay(false),
m_iNumHotCues(NUM_HOT_CUES),
m_pCurrentSavedLoopControl(nullptr)
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
,
m_trackMutex(QMutex::Recursive)
#endif
{
// To silence a compiler warning about CUE_MODE_PIONEER.
Q_UNUSED(CUE_MODE_PIONEER);
createControls();
m_pTrackSamples = ControlObject::getControl(ConfigKey(group, "track_samples"));
m_pQuantizeEnabled = ControlObject::getControl(ConfigKey(group, "quantize"));
connect(m_pQuantizeEnabled, &ControlObject::valueChanged,
this, &CueControl::quantizeChanged,
Qt::DirectConnection);
m_pClosestBeat = ControlObject::getControl(ConfigKey(group, "beat_closest"));
m_pLoopStartPosition = make_parented<ControlProxy>(group, "loop_start_position", this);
m_pLoopEndPosition = make_parented<ControlProxy>(group, "loop_end_position", this);
m_pLoopEnabled = make_parented<ControlProxy>(group, "loop_enabled", this);
m_pBeatLoopActivate = make_parented<ControlProxy>(group, "beatloop_activate", this);
m_pBeatLoopSize = make_parented<ControlProxy>(group, "beatloop_size", this);
m_pCuePoint = new ControlObject(ConfigKey(group, "cue_point"));
m_pCuePoint->set(Cue::kNoPosition);
m_pCueMode = new ControlObject(ConfigKey(group, "cue_mode"));
m_pCueSet = new ControlPushButton(ConfigKey(group, "cue_set"));
m_pCueSet->setButtonMode(ControlPushButton::TRIGGER);
connect(m_pCueSet, &ControlObject::valueChanged,
this, &CueControl::cueSet,
Qt::DirectConnection);
m_pCueClear = new ControlPushButton(ConfigKey(group, "cue_clear"));
m_pCueClear->setButtonMode(ControlPushButton::TRIGGER);
connect(m_pCueClear, &ControlObject::valueChanged,
this, &CueControl::cueClear,
Qt::DirectConnection);
m_pCueGoto = new ControlPushButton(ConfigKey(group, "cue_goto"));
connect(m_pCueGoto, &ControlObject::valueChanged,
this, &CueControl::cueGoto,
Qt::DirectConnection);
m_pCueGotoAndPlay =
new ControlPushButton(ConfigKey(group, "cue_gotoandplay"));
connect(m_pCueGotoAndPlay, &ControlObject::valueChanged,
this, &CueControl::cueGotoAndPlay,
Qt::DirectConnection);
m_pCuePlay =
new ControlPushButton(ConfigKey(group, "cue_play"));
connect(m_pCuePlay, &ControlObject::valueChanged,
this, &CueControl::cuePlay,
Qt::DirectConnection);
m_pCueGotoAndStop =
new ControlPushButton(ConfigKey(group, "cue_gotoandstop"));
connect(m_pCueGotoAndStop, &ControlObject::valueChanged,
this, &CueControl::cueGotoAndStop,
Qt::DirectConnection);
m_pCuePreview = new ControlPushButton(ConfigKey(group, "cue_preview"));
connect(m_pCuePreview, &ControlObject::valueChanged,
this, &CueControl::cuePreview,
Qt::DirectConnection);
m_pCueCDJ = new ControlPushButton(ConfigKey(group, "cue_cdj"));
connect(m_pCueCDJ, &ControlObject::valueChanged,
this, &CueControl::cueCDJ,
Qt::DirectConnection);
m_pCueDefault = new ControlPushButton(ConfigKey(group, "cue_default"));
connect(m_pCueDefault, &ControlObject::valueChanged,
this, &CueControl::cueDefault,
Qt::DirectConnection);
m_pPlayStutter = new ControlPushButton(ConfigKey(group, "play_stutter"));
connect(m_pPlayStutter, &ControlObject::valueChanged,
this, &CueControl::playStutter,
Qt::DirectConnection);
m_pCueIndicator = new ControlIndicator(ConfigKey(group, "cue_indicator"));
m_pPlayIndicator = new ControlIndicator(ConfigKey(group, "play_indicator"));
m_pPlayLatched = new ControlObject(ConfigKey(group, "play_latched"));
m_pPlayLatched->setReadOnly();
m_pIntroStartPosition = new ControlObject(ConfigKey(group, "intro_start_position"));
m_pIntroStartPosition->set(Cue::kNoPosition);
m_pIntroStartEnabled = new ControlObject(ConfigKey(group, "intro_start_enabled"));
m_pIntroStartEnabled->setReadOnly();
m_pIntroStartSet = new ControlPushButton(ConfigKey(group, "intro_start_set"));
connect(m_pIntroStartSet, &ControlObject::valueChanged,
this, &CueControl::introStartSet,
Qt::DirectConnection);
m_pIntroStartClear = new ControlPushButton(ConfigKey(group, "intro_start_clear"));
connect(m_pIntroStartClear, &ControlObject::valueChanged,
this, &CueControl::introStartClear,
Qt::DirectConnection);
m_pIntroStartActivate = new ControlPushButton(ConfigKey(group, "intro_start_activate"));
connect(m_pIntroStartActivate, &ControlObject::valueChanged,
this, &CueControl::introStartActivate,
Qt::DirectConnection);
m_pIntroEndPosition = new ControlObject(ConfigKey(group, "intro_end_position"));
m_pIntroEndPosition->set(Cue::kNoPosition);
m_pIntroEndEnabled = new ControlObject(ConfigKey(group, "intro_end_enabled"));
m_pIntroEndEnabled->setReadOnly();
m_pIntroEndSet = new ControlPushButton(ConfigKey(group, "intro_end_set"));
connect(m_pIntroEndSet, &ControlObject::valueChanged,
this, &CueControl::introEndSet,
Qt::DirectConnection);
m_pIntroEndClear = new ControlPushButton(ConfigKey(group, "intro_end_clear"));
connect(m_pIntroEndClear, &ControlObject::valueChanged,
this, &CueControl::introEndClear,
Qt::DirectConnection);
m_pIntroEndActivate = new ControlPushButton(ConfigKey(group, "intro_end_activate"));
connect(m_pIntroEndActivate, &ControlObject::valueChanged,
this, &CueControl::introEndActivate,
Qt::DirectConnection);
m_pOutroStartPosition = new ControlObject(ConfigKey(group, "outro_start_position"));
m_pOutroStartPosition->set(Cue::kNoPosition);
m_pOutroStartEnabled = new ControlObject(ConfigKey(group, "outro_start_enabled"));
m_pOutroStartEnabled->setReadOnly();
m_pOutroStartSet = new ControlPushButton(ConfigKey(group, "outro_start_set"));
connect(m_pOutroStartSet, &ControlObject::valueChanged,
this, &CueControl::outroStartSet,
Qt::DirectConnection);
m_pOutroStartClear = new ControlPushButton(ConfigKey(group, "outro_start_clear"));
connect(m_pOutroStartClear, &ControlObject::valueChanged,
this, &CueControl::outroStartClear,
Qt::DirectConnection);
m_pOutroStartActivate = new ControlPushButton(ConfigKey(group, "outro_start_activate"));
connect(m_pOutroStartActivate, &ControlObject::valueChanged,
this, &CueControl::outroStartActivate,
Qt::DirectConnection);
m_pOutroEndPosition = new ControlObject(ConfigKey(group, "outro_end_position"));
m_pOutroEndPosition->set(Cue::kNoPosition);
m_pOutroEndEnabled = new ControlObject(ConfigKey(group, "outro_end_enabled"));
m_pOutroEndEnabled->setReadOnly();
m_pOutroEndSet = new ControlPushButton(ConfigKey(group, "outro_end_set"));
connect(m_pOutroEndSet, &ControlObject::valueChanged,
this, &CueControl::outroEndSet,
Qt::DirectConnection);
m_pOutroEndClear = new ControlPushButton(ConfigKey(group, "outro_end_clear"));
connect(m_pOutroEndClear, &ControlObject::valueChanged,
this, &CueControl::outroEndClear,
Qt::DirectConnection);
m_pOutroEndActivate = new ControlPushButton(ConfigKey(group, "outro_end_activate"));
connect(m_pOutroEndActivate, &ControlObject::valueChanged,
this, &CueControl::outroEndActivate,
Qt::DirectConnection);
m_pVinylControlEnabled = new ControlProxy(group, "vinylcontrol_enabled");
m_pVinylControlMode = new ControlProxy(group, "vinylcontrol_mode");
m_pHotcueFocus = new ControlObject(ConfigKey(group, "hotcue_focus"));
setHotcueFocusIndex(Cue::kNoHotCue);
m_pHotcueFocusColorPrev = new ControlObject(ConfigKey(group, "hotcue_focus_color_prev"));
connect(m_pHotcueFocusColorPrev,
&ControlObject::valueChanged,
this,
&CueControl::hotcueFocusColorPrev,
Qt::DirectConnection);
m_pHotcueFocusColorNext = new ControlObject(ConfigKey(group, "hotcue_focus_color_next"));
connect(m_pHotcueFocusColorNext,
&ControlObject::valueChanged,
this,
&CueControl::hotcueFocusColorNext,
Qt::DirectConnection);
}
CueControl::~CueControl() {
delete m_pCuePoint;
delete m_pCueMode;
delete m_pCueSet;
delete m_pCueClear;
delete m_pCueGoto;
delete m_pCueGotoAndPlay;
delete m_pCuePlay;
delete m_pCueGotoAndStop;
delete m_pCuePreview;
delete m_pCueCDJ;
delete m_pCueDefault;
delete m_pPlayStutter;
delete m_pCueIndicator;
delete m_pPlayIndicator;
delete m_pPlayLatched;
delete m_pIntroStartPosition;
delete m_pIntroStartEnabled;
delete m_pIntroStartSet;
delete m_pIntroStartClear;
delete m_pIntroStartActivate;
delete m_pIntroEndPosition;
delete m_pIntroEndEnabled;
delete m_pIntroEndSet;
delete m_pIntroEndClear;
delete m_pIntroEndActivate;
delete m_pOutroStartPosition;
delete m_pOutroStartEnabled;
delete m_pOutroStartSet;
delete m_pOutroStartClear;
delete m_pOutroStartActivate;
delete m_pOutroEndPosition;
delete m_pOutroEndEnabled;
delete m_pOutroEndSet;
delete m_pOutroEndClear;
delete m_pOutroEndActivate;
delete m_pVinylControlEnabled;
delete m_pVinylControlMode;
delete m_pHotcueFocus;
delete m_pHotcueFocusColorPrev;
delete m_pHotcueFocusColorNext;
qDeleteAll(m_hotcueControls);
}
void CueControl::createControls() {
for (int i = 0; i < m_iNumHotCues; ++i) {
HotcueControl* pControl = new HotcueControl(getGroup(), i);
connect(pControl, &HotcueControl::hotcuePositionChanged,
this, &CueControl::hotcuePositionChanged,
Qt::DirectConnection);
connect(pControl,
&HotcueControl::hotcueEndPositionChanged,
this,
&CueControl::hotcueEndPositionChanged,
Qt::DirectConnection);
connect(pControl,
&HotcueControl::hotcueSet,
this,
&CueControl::hotcueSet,
Qt::DirectConnection);
connect(pControl,
&HotcueControl::hotcueGoto,
this,
&CueControl::hotcueGoto,
Qt::DirectConnection);
connect(pControl,
&HotcueControl::hotcueGotoAndPlay,
this,
&CueControl::hotcueGotoAndPlay,
Qt::DirectConnection);
connect(pControl,
&HotcueControl::hotcueGotoAndStop,
this,
&CueControl::hotcueGotoAndStop,
Qt::DirectConnection);
connect(pControl,
&HotcueControl::hotcueGotoAndLoop,
this,
&CueControl::hotcueGotoAndLoop,
Qt::DirectConnection);
connect(pControl,
&HotcueControl::hotcueCueLoop,
this,
&CueControl::hotcueCueLoop,
Qt::DirectConnection);
connect(pControl,
&HotcueControl::hotcueActivate,
this,
&CueControl::hotcueActivate,
Qt::DirectConnection);
connect(pControl,
&HotcueControl::hotcueActivatePreview,
this,
&CueControl::hotcueActivatePreview,
Qt::DirectConnection);
connect(pControl,
&HotcueControl::hotcueClear,
this,
&CueControl::hotcueClear,
Qt::DirectConnection);
m_hotcueControls.append(pControl);
}
}
void CueControl::attachCue(const CuePointer& pCue, HotcueControl* pControl) {
VERIFY_OR_DEBUG_ASSERT(pControl) {
return;
}
detachCue(pControl);
connect(pCue.get(),
&Cue::updated,
this,
&CueControl::cueUpdated,
Qt::DirectConnection);
pControl->setCue(pCue);
}
void CueControl::detachCue(HotcueControl* pControl) {
VERIFY_OR_DEBUG_ASSERT(pControl) {
return;
}
CuePointer pCue = pControl->getCue();
if (!pCue) {
return;
}
disconnect(pCue.get(), nullptr, this, nullptr);
m_pCurrentSavedLoopControl.testAndSetRelease(pControl, nullptr);
pControl->resetCue();
}
// This is called from the EngineWokerThread and ends with the initial seek
// via seekOnLoad(). There is the theoretical and pending issue of a delayed control
// command intended for the old track that might be performed instead.
void CueControl::trackLoaded(TrackPointer pNewTrack) {
QMutexLocker lock(&m_trackMutex);
if (m_pLoadedTrack) {
disconnect(m_pLoadedTrack.get(), nullptr, this, nullptr);
updateCurrentlyPreviewingIndex(Cue::kNoHotCue);
for (const auto& pControl : qAsConst(m_hotcueControls)) {
detachCue(pControl);
}
m_pCueIndicator->setBlinkValue(ControlIndicator::OFF);
m_pCuePoint->set(Cue::kNoPosition);
m_pIntroStartPosition->set(Cue::kNoPosition);
m_pIntroStartEnabled->forceSet(0.0);
m_pIntroEndPosition->set(Cue::kNoPosition);
m_pIntroEndEnabled->forceSet(0.0);
m_pOutroStartPosition->set(Cue::kNoPosition);
m_pOutroStartEnabled->forceSet(0.0);
m_pOutroEndPosition->set(Cue::kNoPosition);
m_pOutroEndEnabled->forceSet(0.0);
setHotcueFocusIndex(Cue::kNoHotCue);
m_pLoadedTrack.reset();
m_usedSeekOnLoadPosition.setValue(kDefaultLoadPosition);
}
if (!pNewTrack) {
return;
}
m_pLoadedTrack = pNewTrack;
connect(m_pLoadedTrack.get(),
&Track::analyzed,
this,
&CueControl::trackAnalyzed,
Qt::DirectConnection);
connect(m_pLoadedTrack.get(),
&Track::cuesUpdated,
this,
&CueControl::trackCuesUpdated,
Qt::DirectConnection);
lock.unlock();
// Use pNewTrack from now, because m_pLoadedTrack might have been reset
// immediately after leaving the locking scope!
// Update COs with cues from track.
loadCuesFromTrack();
// Seek track according to SeekOnLoadMode.
SeekOnLoadMode seekOnLoadMode = getSeekOnLoadPreference();
switch (seekOnLoadMode) {
case SeekOnLoadMode::Beginning:
// This allows users to load tracks and have the needle-drop be maintained.
if (!(m_pVinylControlEnabled->toBool() &&
m_pVinylControlMode->get() == MIXXX_VCMODE_ABSOLUTE)) {
seekOnLoad(mixxx::audio::kStartFramePos);
}
break;
case SeekOnLoadMode::FirstSound: {
CuePointer pAudibleSound =
pNewTrack->findCueByType(mixxx::CueType::AudibleSound);
mixxx::audio::FramePos audibleSoundPosition = mixxx::audio::kInvalidFramePos;
if (pAudibleSound) {
audibleSoundPosition = pAudibleSound->getPosition();
}
if (audibleSoundPosition.isValid()) {
seekOnLoad(audibleSoundPosition);
} else {
seekOnLoad(mixxx::audio::kStartFramePos);
}
break;
}
case SeekOnLoadMode::MainCue: {
// Take main cue position from CO instead of cue point list because
// value in CO will be quantized if quantization is enabled
// while value in cue point list will never be quantized.
// This prevents jumps when track analysis finishes while quantization is enabled.
const auto mainCuePosition =
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pCuePoint->get());
if (mainCuePosition.isValid()) {
seekOnLoad(mainCuePosition);
} else {
seekOnLoad(mixxx::audio::kStartFramePos);
}
break;
}
case SeekOnLoadMode::IntroStart: {
const auto introStartPosition =
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pIntroStartPosition->get());
if (introStartPosition.isValid()) {
seekOnLoad(introStartPosition);
} else {
seekOnLoad(mixxx::audio::kStartFramePos);
}
break;
}
default:
DEBUG_ASSERT(!"Unknown enum value");
seekOnLoad(mixxx::audio::kStartFramePos);
break;
}
}
void CueControl::seekOnLoad(mixxx::audio::FramePos seekOnLoadPosition) {
DEBUG_ASSERT(seekOnLoadPosition.isValid());
seekExact(seekOnLoadPosition.toEngineSamplePos());
m_usedSeekOnLoadPosition.setValue(seekOnLoadPosition.toEngineSamplePos());
}
void CueControl::cueUpdated() {
//QMutexLocker lock(&m_mutex);
// We should get a trackCuesUpdated call anyway, so do nothing.
}
void CueControl::loadCuesFromTrack() {
QMutexLocker lock(&m_trackMutex);
if (!m_pLoadedTrack) {
return;
}
QSet<int> active_hotcues;
CuePointer pMainCue;
CuePointer pIntroCue;
CuePointer pOutroCue;
const QList<CuePointer> cues = m_pLoadedTrack->getCuePoints();
for (const auto& pCue : cues) {
switch (pCue->getType()) {
case mixxx::CueType::MainCue:
DEBUG_ASSERT(!pMainCue); // There should be only one MainCue cue
pMainCue = pCue;
break;
case mixxx::CueType::Intro:
DEBUG_ASSERT(!pIntroCue); // There should be only one Intro cue
pIntroCue = pCue;
break;
case mixxx::CueType::Outro:
DEBUG_ASSERT(!pOutroCue); // There should be only one Outro cue
pOutroCue = pCue;
break;
case mixxx::CueType::HotCue:
case mixxx::CueType::Loop: {
if (pCue->getHotCue() == Cue::kNoHotCue) {
continue;
}
int hotcue = pCue->getHotCue();
HotcueControl* pControl = m_hotcueControls.value(hotcue, NULL);
// Cue's hotcue doesn't have a hotcue control.
if (pControl == nullptr) {
continue;
}
CuePointer pOldCue(pControl->getCue());
// If the old hotcue is different than this one.
if (pOldCue != pCue) {
// old cue is detached if required
attachCue(pCue, pControl);
} else {
// If the old hotcue is the same, then we only need to update
Cue::StartAndEndPositions pos = pCue->getStartAndEndPosition();
pControl->setPosition(pos.startPosition);
pControl->setEndPosition(pos.endPosition);
pControl->setColor(pCue->getColor());
pControl->setType(pCue->getType());
}
// Add the hotcue to the list of active hotcues
active_hotcues.insert(hotcue);
break;
}
default:
break;
}
}
// Detach all hotcues that are no longer present
for (int hotCueIndex = 0; hotCueIndex < m_iNumHotCues; ++hotCueIndex) {
if (!active_hotcues.contains(hotCueIndex)) {
HotcueControl* pControl = m_hotcueControls.at(hotCueIndex);
detachCue(pControl);
}
}
if (pIntroCue) {
const auto startPosition = quantizeCuePoint(pIntroCue->getPosition());
const auto endPosition = quantizeCuePoint(pIntroCue->getEndPosition());
m_pIntroStartPosition->set(startPosition.toEngineSamplePosMaybeInvalid());
m_pIntroStartEnabled->forceSet(startPosition.isValid());
m_pIntroEndPosition->set(endPosition.toEngineSamplePosMaybeInvalid());
m_pIntroEndEnabled->forceSet(endPosition.isValid());
} else {
m_pIntroStartPosition->set(Cue::kNoPosition);
m_pIntroStartEnabled->forceSet(0.0);
m_pIntroEndPosition->set(Cue::kNoPosition);
m_pIntroEndEnabled->forceSet(0.0);
}
if (pOutroCue) {
const auto startPosition = quantizeCuePoint(pOutroCue->getPosition());
const auto endPosition = quantizeCuePoint(pOutroCue->getEndPosition());
m_pOutroStartPosition->set(startPosition.toEngineSamplePosMaybeInvalid());
m_pOutroStartEnabled->forceSet(startPosition.isValid());
m_pOutroEndPosition->set(endPosition.toEngineSamplePosMaybeInvalid());
m_pOutroEndEnabled->forceSet(endPosition.isValid());
} else {
m_pOutroStartPosition->set(Cue::kNoPosition);
m_pOutroStartEnabled->forceSet(0.0);
m_pOutroEndPosition->set(Cue::kNoPosition);
m_pOutroEndEnabled->forceSet(0.0);
}
// Because of legacy, we store the main cue point twice and need to
// sync both values.
// The mixxx::CueType::MainCue from getCuePoints() has the priority
mixxx::audio::FramePos mainCuePosition;
if (pMainCue) {
mainCuePosition = pMainCue->getPosition();
// adjust the track cue accordingly
m_pLoadedTrack->setMainCuePosition(mainCuePosition);
} else {
// If no load cue point is stored, read from track
// Note: This is mixxx::audio::kStartFramePos for new tracks
// and always a valid position.
mainCuePosition = m_pLoadedTrack->getMainCuePosition();
DEBUG_ASSERT(mainCuePosition.isValid());
// A main cue point only needs to be added if the position
// differs from the default position.
if (mainCuePosition != mixxx::audio::kStartFramePos) {
qInfo()
<< "Adding missing main cue point at"
<< mainCuePosition
<< "for track"
<< m_pLoadedTrack->getLocation();
m_pLoadedTrack->createAndAddCue(
mixxx::CueType::MainCue,
Cue::kNoHotCue,
mainCuePosition,
mixxx::audio::kInvalidFramePos);
}
}
DEBUG_ASSERT(mainCuePosition.isValid());
const auto quantizedMainCuePosition = quantizeCuePoint(mainCuePosition);
m_pCuePoint->set(quantizedMainCuePosition.toEngineSamplePosMaybeInvalid());
}
void CueControl::trackAnalyzed() {
SampleOfTrack sampleOfTrack = getSampleOfTrack();
if (sampleOfTrack.current != m_usedSeekOnLoadPosition.getValue()) {
// the track is already manual cued, don't re-cue
return;
}
// Make track follow the updated cues.
SeekOnLoadMode seekOnLoadMode = getSeekOnLoadPreference();
switch (seekOnLoadMode) {
case SeekOnLoadMode::MainCue: {
const auto position =
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pCuePoint->get());
if (position.isValid()) {
seekOnLoad(position);
}
break;
}
case SeekOnLoadMode::IntroStart: {
const auto position =
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pIntroStartPosition->get());
if (position.isValid()) {
seekOnLoad(position);
}
break;
}
default:
// nothing to do here
break;
}
}
void CueControl::trackCuesUpdated() {
loadCuesFromTrack();
}
void CueControl::trackBeatsUpdated(mixxx::BeatsPointer pBeats) {
Q_UNUSED(pBeats);
loadCuesFromTrack();
}
void CueControl::quantizeChanged(double v) {
Q_UNUSED(v);
// check if we were at the cue point before
bool wasTrackAtCue = getTrackAt() == TrackAt::Cue;
bool wasTrackAtIntro = isTrackAtIntroCue();
loadCuesFromTrack();
// if we are playing (no matter what reason for) do not seek
if (m_pPlay->toBool()) {
return;
}
// Retrieve new cue pos and follow
const auto cuePosition =
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pCuePoint->get());
if (wasTrackAtCue && cuePosition.isValid()) {
seekExact(cuePosition.toEngineSamplePos());
}
// Retrieve new intro start pos and follow
const auto introPosition =
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pIntroStartPosition->get());
if (wasTrackAtIntro && introPosition.isValid()) {
seekExact(introPosition.toEngineSamplePos());
}
}
void CueControl::hotcueSet(HotcueControl* pControl, double value, HotcueSetMode mode) {
//qDebug() << "CueControl::hotcueSet" << value;
if (value <= 0) {
return;
}
QMutexLocker lock(&m_trackMutex);
if (!m_pLoadedTrack) {
return;
}
// Note: the cue is just detached from the hotcue control
// It remains in the database for later use
// TODO: find a rule, that allows us to delete the cue as well
// https://bugs.launchpad.net/mixxx/+bug/1653276
hotcueClear(pControl, value);
mixxx::audio::FramePos cueStartPosition;
mixxx::audio::FramePos cueEndPosition;
mixxx::CueType cueType = mixxx::CueType::Invalid;
bool loopEnabled = m_pLoopEnabled->toBool();
if (mode == HotcueSetMode::Auto) {
mode = loopEnabled ? HotcueSetMode::Loop : HotcueSetMode::Cue;
}
switch (mode) {
case HotcueSetMode::Cue: {
// If no loop is enabled, just store regular jump cue
cueStartPosition = getQuantizedCurrentPosition();
cueType = mixxx::CueType::HotCue;
break;
}
case HotcueSetMode::Loop: {
if (loopEnabled) {
// If a loop is enabled, save the current loop
cueStartPosition =
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pLoopStartPosition->get());
cueEndPosition =
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pLoopEndPosition->get());
} else {
// If no loop is enabled, save a loop starting from the current
// position and with the current beatloop size
cueStartPosition = getQuantizedCurrentPosition();
double beatloopSize = m_pBeatLoopSize->get();
const mixxx::BeatsPointer pBeats = m_pLoadedTrack->getBeats();
if (beatloopSize <= 0 || !pBeats) {
return;
}
if (cueStartPosition.isValid()) {
cueEndPosition = pBeats->findNBeatsFromPosition(cueStartPosition, beatloopSize);
}
}
cueType = mixxx::CueType::Loop;
break;
}
default:
DEBUG_ASSERT(!"Invalid HotcueSetMode");
return;
}
VERIFY_OR_DEBUG_ASSERT(cueType != mixxx::CueType::Invalid) {
return;
}
// Abort if no position has been found.
VERIFY_OR_DEBUG_ASSERT(cueStartPosition.isValid() &&
(cueType != mixxx::CueType::Loop || cueEndPosition.isValid())) {
return;
}
int hotcueIndex = pControl->getHotcueIndex();
CuePointer pCue = m_pLoadedTrack->createAndAddCue(
cueType,
hotcueIndex,
cueStartPosition,
cueEndPosition);
// TODO(XXX) deal with spurious signals
attachCue(pCue, pControl);
if (cueType == mixxx::CueType::Loop) {
ConfigKey autoLoopColorsKey("[Controls]", "auto_loop_colors");
if (getConfig()->getValue(autoLoopColorsKey, false)) {
auto hotcueColorPalette =
m_colorPaletteSettings.getHotcueColorPalette();
pCue->setColor(hotcueColorPalette.colorForHotcueIndex(hotcueIndex));
} else {
pCue->setColor(mixxx::PredefinedColorPalettes::kDefaultLoopColor);
}
} else {
ConfigKey autoHotcueColorsKey("[Controls]", "auto_hotcue_colors");
if (getConfig()->getValue(autoHotcueColorsKey, false)) {
auto hotcueColorPalette =
m_colorPaletteSettings.getHotcueColorPalette();
pCue->setColor(hotcueColorPalette.colorForHotcueIndex(hotcueIndex));
} else {
pCue->setColor(mixxx::PredefinedColorPalettes::kDefaultCueColor);
}
}
if (cueType == mixxx::CueType::Loop) {
setCurrentSavedLoopControlAndActivate(pControl);
}
// If quantize is enabled and we are not playing, jump to the cue point
// since it's not necessarily where we currently are. TODO(XXX) is this
// potentially invalid for vinyl control?
bool playing = m_pPlay->toBool();
if (!playing && m_pQuantizeEnabled->toBool()) {
lock.unlock(); // prevent deadlock.
// Enginebuffer will quantize more exactly than we can.
seekAbs(cueStartPosition.toEngineSamplePos());
}
}
void CueControl::hotcueGoto(HotcueControl* pControl, double value) {
if (value <= 0) {
return;
}
const mixxx::audio::FramePos position = pControl->getPosition();
if (position.isValid()) {
seekAbs(position.toEngineSamplePos());
}
}
void CueControl::hotcueGotoAndStop(HotcueControl* pControl, double value) {
if (value <= 0) {
return;
}
const mixxx::audio::FramePos position = pControl->getPosition();
if (!position.isValid()) {
return;
}
if (m_currentlyPreviewingIndex == Cue::kNoHotCue) {
m_pPlay->set(0.0);
seekExact(position.toEngineSamplePos());
} else {
// this becomes a play latch command if we are previewing
m_pPlay->set(0.0);
}
}
void CueControl::hotcueGotoAndPlay(HotcueControl* pControl, double value) {
if (value <= 0) {
return;
}
const mixxx::audio::FramePos position = pControl->getPosition();
if (position.isValid()) {
seekAbs(position.toEngineSamplePos());
// End previewing to not jump back if a sticking finger on a cue
// button is released (just in case)
updateCurrentlyPreviewingIndex(Cue::kNoHotCue);
if (!m_pPlay->toBool()) {
// don't move the cue point to the hot cue point in DENON mode
m_bypassCueSetByPlay = true;
m_pPlay->set(1.0);
}
}
setHotcueFocusIndex(pControl->getHotcueIndex());
}
void CueControl::hotcueGotoAndLoop(HotcueControl* pControl, double value) {
if (value == 0) {
return;
}
CuePointer pCue = pControl->getCue();
if (!pCue) {
return;
}
const mixxx::audio::FramePos startPosition = pCue->getPosition();
if (!startPosition.isValid()) {
return;
}
if (pCue->getType() == mixxx::CueType::Loop) {
seekAbs(startPosition.toEngineSamplePos());
setCurrentSavedLoopControlAndActivate(pControl);
} else if (pCue->getType() == mixxx::CueType::HotCue) {
seekAbs(startPosition.toEngineSamplePos());
setBeatLoop(startPosition.toEngineSamplePos(), true);
} else {
return;
}
// End previewing to not jump back if a sticking finger on a cue
// button is released (just in case)
updateCurrentlyPreviewingIndex(Cue::kNoHotCue);
if (!m_pPlay->toBool()) {
// don't move the cue point to the hot cue point in DENON mode
m_bypassCueSetByPlay = true;
m_pPlay->set(1.0);
}
setHotcueFocusIndex(pControl->getHotcueIndex());
}
void CueControl::hotcueCueLoop(HotcueControl* pControl, double value) {
if (value == 0) {
return;
}
CuePointer pCue = pControl->getCue();
if (!pCue || !pCue->getPosition().isValid()) {
hotcueSet(pControl, value, HotcueSetMode::Cue);
pCue = pControl->getCue();
VERIFY_OR_DEBUG_ASSERT(pCue && pCue->getPosition().isValid()) {
return;
}
}
switch (pCue->getType()) {
case mixxx::CueType::Loop: {
// The hotcue_X_cueloop CO was invoked for a saved loop, set it as
// active the first time this happens and toggle the loop_enabled state
// on subsequent invocations.
if (m_pCurrentSavedLoopControl != pControl) {
setCurrentSavedLoopControlAndActivate(pControl);
} else {
bool loopActive = pControl->getStatus() == HotcueControl::Status::Active;
Cue::StartAndEndPositions pos = pCue->getStartAndEndPosition();
setLoop(pos.startPosition.toEngineSamplePosMaybeInvalid(),
pos.endPosition.toEngineSamplePosMaybeInvalid(),
!loopActive);
}
} break;
case mixxx::CueType::HotCue: {
// The hotcue_X_cueloop CO was invoked for a hotcue. In that case,
// create a beatloop starting at the hotcue position. This is useful for
// mapping the CUE LOOP mode labeled on some controllers.
setCurrentSavedLoopControlAndActivate(nullptr);
const mixxx::audio::FramePos startPosition = pCue->getPosition();
const bool loopActive = m_pLoopEnabled->toBool() &&
startPosition ==
mixxx::audio::FramePos::fromEngineSamplePosMaybeInvalid(
m_pLoopStartPosition->get());
setBeatLoop(startPosition.toEngineSamplePosMaybeInvalid(), !loopActive);
break;
}
default:
return;
}