-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
enginesynctest.cpp
3181 lines (2680 loc) · 133 KB
/
enginesynctest.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 <gmock/gmock.h>
#include <gtest/gtest.h>
#include <memory>
#include <string>
#include "control/controlobject.h"
#include "engine/controls/bpmcontrol.h"
#include "engine/sync/synccontrol.h"
#include "mixer/basetrackplayer.h"
#include "preferences/usersettings.h"
#include "test/mixxxtest.h"
#include "test/mockedenginebackendtest.h"
#include "track/beats.h"
namespace {
constexpr double kMaxFloatingPointErrorLowPrecision = 0.005;
constexpr double kMaxFloatingPointErrorHighPrecision = 0.0000000000000005;
constexpr double kMaxBeatDistanceEpsilon = 1e-9;
} // namespace
/// Tests for Sync Lock.
/// The following manual tests should probably be performed:
/// * Quantize mode nudges tracks in sync, whether internal or deck leader.
/// * Flinging tracks with the waveform should work.
/// * vinyl??
class EngineSyncTest : public MockedEngineBackendTest {
public:
QString getLeaderGroup() {
Syncable* pLeaderSyncable = m_pEngineSync->getLeaderSyncable();
if (pLeaderSyncable) {
return pLeaderSyncable->getGroup();
}
return QString();
}
bool isExplicitLeader(const QString& group) {
return isLeader(group, SyncMode::LeaderExplicit);
}
bool isSoftLeader(const QString& group) {
return isLeader(group, SyncMode::LeaderSoft);
}
bool isFollower(const QString& group) {
if (group == m_sInternalClockGroup) {
return !ControlObject::getControl(ConfigKey(m_sInternalClockGroup,
"sync_leader"))
->toBool();
}
if (auto mode = ControlObject::getControl(ConfigKey(group, "sync_mode"))
->get();
static_cast<SyncMode>(mode) != SyncMode::Follower) {
qWarning() << "expected mode Follower, got" << mode;
return false;
}
if (!ControlObject::getControl(ConfigKey(group, "sync_enabled"))->toBool()) {
qWarning() << "sync_enabled should be on, isn't";
return false;
}
if (double leader = ControlObject::getControl(
ConfigKey(group, "sync_leader"))
->get();
leader != 0.0) {
qWarning() << "sync_leader should be 0.0, is" << leader;
return false;
}
return true;
}
void assertSyncOff(const QString& group) {
if (group == m_sInternalClockGroup) {
EXPECT_EQ(0,
ControlObject::getControl(
ConfigKey(m_sInternalClockGroup, "sync_leader"))
->get());
} else {
EXPECT_EQ(SyncMode::None,
static_cast<SyncMode>(ControlObject::getControl(ConfigKey(group, "sync_mode"))
->get()));
EXPECT_EQ(0,
ControlObject::getControl(ConfigKey(group, "sync_enabled"))
->get());
EXPECT_EQ(0,
ControlObject::getControl(ConfigKey(group, "sync_leader"))
->get());
}
}
void assertNoLeader() {
EXPECT_EQ(NULL, m_pEngineSync->getLeaderChannel());
EXPECT_EQ(NULL, m_pEngineSync->getLeaderSyncable());
}
private:
bool isLeader(const QString& group, SyncMode leaderType) {
if (group == m_sInternalClockGroup) {
double leader = ControlObject::getControl(ConfigKey(m_sInternalClockGroup,
"sync_leader"))
->get();
if (leaderType == SyncMode::LeaderSoft && leader != 1.0) {
qWarning() << "internal clock sync_leader should be 1.0, is" << leader;
return false;
} else if (leaderType == SyncMode::LeaderExplicit && leader != 2.0) {
qWarning() << "internal clock sync_leader should be 2.0, is" << leader;
return false;
}
if (m_pEngineSync->getLeaderChannel()) {
qWarning() << "no current leader";
return false;
}
if (m_sInternalClockGroup != getLeaderGroup()) {
qWarning() << "internal clock is not leader, it's" << getLeaderGroup();
return false;
}
return true;
}
if (group == m_sGroup1) {
if (m_pEngineSync->getLeaderChannel() != m_pChannel1) {
qWarning() << "leader pointer should be channel 1, is "
<< (m_pEngineSync->getLeaderChannel()
? m_pEngineSync->getLeaderChannel()
->getGroup()
: "null");
return false;
}
} else if (group == m_sGroup2) {
if (m_pEngineSync->getLeaderChannel() != m_pChannel2) {
qWarning() << "leader pointer should be channel 2, is "
<< (m_pEngineSync->getLeaderChannel()
? m_pEngineSync->getLeaderChannel()
->getGroup()
: "null");
return false;
}
} else if (group == m_sGroup3) {
if (m_pEngineSync->getLeaderChannel() != m_pChannel3) {
qWarning() << "leader pointer should be channel 3, is "
<< (m_pEngineSync->getLeaderChannel()
? m_pEngineSync->getLeaderChannel()
->getGroup()
: "null");
return false;
}
}
if (getLeaderGroup() != group) {
qWarning() << "leader group should be" << group << ", is" << getLeaderGroup();
return false;
}
if (auto mode = ControlObject::getControl(ConfigKey(group, "sync_mode"))
->get();
static_cast<SyncMode>(mode) != leaderType) {
qWarning() << "mode should be" << leaderType << ", is" << mode;
return false;
}
if (!ControlObject::getControl(ConfigKey(group, "sync_enabled"))->toBool()) {
qWarning() << "sync_enabled should be true, isn't";
return false;
}
switch (leaderType) {
case SyncMode::LeaderSoft: {
if (double leader = ControlObject::getControl(
ConfigKey(group, "sync_leader"))
->get();
leader != 1.0) {
qWarning() << "leader should be 1.0, is" << leader;
return false;
}
break;
}
case SyncMode::LeaderExplicit: {
if (double leader = ControlObject::getControl(
ConfigKey(group, "sync_leader"))
->get();
leader != 2.0) {
qWarning() << "leader should be 2.0, is" << leader;
return false;
}
break;
}
default:
qWarning() << "bad leader type specified";
return false;
}
return true;
}
};
TEST_F(EngineSyncTest, ControlObjectsExist) {
// This isn't exhaustive, but certain COs have a habit of not being set up properly.
EXPECT_TRUE(ControlObject::getControl(ConfigKey(m_sGroup1, "file_bpm")) !=
NULL);
}
TEST_F(EngineSyncTest, SetLeaderSuccess) {
// If we set the first channel to leader, EngineSync should get that message.
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonLeaderSync1->set(static_cast<double>(SyncMode::LeaderExplicit));
ProcessBuffer();
// No tracks are playing and we have no beats, LeaderExplicit state is in stand-by
EXPECT_DOUBLE_EQ(
0.0, ControlObject::getControl(ConfigKey(m_sGroup1, "bpm"))->get());
// The sync lock should now be internal clock, with group 1 waiting for play.
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
EXPECT_TRUE(isFollower(m_sGroup1));
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
pButtonLeaderSync2->set(static_cast<double>(SyncMode::Follower));
ProcessBuffer();
EXPECT_TRUE(isFollower(m_sGroup2));
// Now set channel 2 to be leader.
pButtonLeaderSync2->set(static_cast<double>(SyncMode::LeaderExplicit));
ProcessBuffer();
// Now channel 2 should be waiting leader, and channel 1 should be a follower.
EXPECT_TRUE(isFollower(m_sGroup2));
EXPECT_TRUE(isFollower(m_sGroup1));
// Now back again.
pButtonLeaderSync1->set(static_cast<double>(SyncMode::LeaderExplicit));
ProcessBuffer();
// Now channel 1 should be waiting leader, and channel 2 should be a follower.
EXPECT_TRUE(isFollower(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
// Now set channel 1 to follower, now all are followers, waiting for a tempo to adopt.
pButtonLeaderSync1->set(static_cast<double>(SyncMode::Follower));
ProcessBuffer();
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
EXPECT_TRUE(isFollower(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
}
TEST_F(EngineSyncTest, ExplicitLeaderPersists) {
// If we set an explicit leader, enabling sync or pressing play on other decks
// doesn't cause the leader to move around.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(120));
m_pTrack1->trySetBeats(pBeats1);
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(124));
m_pTrack2->trySetBeats(pBeats2);
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
ControlObject::getControl(ConfigKey(m_sGroup1, "play"))->set(1.0);
ProcessBuffer();
pButtonLeaderSync1->set(static_cast<double>(SyncMode::LeaderExplicit));
ProcessBuffer();
// The sync lock should now be channel 1.
EXPECT_TRUE(isExplicitLeader(m_sGroup1));
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_enabled");
ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(1.0);
pButtonLeaderSync2->set(1.0);
ProcessBuffer();
EXPECT_TRUE(isExplicitLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
// Stop deck 2, and restart it, no change.
ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(0.0);
ProcessBuffer();
ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(1.0);
ProcessBuffer();
EXPECT_TRUE(isExplicitLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
}
TEST_F(EngineSyncTest, SetLeaderWhilePlaying) {
// Make sure we don't get two leader lights if we change leaders while playing.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(120));
m_pTrack1->trySetBeats(pBeats1);
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(124));
m_pTrack2->trySetBeats(pBeats2);
mixxx::BeatsPointer pBeats3 = mixxx::Beats::fromConstTempo(
m_pTrack3->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(128));
m_pTrack3->trySetBeats(pBeats3);
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonLeaderSync1->set(static_cast<double>(SyncMode::LeaderExplicit));
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
pButtonLeaderSync2->set(static_cast<double>(SyncMode::Follower));
auto pButtonLeaderSync3 =
std::make_unique<ControlProxy>(m_sGroup3, "sync_mode");
pButtonLeaderSync3->set(static_cast<double>(SyncMode::Follower));
ControlObject::getControl(ConfigKey(m_sGroup1, "play"))->set(1.0);
ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(1.0);
ControlObject::getControl(ConfigKey(m_sGroup3, "play"))->set(1.0);
ProcessBuffer();
pButtonLeaderSync3->set(static_cast<double>(SyncMode::LeaderExplicit));
ProcessBuffer();
EXPECT_TRUE(isFollower(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
EXPECT_TRUE(isExplicitLeader(m_sGroup3));
}
TEST_F(EngineSyncTest, SetEnabledBecomesLeader) {
// If we set the first channel with a valid tempo to follower, it should be leader.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(80));
m_pTrack1->trySetBeats(pBeats1);
ProcessBuffer();
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonLeaderSync1->set(static_cast<double>(SyncMode::Follower));
ProcessBuffer();
EXPECT_TRUE(isSoftLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
}
TEST_F(EngineSyncTest, DisableInternalLeaderWhilePlaying) {
auto pButtonLeaderSync = std::make_unique<ControlProxy>(
m_sInternalClockGroup, "sync_leader");
pButtonLeaderSync->set(1.0);
auto pButtonSyncMode1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonSyncMode1->set(static_cast<double>(SyncMode::Follower));
auto pButtonSyncMode2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
pButtonSyncMode2->set(static_cast<double>(SyncMode::Follower));
ProcessBuffer();
// The sync lock should now be Internal.
EXPECT_TRUE(isExplicitLeader(m_sInternalClockGroup));
// Make sure both decks are playing.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(80));
m_pTrack1->trySetBeats(pBeats1);
ControlObject::getControl(ConfigKey(m_sGroup1, "play"))->set(1.0);
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(80));
m_pTrack2->trySetBeats(pBeats2);
ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(1.0);
ProcessBuffer();
// Now unset Internal leader.
pButtonLeaderSync->set(0.0);
ProcessBuffer();
// This is not allowed, Internal should still be leader.
EXPECT_TRUE(isSoftLeader(m_sInternalClockGroup));
EXPECT_EQ(1, pButtonLeaderSync->get());
}
TEST_F(EngineSyncTest, DisableSyncOnLeader) {
// Channel 1 follower, channel 2 leader.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(130));
m_pTrack1->trySetBeats(pBeats1);
auto pButtonSyncMode1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonSyncMode1->set(static_cast<double>(SyncMode::Follower));
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(130));
m_pTrack2->trySetBeats(pBeats2);
// Set deck two to leader, but this is not allowed because it's stopped.
ProcessBuffer();
auto pButtonSyncLeader2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_leader");
pButtonSyncLeader2->set(1.0);
ProcessBuffer();
EXPECT_TRUE(isSoftLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
// Set deck 2 to playing, now it becomes explicit leader.
ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(1.0);
// The request to become leader is queued, so we have to process a buffer.
ProcessBuffer();
EXPECT_TRUE(isFollower(m_sGroup1));
EXPECT_TRUE(isSoftLeader(m_sGroup2));
// Unset enabled on channel2, it should work.
auto pButtonSyncEnabled2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_enabled");
pButtonSyncEnabled2->set(0.0);
ProcessBuffer();
EXPECT_TRUE(isSoftLeader(m_sGroup1));
EXPECT_EQ(0, ControlObject::getControl(ConfigKey(m_sGroup2, "sync_enabled"))->get());
EXPECT_EQ(0, ControlObject::getControl(ConfigKey(m_sGroup2, "sync_leader"))->get());
}
TEST_F(EngineSyncTest, InternalLeaderSetFollowerSliderMoves) {
// If internal is leader, and we turn on a follower, the slider should move.
auto pButtonLeaderSyncInternal = std::make_unique<ControlProxy>(
m_sInternalClockGroup, "sync_leader");
auto pInternalClockBpm =
std::make_unique<ControlProxy>(m_sInternalClockGroup, "bpm");
pInternalClockBpm->set(100.0);
// Request internal clock to become SyncMode::LeaderExplicit
pButtonLeaderSyncInternal->set(1);
EXPECT_TRUE(isExplicitLeader(m_sInternalClockGroup));
// Set the file bpm of channel 1 to 80 bpm.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(80));
m_pTrack1->trySetBeats(pBeats1);
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonLeaderSync1->set(static_cast<double>(SyncMode::Follower));
ProcessBuffer();
EXPECT_TRUE(isFollower(m_sGroup1));
EXPECT_TRUE(isExplicitLeader(m_sInternalClockGroup));
EXPECT_DOUBLE_EQ(getRateSliderValue(1.25),
ControlObject::getControl(ConfigKey(m_sGroup1, "rate"))->get());
EXPECT_DOUBLE_EQ(100.0,
ControlObject::getControl(ConfigKey(m_sGroup1, "bpm"))->get());
}
TEST_F(EngineSyncTest, AnySyncDeckSliderStays) {
// If there exists a sync deck, even if it's not playing, don't change the
// leader BPM if a new deck enables sync.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(80));
m_pTrack1->trySetBeats(pBeats1);
ProcessBuffer();
auto pButtonSyncEnabled1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_enabled");
pButtonSyncEnabled1->set(1.0);
// After setting up the first deck, the internal BPM should be 80.
EXPECT_DOUBLE_EQ(80.0,
ControlObject::getControl(ConfigKey(m_sInternalClockGroup, "bpm"))
->get());
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(100));
m_pTrack2->trySetBeats(pBeats2);
auto pButtonSyncEnabled2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_enabled");
pButtonSyncEnabled2->set(1.0);
// After the second one, though, the internal BPM should still be 80.
EXPECT_DOUBLE_EQ(80.0,
ControlObject::getControl(ConfigKey(m_sInternalClockGroup, "bpm"))
->get());
}
TEST_F(EngineSyncTest, InternalClockFollowsFirstPlayingDeck) {
// Same as above, except we use the midi lights to change state.
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
auto pButtonSyncEnabled1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_enabled");
auto pButtonSyncEnabled2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_enabled");
// Set up decks so they can be playing, and start deck 1.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(100));
m_pTrack1->trySetBeats(pBeats1);
ControlObject::set(ConfigKey(m_sGroup1, "rate"), getRateSliderValue(1.0));
ControlObject::set(ConfigKey(m_sGroup1, "play"), 1.0);
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(130));
m_pTrack2->trySetBeats(pBeats2);
ControlObject::set(ConfigKey(m_sGroup2, "rate"), getRateSliderValue(1.0));
ControlObject::set(ConfigKey(m_sGroup2, "play"), 0.0);
ProcessBuffer();
// Set channel 1 to be enabled
pButtonSyncEnabled1->set(1.0);
ProcessBuffer();
// The sync lock should now be deck 1.
EXPECT_TRUE(isSoftLeader(m_sGroup1));
EXPECT_DOUBLE_EQ(130.0,
ControlObject::get(ConfigKey(m_sInternalClockGroup, "bpm")));
// Set channel 2 to be enabled.
pButtonSyncEnabled2->set(1);
ProcessBuffer();
// channel 1 still leader while 2 is not playing
EXPECT_TRUE(isSoftLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
EXPECT_TRUE(isFollower(m_sGroup2));
// The rate should not have changed -- deck 1 still matches deck 2.
EXPECT_DOUBLE_EQ(getRateSliderValue(1.3),
ControlObject::getControl(ConfigKey(m_sGroup1, "rate"))->get());
// Reset channel 2 rate, set channel 2 to play, and process a buffer.
ControlObject::set(ConfigKey(m_sGroup2, "rate"), getRateSliderValue(1.0));
ControlObject::set(ConfigKey(m_sGroup2, "play"), 1.0);
ProcessBuffer();
// Deck 1 still leader
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
EXPECT_TRUE(isSoftLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
// Now disable sync on channel 1.
pButtonSyncEnabled1->set(0);
ProcessBuffer();
// Leader flips to deck 2
EXPECT_TRUE(isSoftLeader(m_sGroup2));
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
// Rate should now match channel 2.
EXPECT_DOUBLE_EQ(
130.0, ControlObject::get(ConfigKey(m_sInternalClockGroup, "bpm")));
}
TEST_F(EngineSyncTest, SetExplicitLeaderByLights) {
// Same as above, except we use the midi lights to change state.
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
auto pButtonSyncEnabled1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_enabled");
auto pButtonSyncEnabled2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_enabled");
auto pButtonSyncLeader1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_leader");
auto pButtonSyncLeader2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_leader");
// Set the file bpm of channel 1 to 160bpm.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(160));
m_pTrack1->trySetBeats(pBeats1);
// Set the file bpm of channel 2 to 150bpm.
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(150));
m_pTrack2->trySetBeats(pBeats2);
ControlObject::set(ConfigKey(m_sGroup1, "play"), 1.0);
ControlObject::set(ConfigKey(m_sGroup2, "play"), 1.0);
ProcessBuffer();
// Set channel 1 to be explicit leader.
pButtonSyncLeader1->set(1.0);
ProcessBuffer();
// The sync lock should now be channel 1.
EXPECT_TRUE(isSoftLeader(m_sGroup1));
// Set channel 2 to be follower.
pButtonSyncEnabled2->set(1);
ProcessBuffer();
EXPECT_TRUE(isFollower(m_sGroup2));
// Now set channel 2 to be leader.
pButtonSyncLeader2->set(1);
ProcessBuffer();
// Now channel 2 should be leader, and channel 1 should be a follower.
EXPECT_TRUE(isFollower(m_sGroup1));
EXPECT_TRUE(isSoftLeader(m_sGroup2));
// Now back again.
pButtonSyncLeader1->set(1);
ProcessBuffer();
// Now channel 1 should be leader, and channel 2 should be a follower.
EXPECT_TRUE(isSoftLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
// Now set channel 1 to not-leader.
// This will choose automatically a Soft Leader, so it chooses the other deck.
pButtonSyncLeader1->set(0);
ProcessBuffer();
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
EXPECT_TRUE(isFollower(m_sGroup1));
EXPECT_TRUE(isSoftLeader(m_sGroup2));
// Try again without playing
pButtonSyncLeader1->set(1);
ProcessBuffer();
EXPECT_TRUE(isSoftLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
ControlObject::set(ConfigKey(m_sGroup1, "play"), 0.0);
pButtonSyncLeader1->set(0);
ProcessBuffer();
// Now the m_sGroup2 should be leader because m_sGroup1 can't lead without playing
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
EXPECT_TRUE(isSoftLeader(m_sGroup2));
EXPECT_TRUE(isFollower(m_sGroup1));
}
TEST_F(EngineSyncTest, SetExplicitLeaderByLightsNoTracks) {
// Same as above, except we use the midi lights to change state.
auto pButtonSyncEnabled2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_enabled");
auto pButtonSyncLeader1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_leader");
pButtonSyncLeader1->set(1);
// Set channel 2 to be follower.
pButtonSyncEnabled2->set(1);
// Without a track loaded, deck 1 can't be an explicit leader.
EXPECT_TRUE(isFollower(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
pButtonSyncLeader1->set(0);
EXPECT_TRUE(isFollower(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
}
TEST_F(EngineSyncTest, RateChangeTest) {
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonLeaderSync1->set(static_cast<double>(SyncMode::LeaderExplicit));
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
pButtonLeaderSync2->set(static_cast<double>(SyncMode::Follower));
ProcessBuffer();
// Set the file bpm of channel 1 to 160bpm.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(160));
m_pTrack1->trySetBeats(pBeats1);
EXPECT_DOUBLE_EQ(
160.0, ControlObject::get(ConfigKey(m_sGroup1, "file_bpm")));
ProcessBuffer();
EXPECT_DOUBLE_EQ(
160.0, ControlObject::get(ConfigKey(m_sInternalClockGroup, "bpm")));
// Set the rate of channel 1 to 1.2.
ControlObject::set(ConfigKey(m_sGroup1, "rate"), getRateSliderValue(1.2));
EXPECT_DOUBLE_EQ(getRateSliderValue(1.2),
ControlObject::get(ConfigKey(m_sGroup1, "rate")));
EXPECT_DOUBLE_EQ(192.0, ControlObject::get(ConfigKey(m_sGroup1, "bpm")));
// Internal leader should also be 192.
EXPECT_DOUBLE_EQ(
192.0, ControlObject::get(ConfigKey(m_sInternalClockGroup, "bpm")));
// Set the file bpm of channel 2 to 120bpm.
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(120));
m_pTrack2->trySetBeats(pBeats2);
EXPECT_DOUBLE_EQ(
120.0, ControlObject::get(ConfigKey(m_sGroup2, "file_bpm")));
EXPECT_DOUBLE_EQ(getRateSliderValue(0.8),
ControlObject::get(ConfigKey(m_sGroup2, "rate")));
// Leader is currently 192, BPM before sync is 120, so the closer sync should be 96
EXPECT_DOUBLE_EQ(96.0, ControlObject::get(ConfigKey(m_sGroup2, "bpm")));
}
TEST_F(EngineSyncTest, RateChangeTestWeirdOrder) {
// This is like the test above, but the user loads the track after the slider has been tweaked.
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonLeaderSync1->set(static_cast<double>(SyncMode::LeaderExplicit));
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
pButtonLeaderSync2->set(static_cast<double>(SyncMode::Follower));
ProcessBuffer();
// Set the file bpm of channel 1 to 160bpm.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(160));
m_pTrack1->trySetBeats(pBeats1);
EXPECT_DOUBLE_EQ(
160.0, ControlObject::get(ConfigKey(m_sInternalClockGroup, "bpm")));
// Set the file bpm of channel 2 to 120bpm.
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(120));
m_pTrack2->trySetBeats(pBeats2);
// Set the rate slider of channel 1 to 1.2.
ControlObject::set(ConfigKey(m_sGroup1, "rate"), getRateSliderValue(1.2));
// Rate slider for channel 2 should now be 1.6 = (160 * 1.2 / 120) - 1.0.
EXPECT_DOUBLE_EQ(getRateSliderValue(1.6),
ControlObject::get(ConfigKey(m_sGroup2, "rate")));
EXPECT_DOUBLE_EQ(192.0, ControlObject::get(ConfigKey(m_sGroup2, "bpm")));
// Internal Leader BPM should read the same.
EXPECT_DOUBLE_EQ(
192.0, ControlObject::get(ConfigKey(m_sInternalClockGroup, "bpm")));
}
TEST_F(EngineSyncTest, RateChangeTestOrder3) {
// Set the file bpm of channel 1 to 160bpm.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(160));
m_pTrack1->trySetBeats(pBeats1);
EXPECT_DOUBLE_EQ(
160.0, ControlObject::get(ConfigKey(m_sGroup1, "file_bpm")));
// Set the file bpm of channel 2 to 120bpm.
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(120));
m_pTrack2->trySetBeats(pBeats2);
EXPECT_DOUBLE_EQ(
120.0, ControlObject::get(ConfigKey(m_sGroup2, "file_bpm")));
ProcessBuffer();
// Turn on Leader. Setting leader explicitly means we don't match the tempo of
// another deck.
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonLeaderSync1->set(static_cast<double>(SyncMode::LeaderExplicit));
ProcessBuffer();
EXPECT_TRUE(isExplicitLeader(m_sGroup1));
EXPECT_DOUBLE_EQ(160.0, ControlObject::get(ConfigKey(m_sGroup1, "bpm")));
// Turn on follower.
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
pButtonLeaderSync2->set(static_cast<double>(SyncMode::Follower));
ProcessBuffer();
// Follower should immediately set its slider.
EXPECT_NEAR(getRateSliderValue(1.0),
ControlObject::get(ConfigKey(m_sGroup1, "rate")),
kMaxFloatingPointErrorLowPrecision);
EXPECT_DOUBLE_EQ(160.0, ControlObject::get(ConfigKey(m_sGroup2, "bpm")));
EXPECT_DOUBLE_EQ(
160.0, ControlObject::get(ConfigKey(m_sInternalClockGroup, "bpm")));
}
TEST_F(EngineSyncTest, FollowerRateChange) {
// Confirm that followers can change sync lock rate as well.
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonLeaderSync1->set(static_cast<double>(SyncMode::LeaderExplicit));
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
pButtonLeaderSync2->set(static_cast<double>(SyncMode::Follower));
ProcessBuffer();
// Set the file bpm of channel 1 to 160bpm.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(160));
m_pTrack1->trySetBeats(pBeats1);
// Set the file bpm of channel 2 to 120bpm.
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(120));
m_pTrack2->trySetBeats(pBeats2);
// Set the rate slider of channel 1 to 1.2.
ControlObject::set(ConfigKey(m_sGroup1, "rate"), getRateSliderValue(1.2));
// Rate slider for channel 2 should now be 1.6 = (160 * 1.2 / 120).
EXPECT_DOUBLE_EQ(getRateSliderValue(1.6),
ControlObject::get(ConfigKey(m_sGroup2, "rate")));
EXPECT_DOUBLE_EQ(192.0, ControlObject::get(ConfigKey(m_sGroup2, "bpm")));
// Try to twiddle the rate slider on channel 2.
auto pSlider2 = std::make_unique<ControlProxy>(m_sGroup2, "rate");
pSlider2->set(getRateSliderValue(0.8));
ProcessBuffer();
// Rates should still be changed even though it's a follower.
EXPECT_DOUBLE_EQ(getRateSliderValue(0.8),
ControlObject::get(ConfigKey(m_sGroup2, "rate")));
EXPECT_DOUBLE_EQ(96.0, ControlObject::get(ConfigKey(m_sGroup2, "bpm")));
EXPECT_DOUBLE_EQ(getRateSliderValue(0.6),
ControlObject::get(ConfigKey(m_sGroup1, "rate")));
EXPECT_DOUBLE_EQ(96.0, ControlObject::get(ConfigKey(m_sGroup1, "bpm")));
}
TEST_F(EngineSyncTest, InternalRateChangeTest) {
auto pButtonLeaderSyncInternal = std::make_unique<ControlProxy>(
m_sInternalClockGroup, "sync_leader");
pButtonLeaderSyncInternal->set(1.0);
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonLeaderSync1->set(static_cast<double>(SyncMode::Follower));
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
pButtonLeaderSync2->set(static_cast<double>(SyncMode::Follower));
ProcessBuffer();
EXPECT_TRUE(isExplicitLeader(m_sInternalClockGroup));
EXPECT_TRUE(isFollower(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
// Set the file bpm of channel 1 to 160bpm.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(160));
m_pTrack1->trySetBeats(pBeats1);
EXPECT_DOUBLE_EQ(160.0,
ControlObject::getControl(ConfigKey(m_sGroup1, "file_bpm"))->get());
// Set the file bpm of channel 2 to 120bpm.
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(120));
m_pTrack2->trySetBeats(pBeats2);
EXPECT_DOUBLE_EQ(120.0,
ControlObject::getControl(ConfigKey(m_sGroup2, "file_bpm"))->get());
// Set the internal rate to 150.
auto pLeaderSyncSlider =
std::make_unique<ControlProxy>(m_sInternalClockGroup, "bpm");
pLeaderSyncSlider->set(150.0);
EXPECT_DOUBLE_EQ(150.0,
ControlObject::getControl(ConfigKey(m_sInternalClockGroup, "bpm"))
->get());
// Set decks playing, and process a buffer to update all the COs.
ControlObject::getControl(ConfigKey(m_sGroup1, "play"))->set(1.0);
ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(1.0);
ProcessBuffer();
// Rate sliders for channels 1 and 2 should change appropriately.
EXPECT_DOUBLE_EQ(getRateSliderValue(0.9375),
ControlObject::getControl(ConfigKey(m_sGroup1, "rate"))->get());
EXPECT_DOUBLE_EQ(150.0,
ControlObject::getControl(ConfigKey(m_sGroup1, "bpm"))->get());
EXPECT_DOUBLE_EQ(getRateSliderValue(1.25),
ControlObject::getControl(ConfigKey(m_sGroup2, "rate"))->get());
EXPECT_DOUBLE_EQ(150.0,
ControlObject::getControl(ConfigKey(m_sGroup2, "bpm"))->get());
// Set the internal rate to 140.
pLeaderSyncSlider->set(140.0);
// Update COs again.
ProcessBuffer();
// Rate sliders for channels 1 and 2 should change appropriately.
EXPECT_DOUBLE_EQ(getRateSliderValue(.875),
ControlObject::getControl(ConfigKey(m_sGroup1, "rate"))->get());
EXPECT_DOUBLE_EQ(140.0,
ControlObject::getControl(ConfigKey(m_sGroup1, "bpm"))->get());
EXPECT_NEAR(getRateSliderValue(1.16666667),
ControlObject::getControl(ConfigKey(m_sGroup2, "rate"))->get(),
kMaxFloatingPointErrorLowPrecision);
EXPECT_DOUBLE_EQ(140.0,
ControlObject::getControl(ConfigKey(m_sGroup2, "bpm"))->get());
}
TEST_F(EngineSyncTest, LeaderStopSliderCheck) {
// If the leader is playing, and stop is pushed, the sliders should stay the same.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(120));
m_pTrack1->trySetBeats(pBeats1);
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(128));
m_pTrack2->trySetBeats(pBeats2);
auto pButtonLeaderSync2 =
std::make_unique<ControlProxy>(m_sGroup2, "sync_mode");
pButtonLeaderSync2->set(static_cast<double>(SyncMode::Follower));
auto pButtonLeaderSync1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_mode");
pButtonLeaderSync1->set(static_cast<double>(SyncMode::LeaderExplicit));
ProcessBuffer();
//EXPECT_TRUE(isExplicitLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
auto pChannel1Play = std::make_unique<ControlProxy>(m_sGroup1, "play");
pChannel1Play->set(1.0);
auto pChannel2Play = std::make_unique<ControlProxy>(m_sGroup2, "play");
pChannel2Play->set(1.0);
ProcessBuffer();
EXPECT_DOUBLE_EQ(120.0, ControlObject::get(ConfigKey(m_sGroup2, "bpm")));
EXPECT_DOUBLE_EQ(getRateSliderValue(0.9375),
ControlObject::get(ConfigKey(m_sGroup2, "rate")));
pChannel1Play->set(0.0);
ProcessBuffer();
EXPECT_DOUBLE_EQ(120.0, ControlObject::get(ConfigKey(m_sGroup2, "bpm")));
EXPECT_DOUBLE_EQ(getRateSliderValue(0.9375),
ControlObject::get(ConfigKey(m_sGroup2, "rate")));
}
TEST_F(EngineSyncTest, EnableOneDeckInitsLeader) {
// If Internal is leader, and we turn sync on a playing deck, the playing deck sets the
// internal leader and the beat distances are now aligned.
ControlObject::set(ConfigKey(m_sInternalClockGroup, "bpm"), 124.0);
ControlObject::set(ConfigKey(m_sInternalClockGroup, "beat_distance"), 0.5);
ProcessBuffer();
// Set up the deck to play.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(130));
m_pTrack1->trySetBeats(pBeats1);
ControlObject::getControl(ConfigKey(m_sGroup1, "rate"))
->set(getRateSliderValue(1.0));
ControlObject::getControl(ConfigKey(m_sGroup1, "beat_distance"))->set(0.2);
ControlObject::getControl(ConfigKey(m_sGroup1, "play"))->set(1.0);
// Enable Sync. We have to call requestEnableSync directly
// because calling ProcessBuffer() tries to advance the beat_distance values.
m_pEngineSync->requestSyncMode(
m_pEngineSync->getSyncableForGroup(m_sGroup1), SyncMode::Follower);
// Internal is no longer leader because there is exactly one playing deck.
EXPECT_TRUE(isSoftLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
// Internal clock rate and beat distance should match that deck.
EXPECT_DOUBLE_EQ(
130.0, ControlObject::get(ConfigKey(m_sInternalClockGroup, "bpm")));
EXPECT_DOUBLE_EQ(130.0, ControlObject::get(ConfigKey(m_sGroup1, "bpm")));
EXPECT_DOUBLE_EQ(
0.2, ControlObject::get(ConfigKey(m_sGroup1, "beat_distance")));
EXPECT_DOUBLE_EQ(0.2,
ControlObject::get(
ConfigKey(m_sInternalClockGroup, "beat_distance")));
// Enable second deck, bpm and beat distance should still match original setting.
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(140));
m_pTrack2->trySetBeats(pBeats2);
ControlObject::getControl(ConfigKey(m_sGroup2, "rate"))
->set(getRateSliderValue(1.0));
ControlObject::getControl(ConfigKey(m_sGroup2, "beat_distance"))->set(0.2);
ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(1.0);
m_pEngineSync->requestSyncMode(
m_pEngineSync->getSyncableForGroup(m_sGroup2), SyncMode::Follower);
// Deck 1 is still soft leader.
EXPECT_TRUE(isFollower(m_sInternalClockGroup));
EXPECT_TRUE(isSoftLeader(m_sGroup1));
EXPECT_TRUE(isFollower(m_sGroup2));
EXPECT_DOUBLE_EQ(
130.0, ControlObject::get(ConfigKey(m_sInternalClockGroup, "bpm")));
EXPECT_DOUBLE_EQ(130.0, ControlObject::get(ConfigKey(m_sGroup2, "bpm")));
EXPECT_DOUBLE_EQ(
0.2, ControlObject::get(ConfigKey(m_sGroup2, "beat_distance")));
EXPECT_DOUBLE_EQ(0.2,
ControlObject::get(
ConfigKey(m_sInternalClockGroup, "beat_distance")));
}
TEST_F(EngineSyncTest, MomentarySyncAlgorithmTwo) {
m_pConfig->set(ConfigKey("[BPM]", "sync_lock_algorithm"),
ConfigValue(EngineSync::PREFER_LOCK_BPM));
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(120));
m_pTrack1->trySetBeats(pBeats1);
mixxx::BeatsPointer pBeats2 = mixxx::Beats::fromConstTempo(
m_pTrack2->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(128));
m_pTrack2->trySetBeats(pBeats2);
ControlObject::getControl(ConfigKey(m_sGroup2, "play"))->set(1.0);
ProcessBuffer();
auto pButtonSyncEnabled1 =
std::make_unique<ControlProxy>(m_sGroup1, "sync_enabled");
pButtonSyncEnabled1->set(1.0);
pButtonSyncEnabled1->set(0.0);
ProcessBuffer();
EXPECT_DOUBLE_EQ(128.0, ControlObject::get(ConfigKey(m_sGroup1, "bpm")));
}
TEST_F(EngineSyncTest, EnableOneDeckInitializesLeader) {
// Enabling sync on a deck causes it to be leader, and sets bpm and clock.
// Set the deck to play.
mixxx::BeatsPointer pBeats1 = mixxx::Beats::fromConstTempo(
m_pTrack1->getSampleRate(), mixxx::audio::kStartFramePos, mixxx::Bpm(130));
m_pTrack1->trySetBeats(pBeats1);
ProcessBuffer();
ControlObject::getControl(ConfigKey(m_sGroup1, "rate"))
->set(getRateSliderValue(1.0));
ControlObject::getControl(ConfigKey(m_sGroup1, "beat_distance"))->set(0.2);