forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcuecontrol.cpp
1048 lines (897 loc) · 33.4 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
// cuecontrol.cpp
// Created 11/5/2009 by RJ Ryan ([email protected])
#include <QMutexLocker>
#include "engine/cuecontrol.h"
#include "controlobject.h"
#include "controlpushbutton.h"
#include "controlindicator.h"
#include "trackinfoobject.h"
#include "library/dao/cue.h"
#include "cachingreader.h"
#include "vinylcontrol/defs_vinylcontrol.h"
static const double CUE_MODE_MIXXX = 0.0;
static const double CUE_MODE_PIONEER = 1.0;
static const double CUE_MODE_DENON = 2.0;
static const double CUE_MODE_NUMARK = 3.0;
CueControl::CueControl(QString group,
ConfigObject<ConfigValue>* _config) :
EngineControl(group, _config),
m_bHotcueCancel(false),
m_bPreviewing(false),
m_bPreviewingHotcue(false),
m_pPlayButton(ControlObject::getControl(ConfigKey(group, "play"))),
m_pStopButton(ControlObject::getControl(ConfigKey(group, "stop"))),
m_iCurrentlyPreviewingHotcues(0),
m_iNumHotCues(NUM_HOT_CUES),
m_pLoadedTrack(),
m_mutex(QMutex::Recursive) {
// 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"));
m_pNextBeat = ControlObject::getControl(ConfigKey(group, "beat_next"));
m_pClosestBeat = ControlObject::getControl(ConfigKey(group, "beat_closest"));
m_pCuePoint = new ControlObject(ConfigKey(group, "cue_point"));
m_pCuePoint->set(-1.0);
m_pCueMode = new ControlObject(ConfigKey(group, "cue_mode"));
// 0.0 -> Pioneer mode
// 1.0 -> Denon mode
m_pCueSet = new ControlPushButton(ConfigKey(group, "cue_set"));
m_pCueSet->setButtonMode(ControlPushButton::TRIGGER);
connect(m_pCueSet, SIGNAL(valueChanged(double)),
this, SLOT(cueSet(double)),
Qt::DirectConnection);
m_pCueGoto = new ControlPushButton(ConfigKey(group, "cue_goto"));
connect(m_pCueGoto, SIGNAL(valueChanged(double)),
this, SLOT(cueGoto(double)),
Qt::DirectConnection);
m_pCueGotoAndPlay =
new ControlPushButton(ConfigKey(group, "cue_gotoandplay"));
connect(m_pCueGotoAndPlay, SIGNAL(valueChanged(double)),
this, SLOT(cueGotoAndPlay(double)),
Qt::DirectConnection);
m_pCueGotoAndStop =
new ControlPushButton(ConfigKey(group, "cue_gotoandstop"));
connect(m_pCueGotoAndStop, SIGNAL(valueChanged(double)),
this, SLOT(cueGotoAndStop(double)),
Qt::DirectConnection);
m_pCuePreview = new ControlPushButton(ConfigKey(group, "cue_preview"));
connect(m_pCuePreview, SIGNAL(valueChanged(double)),
this, SLOT(cuePreview(double)),
Qt::DirectConnection);
m_pCueCDJ = new ControlPushButton(ConfigKey(group, "cue_cdj"));
connect(m_pCueCDJ, SIGNAL(valueChanged(double)),
this, SLOT(cueCDJ(double)),
Qt::DirectConnection);
m_pCueDefault = new ControlPushButton(ConfigKey(group, "cue_default"));
connect(m_pCueDefault, SIGNAL(valueChanged(double)),
this, SLOT(cueDefault(double)),
Qt::DirectConnection);
m_pPlayStutter = new ControlPushButton(ConfigKey(group, "play_stutter"));
connect(m_pPlayStutter, SIGNAL(valueChanged(double)),
this, SLOT(playStutter(double)),
Qt::DirectConnection);
m_pCueIndicator = new ControlIndicator(ConfigKey(group, "cue_indicator"));
m_pPlayIndicator = new ControlIndicator(ConfigKey(group, "play_indicator"));
m_pVinylControlEnabled = new ControlObjectSlave(group, "vinylcontrol_enabled");
m_pVinylControlMode = new ControlObjectSlave(group, "vinylcontrol_mode");
}
CueControl::~CueControl() {
delete m_pCuePoint;
delete m_pCueMode;
delete m_pCueSet;
delete m_pCueGoto;
delete m_pCueGotoAndPlay;
delete m_pCueGotoAndStop;
delete m_pCuePreview;
delete m_pCueCDJ;
delete m_pCueDefault;
delete m_pPlayStutter;
delete m_pCueIndicator;
delete m_pPlayIndicator;
delete m_pVinylControlEnabled;
delete m_pVinylControlMode;
qDeleteAll(m_hotcueControl);
}
void CueControl::createControls() {
for (int i = 0; i < m_iNumHotCues; ++i) {
HotcueControl* pControl = new HotcueControl(getGroup(), i);
connect(pControl, SIGNAL(hotcuePositionChanged(HotcueControl*, double)),
this, SLOT(hotcuePositionChanged(HotcueControl*, double)),
Qt::DirectConnection);
connect(pControl, SIGNAL(hotcueSet(HotcueControl*, double)),
this, SLOT(hotcueSet(HotcueControl*, double)),
Qt::DirectConnection);
connect(pControl, SIGNAL(hotcueGoto(HotcueControl*, double)),
this, SLOT(hotcueGoto(HotcueControl*, double)),
Qt::DirectConnection);
connect(pControl, SIGNAL(hotcueGotoAndPlay(HotcueControl*, double)),
this, SLOT(hotcueGotoAndPlay(HotcueControl*, double)),
Qt::DirectConnection);
connect(pControl, SIGNAL(hotcueGotoAndStop(HotcueControl*, double)),
this, SLOT(hotcueGotoAndStop(HotcueControl*, double)),
Qt::DirectConnection);
connect(pControl, SIGNAL(hotcueActivate(HotcueControl*, double)),
this, SLOT(hotcueActivate(HotcueControl*, double)),
Qt::DirectConnection);
connect(pControl, SIGNAL(hotcueActivatePreview(HotcueControl*, double)),
this, SLOT(hotcueActivatePreview(HotcueControl*, double)),
Qt::DirectConnection);
connect(pControl, SIGNAL(hotcueClear(HotcueControl*, double)),
this, SLOT(hotcueClear(HotcueControl*, double)),
Qt::DirectConnection);
m_hotcueControl.append(pControl);
}
}
void CueControl::attachCue(Cue* pCue, int hotCue) {
HotcueControl* pControl = m_hotcueControl.value(hotCue, NULL);
if (pControl == NULL) {
return;
}
if (pControl->getCue() != NULL) {
detachCue(pControl->getHotcueNumber());
}
connect(pCue, SIGNAL(updated()),
this, SLOT(cueUpdated()),
Qt::DirectConnection);
pControl->getPosition()->set(pCue->getPosition());
pControl->getEnabled()->set(pCue->getPosition() == -1 ? 0.0 : 1.0);
// set pCue only if all other data is in place
// because we have a null check for valid data else where in the code
pControl->setCue(pCue);
}
void CueControl::detachCue(int hotCue) {
HotcueControl* pControl = m_hotcueControl.value(hotCue, NULL);
if (pControl == NULL) {
return;
}
Cue* pCue = pControl->getCue();
if (!pCue)
return;
disconnect(pCue, 0, this, 0);
// clear pCue first because we have a null check for valid data else where
// in the code
pControl->setCue(NULL);
pControl->getPosition()->set(-1); // invalidate position for hintReader()
pControl->getEnabled()->set(0);
}
void CueControl::trackLoaded(TrackPointer pTrack) {
QMutexLocker lock(&m_mutex);
if (m_pLoadedTrack)
trackUnloaded(m_pLoadedTrack);
if (!pTrack) {
return;
}
m_pLoadedTrack = pTrack;
connect(pTrack.data(), SIGNAL(cuesUpdated()),
this, SLOT(trackCuesUpdated()),
Qt::DirectConnection);
Cue* loadCue = NULL;
const QList<Cue*>& cuePoints = pTrack->getCuePoints();
QListIterator<Cue*> it(cuePoints);
while (it.hasNext()) {
Cue* pCue = it.next();
if (pCue->getType() == Cue::LOAD) {
loadCue = pCue;
} else if (pCue->getType() != Cue::CUE) {
continue;
}
int hotcue = pCue->getHotCue();
if (hotcue != -1)
attachCue(pCue, hotcue);
}
double loadCuePoint = 0.0;
// If cue recall is ON in the prefs, then we're supposed to seek to the cue
// point on song load. Note that [Controls],cueRecall == 0 corresponds to "ON", not OFF.
bool cueRecall = (getConfig()->getValueString(
ConfigKey("[Controls]","CueRecall"), "0").toInt() == 0);
if (loadCue != NULL) {
m_pCuePoint->set(loadCue->getPosition());
if (cueRecall) {
loadCuePoint = loadCue->getPosition();
}
} else {
// If no cue point is stored, set one at track start
m_pCuePoint->set(0.0);
}
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
// If cueRecall is on, seek to it even if we didn't find a cue value (we'll
// seek to 0.
if (cueRecall) {
seekExact(loadCuePoint);
} else if (!(m_pVinylControlEnabled->get() &&
m_pVinylControlMode->get() == MIXXX_VCMODE_ABSOLUTE)) {
// If cuerecall is off, seek to zero unless
// vinylcontrol is on and set to absolute. This allows users to
// load tracks and have the needle-drop be maintained.
seekExact(0.0);
}
}
void CueControl::trackUnloaded(TrackPointer pTrack) {
QMutexLocker lock(&m_mutex);
disconnect(pTrack.data(), 0, this, 0);
for (int i = 0; i < m_iNumHotCues; ++i) {
detachCue(i);
}
// Store the cue point in a load cue.
double cuePoint = m_pCuePoint->get();
if (cuePoint != -1 && cuePoint != 0.0) {
Cue* loadCue = NULL;
const QList<Cue*>& cuePoints = pTrack->getCuePoints();
QListIterator<Cue*> it(cuePoints);
while (it.hasNext()) {
Cue* pCue = it.next();
if (pCue->getType() == Cue::LOAD) {
loadCue = pCue;
break;
}
}
if (!loadCue) {
loadCue = pTrack->addCue();
loadCue->setType(Cue::LOAD);
loadCue->setLength(0);
}
loadCue->setPosition(cuePoint);
}
m_pCueIndicator->setBlinkValue(ControlIndicator::OFF);
m_pCuePoint->set(-1.0);
m_pLoadedTrack.clear();
}
void CueControl::cueUpdated() {
//QMutexLocker lock(&m_mutex);
// We should get a trackCuesUpdated call anyway, so do nothing.
}
void CueControl::trackCuesUpdated() {
QMutexLocker lock(&m_mutex);
QSet<int> active_hotcues;
if (!m_pLoadedTrack)
return;
const QList<Cue*>& cuePoints = m_pLoadedTrack->getCuePoints();
QListIterator<Cue*> it(cuePoints);
while (it.hasNext()) {
Cue* pCue = it.next();
if (pCue->getType() != Cue::CUE && pCue->getType() != Cue::LOAD)
continue;
int hotcue = pCue->getHotCue();
if (hotcue != -1) {
HotcueControl* pControl = m_hotcueControl.value(hotcue, NULL);
// Cue's hotcue doesn't have a hotcue control.
if (pControl == NULL) {
continue;
}
Cue* pOldCue = pControl->getCue();
// If the old hotcue is different than this one.
if (pOldCue != pCue) {
// If the old hotcue exists, detach it
if (pOldCue != NULL)
detachCue(hotcue);
attachCue(pCue, hotcue);
} else {
// If the old hotcue is the same, then we only need to update
double dOldPosition = pControl->getPosition()->get();
double dOldEnabled = pControl->getEnabled()->get();
double dPosition = pCue->getPosition();
double dEnabled = dPosition == -1 ? 0.0 : 1.0;
if (dEnabled != dOldEnabled) {
pControl->getEnabled()->set(dEnabled);
}
if (dPosition != dOldPosition) {
pControl->getPosition()->set(dPosition);
}
}
// Add the hotcue to the list of active hotcues
active_hotcues.insert(hotcue);
}
}
// Detach all hotcues that are no longer present
for (int i = 0; i < m_iNumHotCues; ++i) {
if (!active_hotcues.contains(i))
detachCue(i);
}
}
void CueControl::hotcueSet(HotcueControl* pControl, double v) {
//qDebug() << "CueControl::hotcueSet" << v;
if (!v)
return;
QMutexLocker lock(&m_mutex);
if (!m_pLoadedTrack)
return;
int hotcue = pControl->getHotcueNumber();
detachCue(hotcue);
Cue* pCue = m_pLoadedTrack->addCue();
double cuePosition =
(m_pQuantizeEnabled->get() > 0.0 && m_pClosestBeat->get() != -1) ?
floor(m_pClosestBeat->get()) : floor(getCurrentSample());
if (!even(static_cast<int>(cuePosition)))
cuePosition--;
pCue->setPosition(cuePosition);
pCue->setHotCue(hotcue);
pCue->setLabel("");
pCue->setType(Cue::CUE);
// TODO(XXX) deal with spurious signals
attachCue(pCue, hotcue);
// 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_pPlayButton->get() > 0;
if (!playing && m_pQuantizeEnabled->get() > 0.0) {
lock.unlock(); // prevent deadlock.
// Enginebuffer will quantize more exactly than we can.
seekAbs(cuePosition);
}
}
void CueControl::hotcueGoto(HotcueControl* pControl, double v) {
if (!v)
return;
QMutexLocker lock(&m_mutex);
if (!m_pLoadedTrack) {
return;
}
Cue* pCue = pControl->getCue();
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
if (pCue) {
int position = pCue->getPosition();
if (position != -1) {
seekAbs(position);
}
}
}
void CueControl::hotcueGotoAndStop(HotcueControl* pControl, double v) {
if (!v)
return;
QMutexLocker lock(&m_mutex);
if (!m_pLoadedTrack)
return;
Cue* pCue = pControl->getCue();
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
if (pCue) {
int position = pCue->getPosition();
if (position != -1) {
m_pPlayButton->set(0.0);
seekExact(position);
}
}
}
void CueControl::hotcueGotoAndPlay(HotcueControl* pControl, double v) {
if (!v)
return;
QMutexLocker lock(&m_mutex);
if (!m_pLoadedTrack) {
return;
}
Cue* pCue = pControl->getCue();
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
if (pCue) {
int position = pCue->getPosition();
if (position != -1) {
seekAbs(position);
m_pPlayButton->set(1.0);
}
}
}
void CueControl::hotcueActivate(HotcueControl* pControl, double v) {
//qDebug() << "CueControl::hotcueActivate" << v;
QMutexLocker lock(&m_mutex);
if (!m_pLoadedTrack) {
return;
}
Cue* pCue = pControl->getCue();
lock.unlock();
if (pCue) {
if (v) {
m_bHotcueCancel = false;
if (pCue->getPosition() == -1) {
hotcueSet(pControl, v);
} else {
if (!m_bPreviewingHotcue && m_pPlayButton->get() == 1.0) {
hotcueGoto(pControl, v);
} else {
hotcueActivatePreview(pControl, v);
}
}
} else {
if (pCue->getPosition() != -1) {
hotcueActivatePreview(pControl, v);
}
}
} else {
if (v) {
// just in case
m_bHotcueCancel = false;
hotcueSet(pControl, v);
} else if (m_bPreviewingHotcue) {
// The cue is non-existent, yet we got a release for it and are
// currently previewing a hotcue. This is indicative of a corner
// case where the cue was detached while we were pressing it. Let
// hotcueActivatePreview handle it.
hotcueActivatePreview(pControl, v);
}
}
}
void CueControl::hotcueActivatePreview(HotcueControl* pControl, double v) {
QMutexLocker lock(&m_mutex);
if (!m_pLoadedTrack) {
return;
}
Cue* pCue = pControl->getCue();
if (v) {
if (pCue && pCue->getPosition() != -1) {
m_iCurrentlyPreviewingHotcues++;
int iPosition = pCue->getPosition();
m_bPreviewingHotcue = true;
m_pPlayButton->set(1.0);
pControl->setPreviewing(true);
pControl->setPreviewingPosition(iPosition);
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
seekAbs(iPosition);
}
} else if (m_bPreviewingHotcue) {
// This is a activate release and we are previewing at least one
// hotcue. If this hotcue is previewing:
if (pControl->isPreviewing()) {
// Mark this hotcue as not previewing.
int iPosition = pControl->getPreviewingPosition();
pControl->setPreviewing(false);
pControl->setPreviewingPosition(-1);
// If this is the last hotcue to leave preview.
if (--m_iCurrentlyPreviewingHotcues == 0) {
bool bHotcueCancel = m_bHotcueCancel;
m_bPreviewingHotcue = false;
m_bHotcueCancel = false;
// If hotcue cancel was not marked then snap back to the
// hotcue and stop.
if (!bHotcueCancel) {
m_pPlayButton->set(0.0);
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
seekExact(iPosition);
}
}
}
}
}
void CueControl::hotcueClear(HotcueControl* pControl, double v) {
if (!v)
return;
QMutexLocker lock(&m_mutex);
if (!m_pLoadedTrack) {
return;
}
Cue* pCue = pControl->getCue();
if (pCue) {
pCue->setHotCue(-1);
}
detachCue(pControl->getHotcueNumber());
}
void CueControl::hotcuePositionChanged(HotcueControl* pControl, double newPosition) {
QMutexLocker lock(&m_mutex);
if (!m_pLoadedTrack)
return;
Cue* pCue = pControl->getCue();
if (pCue) {
// Setting the position to -1 is the same as calling hotcue_x_clear
if (newPosition == -1) {
pCue->setHotCue(-1);
detachCue(pControl->getHotcueNumber());
} else if (newPosition > 0 && newPosition < m_pTrackSamples->get()) {
int position = newPosition;
// People writing from MIDI land, elsewhere might be careless.
if (position % 2 != 0) {
position--;
}
pCue->setPosition(position);
}
}
}
void CueControl::hintReader(HintVector* pHintList) {
Hint cue_hint;
double cuePoint = m_pCuePoint->get();
if (cuePoint >= 0) {
cue_hint.sample = m_pCuePoint->get();
cue_hint.length = 0;
cue_hint.priority = 10;
pHintList->append(cue_hint);
}
// this is called from the engine thread
// it is no locking required, because m_hotcueControl is filled during the
// constructor and getPosition()->get() is a ControlObject
for (QList<HotcueControl*>::const_iterator it = m_hotcueControl.constBegin();
it != m_hotcueControl.constEnd(); ++it) {
HotcueControl* pControl = *it;
double position = pControl->getPosition()->get();
if (position != -1) {
cue_hint.sample = position;
if (cue_hint.sample % 2 != 0)
cue_hint.sample--;
cue_hint.length = 0;
cue_hint.priority = 10;
pHintList->append(cue_hint);
}
}
}
void CueControl::saveCuePoint(double cuePoint) {
if (m_pLoadedTrack) {
m_pLoadedTrack->setCuePoint(cuePoint);
}
}
void CueControl::cueSet(double v) {
if (!v)
return;
QMutexLocker lock(&m_mutex);
double cue = (m_pQuantizeEnabled->get() > 0.0 && m_pClosestBeat->get() != -1) ?
floor(m_pClosestBeat->get()) : floor(getCurrentSample());
if (!even(static_cast<int>(cue)))
cue--;
m_pCuePoint->set(cue);
saveCuePoint(cue);
}
void CueControl::cueGoto(double v)
{
if (!v)
return;
QMutexLocker lock(&m_mutex);
// Seek to cue point
double cuePoint = m_pCuePoint->get();
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
seekAbs(cuePoint);
}
void CueControl::cueGotoAndPlay(double v)
{
if (!v)
return;
cueGoto(v);
QMutexLocker lock(&m_mutex);
// Start playing if not already
if (m_pPlayButton->get()==0.) {
m_pPlayButton->set(1.0);
}
}
void CueControl::cueGotoAndStop(double v)
{
if (!v)
return;
QMutexLocker lock(&m_mutex);
m_pPlayButton->set(0.0);
double cuePoint = m_pCuePoint->get();
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
seekExact(cuePoint);
}
void CueControl::cuePreview(double v)
{
QMutexLocker lock(&m_mutex);
if (v) {
m_bPreviewing = true;
m_pPlayButton->set(1.0);
} else if (!v && m_bPreviewing) {
m_bPreviewing = false;
m_pPlayButton->set(0.0);
}
double cuePoint = m_pCuePoint->get();
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
seekAbs(cuePoint);
}
void CueControl::cueCDJ(double v) {
// This is how Pioneer cue buttons work:
// If pressed while playing, stop playback and go to cue.
// If pressed while stopped and at cue, play while pressed.
// If pressed while stopped and not at cue, set new cue point.
// If play is pressed while holding cue, the deck is now playing. (Handled in playFromCuePreview().)
QMutexLocker lock(&m_mutex);
bool playing = (m_pPlayButton->get() == 1.0);
if (v) {
if (playing || atEndPosition()) {
// Jump to cue when playing or when at end position
// Just in case.
m_bPreviewing = false;
m_pPlayButton->set(0.0);
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
seekAbs(m_pCuePoint->get());
} else if (isTrackAtCue()) {
// pause at cue point
m_bPreviewing = true;
m_pPlayButton->set(1.0);
} else {
// Pause not at cue point and not at end position
cueSet(v);
// Just in case.
m_bPreviewing = false;
// If quantize is enabled, jump to the cue point since it's not
// necessarily where we currently are
if (m_pQuantizeEnabled->get() > 0.0) {
lock.unlock(); // prevent deadlock.
// Enginebuffer will quantize more exactly than we can.
seekAbs(m_pCuePoint->get());
}
}
} else if (m_bPreviewing) {
m_bPreviewing = false;
m_pPlayButton->set(0.0);
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
seekAbs(m_pCuePoint->get());
}
// indicator may flash because the delayed adoption of seekAbs
// Correct the Indicator set via play
if (m_pLoadedTrack && !playing) {
m_pCueIndicator->setBlinkValue(ControlIndicator::ON);
} else {
m_pCueIndicator->setBlinkValue(ControlIndicator::OFF);
}
}
void CueControl::cueDenon(double v) {
// This is how Denon DN-S 3700 cue buttons work:
// If pressed go to cue and stop.
// If pressed while stopped and at cue, play while pressed.
// Cue Point is moved by play from pause
QMutexLocker lock(&m_mutex);
bool playing = (m_pPlayButton->get() == 1.0);
if (v) {
if (!playing && isTrackAtCue()) {
// pause at cue point
m_bPreviewing = true;
m_pPlayButton->set(1.0);
} else {
// Just in case.
m_bPreviewing = false;
m_pPlayButton->set(0.0);
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
seekAbs(m_pCuePoint->get());
}
} else if (m_bPreviewing) {
m_bPreviewing = false;
m_pPlayButton->set(0.0);
// Need to unlock before emitting any signals to prevent deadlock.
lock.unlock();
seekAbs(m_pCuePoint->get());
}
}
void CueControl::cueDefault(double v) {
double cueMode = m_pCueMode->get();
// Decide which cue implementation to call based on the user preference
if (cueMode == CUE_MODE_DENON || cueMode == CUE_MODE_NUMARK) {
cueDenon(v);
} else {
// The modes CUE_MODE_PIONEER and CUE_MODE_MIXXX are similar
// are handled inside cueCDJ(v)
// default to Pioneer mode
cueCDJ(v);
}
}
void CueControl::pause(double v) {
QMutexLocker lock(&m_mutex);
//qDebug() << "CueControl::pause()" << v;
if (v != 0.0) {
m_pPlayButton->set(0.0);
}
}
void CueControl::playStutter(double v) {
QMutexLocker lock(&m_mutex);
//qDebug() << "playStutter" << v;
if (v != 0.0) {
if (m_pPlayButton->get() != 0.0) {
cueGoto(1.0);
} else {
m_pPlayButton->set(1.0);
}
}
}
double CueControl::updateIndicatorsAndModifyPlay(double play, bool playPossible) {
QMutexLocker lock(&m_mutex);
double cueMode = m_pCueMode->get();
if ((cueMode == CUE_MODE_DENON || cueMode == CUE_MODE_NUMARK) &&
play > 0.0 &&
playPossible &&
m_pPlayButton->get() == 0.0) {
// in Denon mode each play from pause moves the cue point
// if not previewing
cueSet(1.0);
}
// when previewing, "play" was set by cue button, a following toggle request
// (play = 0.0) is used for latching play.
bool previewing = false;
if (m_bPreviewing || m_bPreviewingHotcue) {
if (play == 0.0) {
// play latch request: stop previewing and go into normal play mode.
m_bPreviewing = false;
m_bHotcueCancel = true;
play = 1.0;
} else {
previewing = true;
}
}
if (!playPossible) {
// play not possible
play = 0.0;
m_pPlayIndicator->setBlinkValue(ControlIndicator::OFF);
m_pStopButton->set(0.0);
} else if (play && !previewing) {
// Play: Indicates a latched Play
m_pPlayIndicator->setBlinkValue(ControlIndicator::ON);
m_pStopButton->set(0.0);
} else {
// Pause:
m_pStopButton->set(1.0);
if (cueMode == CUE_MODE_DENON) {
if (isTrackAtCue()) {
m_pPlayIndicator->setBlinkValue(ControlIndicator::OFF);
} else {
// Flashing indicates that a following play would move cue point
m_pPlayIndicator->setBlinkValue(ControlIndicator::RATIO1TO1_500MS);
}
} else if (cueMode == CUE_MODE_MIXXX || cueMode == CUE_MODE_NUMARK) {
m_pPlayIndicator->setBlinkValue(ControlIndicator::OFF);
} else {
// Flashing indicates that play is possible in Pioneer mode
m_pPlayIndicator->setBlinkValue(ControlIndicator::RATIO1TO1_500MS);
}
}
if (cueMode != CUE_MODE_DENON && cueMode != CUE_MODE_NUMARK) {
if (m_pCuePoint->get() != -1) {
if (play == 0.0 && !isTrackAtCue() &&
!atEndPosition()) {
if (cueMode == CUE_MODE_MIXXX) {
// in Mixxx mode Cue Button is flashing slow if CUE will move Cue point
m_pCueIndicator->setBlinkValue(ControlIndicator::RATIO1TO1_500MS);
} else {
// in Pioneer mode Cue Button is flashing fast if CUE will move Cue point
m_pCueIndicator->setBlinkValue(ControlIndicator::RATIO1TO1_250MS);
}
} else {
m_pCueIndicator->setBlinkValue(ControlIndicator::OFF);
}
} else {
m_pCueIndicator->setBlinkValue(ControlIndicator::OFF);
}
}
m_pPlayStutter->set(play);
return play;
}
void CueControl::updateIndicators() {
// No need for mutex lock because we are only touching COs.
double cueMode = m_pCueMode->get();
if (cueMode == CUE_MODE_DENON || cueMode == CUE_MODE_NUMARK) {
// Cue button is only lit at cue point
bool playing = m_pPlayButton->get() > 0;
if (isTrackAtCue()) {
// at cue point
if (!playing) {
m_pCueIndicator->setBlinkValue(ControlIndicator::ON);
m_pPlayIndicator->setBlinkValue(ControlIndicator::OFF);
}
} else {
m_pCueIndicator->setBlinkValue(ControlIndicator::OFF);
if (!playing) {
if (!atEndPosition() && cueMode != CUE_MODE_NUMARK) {
// Play will move cue point
m_pPlayIndicator->setBlinkValue(ControlIndicator::RATIO1TO1_500MS);
} else {
// At track end
m_pPlayIndicator->setBlinkValue(ControlIndicator::OFF);
}
}
}
} else {
// Here we have CUE_MODE_PIONEER or CUE_MODE_MIXXX
// default to Pioneer mode
if (!m_bPreviewing) {
bool playing = m_pPlayButton->get() > 0;
if (!playing) {
if (!isTrackAtCue()) {
if (!atEndPosition()) {
if (cueMode == CUE_MODE_MIXXX) {
// in Mixxx mode Cue Button is flashing slow if CUE will move Cue point
m_pCueIndicator->setBlinkValue(ControlIndicator::RATIO1TO1_500MS);
} else {
// in Pioneer mode Cue Button is flashing fast if CUE will move Cue point
m_pCueIndicator->setBlinkValue(ControlIndicator::RATIO1TO1_250MS);
}
} else {
// At track end
m_pCueIndicator->setBlinkValue(ControlIndicator::OFF);
}
} else if (m_pCuePoint->get() != -1) {
// Next Press is preview
m_pCueIndicator->setBlinkValue(ControlIndicator::ON);
}
}
}
}
}
bool CueControl::isTrackAtCue() {
return (fabs(getCurrentSample() - m_pCuePoint->get()) < 1.0f);
}
ConfigKey HotcueControl::keyForControl(int hotcue, QString name) {
ConfigKey key;
key.group = m_group;
// Add one to hotcue so that we dont have a hotcue_0
key.item = QString("hotcue_%1_%2").arg(QString::number(hotcue+1), name);
return key;
}
HotcueControl::HotcueControl(QString group, int i)
: m_group(group),
m_iHotcueNumber(i),
m_pCue(NULL),
m_bPreviewing(false),
m_iPreviewingPosition(-1) {
m_hotcuePosition = new ControlObject(keyForControl(i, "position"));
connect(m_hotcuePosition, SIGNAL(valueChanged(double)),
this, SLOT(slotHotcuePositionChanged(double)),
Qt::DirectConnection);
m_hotcuePosition->set(-1);
m_hotcueEnabled = new ControlObject(keyForControl(i, "enabled"));
m_hotcueEnabled->set(0);
m_hotcueSet = new ControlPushButton(keyForControl(i, "set"));
connect(m_hotcueSet, SIGNAL(valueChanged(double)),
this, SLOT(slotHotcueSet(double)),
Qt::DirectConnection);
m_hotcueGoto = new ControlPushButton(keyForControl(i, "goto"));
connect(m_hotcueGoto, SIGNAL(valueChanged(double)),
this, SLOT(slotHotcueGoto(double)),
Qt::DirectConnection);
m_hotcueGotoAndPlay = new ControlPushButton(keyForControl(i, "gotoandplay"));
connect(m_hotcueGotoAndPlay, SIGNAL(valueChanged(double)),
this, SLOT(slotHotcueGotoAndPlay(double)),
Qt::DirectConnection);
m_hotcueGotoAndStop = new ControlPushButton(keyForControl(i, "gotoandstop"));
connect(m_hotcueGotoAndStop, SIGNAL(valueChanged(double)),
this, SLOT(slotHotcueGotoAndStop(double)),
Qt::DirectConnection);
m_hotcueActivate = new ControlPushButton(keyForControl(i, "activate"));
connect(m_hotcueActivate, SIGNAL(valueChanged(double)),
this, SLOT(slotHotcueActivate(double)),
Qt::DirectConnection);
m_hotcueActivatePreview = new ControlPushButton(keyForControl(i, "activate_preview"));
connect(m_hotcueActivatePreview, SIGNAL(valueChanged(double)),
this, SLOT(slotHotcueActivatePreview(double)),
Qt::DirectConnection);
m_hotcueClear = new ControlPushButton(keyForControl(i, "clear"));