forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdlgprefmixer.cpp
More file actions
1222 lines (1082 loc) · 47.8 KB
/
Copy pathdlgprefmixer.cpp
File metadata and controls
1222 lines (1082 loc) · 47.8 KB
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 "preferences/dialog/dlgprefmixer.h"
#include <QButtonGroup>
#include <QPainterPath>
#include <QStandardItemModel>
#include "control/controlobject.h"
#include "control/controlproxy.h"
#include "defs_urls.h"
#include "effects/chains/equalizereffectchain.h"
#include "effects/chains/quickeffectchain.h"
#include "effects/effectknobparameterslot.h"
#include "effects/effectslot.h"
#include "effects/effectsmanager.h"
#include "effects/presets/effectchainpreset.h"
#include "engine/enginexfader.h"
#include "mixer/playermanager.h"
#include "moc_dlgprefmixer.cpp"
#include "util/math.h"
#include "util/rescaler.h"
namespace {
const QString kEffectForGroupPrefix = QStringLiteral("EffectForGroup_");
const QString kEffectGroupForMaster = QStringLiteral("EffectForGroup_[Master]");
const QString kMainEQParameterKey = QStringLiteral("EffectForGroup_[Master]_parameter");
const ConfigKey kEnableEqsKey = ConfigKey(kMixerProfile, QStringLiteral("EnableEQs"));
const ConfigKey kEqsOnlyKey = ConfigKey(kMixerProfile, QStringLiteral("EQsOnly"));
const ConfigKey kSingleEqKey = ConfigKey(kMixerProfile, QStringLiteral("SingleEQEffect"));
const ConfigKey kEqAutoResetKey = ConfigKey(kMixerProfile, QStringLiteral("EqAutoReset"));
const ConfigKey kGainAutoResetKey = ConfigKey(kMixerProfile, QStringLiteral("GainAutoReset"));
const QString kDefaultMainEqId = QString();
const ConfigKey kHighEqFreqKey = ConfigKey(kMixerProfile, kHighEqFrequency);
const ConfigKey kHighEqFreqPreciseKey =
ConfigKey(kMixerProfile, QStringLiteral("HiEQFrequencyPrecise"));
const ConfigKey kLowEqFreqKey = ConfigKey(kMixerProfile, kLowEqFrequency);
const ConfigKey kLowEqFreqPreciseKey =
ConfigKey(kMixerProfile, QStringLiteral("LoEQFrequencyPrecise"));
const ConfigKey kXfaderModeKey = ConfigKey(EngineXfader::kXfaderConfigKey,
QStringLiteral("xFaderMode"));
const ConfigKey kXfaderCurveKey = ConfigKey(EngineXfader::kXfaderConfigKey,
QStringLiteral("xFaderCurve"));
const ConfigKey kXfaderCalibrationKey = ConfigKey(EngineXfader::kXfaderConfigKey,
QStringLiteral("xFaderCalibration"));
const ConfigKey kXfaderReverseKey = ConfigKey(EngineXfader::kXfaderConfigKey,
QStringLiteral("xFaderReverse"));
constexpr int kFrequencyUpperLimit = 20050;
constexpr int kFrequencyLowerLimit = 16;
constexpr int kXfaderGridHLines = 3;
constexpr int kXfaderGridVLines = 5;
bool isMixingEQ(EffectManifest* pManifest) {
return pManifest->isMixingEQ();
}
bool isMainEQ(EffectManifest* pManifest) {
return pManifest->isMainEQ();
}
} // anonymous namespace
DlgPrefMixer::DlgPrefMixer(
QWidget* pParent,
std::shared_ptr<EffectsManager> pEffectsManager,
UserSettingsPointer pConfig)
: DlgPreferencePage(pParent),
m_pConfig(pConfig),
m_xFaderMode(MIXXX_XFADER_ADDITIVE),
m_transform(EngineXfader::kTransformDefault),
m_cal(0.0),
m_mode(kXfaderModeKey),
m_curve(kXfaderCurveKey),
m_calibration(kXfaderCalibrationKey),
m_reverse(kXfaderReverseKey),
m_crossfader("[Master]", "crossfader"),
m_xFaderReverse(false),
m_COLoFreq(kLowEqFreqKey),
m_COHiFreq(kHighEqFreqKey),
m_lowEqFreq(0.0),
m_highEqFreq(0.0),
m_pChainPresetManager(pEffectsManager->getChainPresetManager()),
m_pEffectsManager(pEffectsManager),
m_pBackendManager(pEffectsManager->getBackendManager()),
m_pNumDecks(make_parented<ControlProxy>(QStringLiteral("[App]"),
QStringLiteral("num_decks"),
this)),
m_ignoreEqQuickEffectBoxSignals(false),
m_singleEq(true),
m_eqEffectsOnly(true),
m_eqAutoReset(false),
m_gainAutoReset(false),
m_eqBypass(false),
m_initializing(true),
m_updatingMainEQ(false),
m_applyingDeckEQs(false),
m_applyingQuickEffects(false) {
setupUi(this);
// Update the crossfader curve graph and other settings when the
// crossfader mode is changed or the slider is moved.
connect(SliderXFader,
QOverload<int>::of(&QSlider::valueChanged),
this,
&DlgPrefMixer::slotUpdateXFader);
connect(SliderXFader, &QSlider::sliderMoved, this, &DlgPrefMixer::slotUpdateXFader);
connect(SliderXFader, &QSlider::sliderReleased, this, &DlgPrefMixer::slotUpdateXFader);
connect(radioButtonAdditive, &QRadioButton::clicked, this, &DlgPrefMixer::slotUpdateXFader);
connect(radioButtonConstantPower,
&QRadioButton::clicked,
this,
&DlgPrefMixer::slotUpdateXFader);
// Don't allow the xfader graph getting keyboard focus
graphicsViewXfader->setFocusPolicy(Qt::NoFocus);
// EQ shelf sliders
connect(SliderHiEQ, &QSlider::valueChanged, this, &DlgPrefMixer::slotHiEqSliderChanged);
connect(SliderHiEQ, &QSlider::sliderMoved, this, &DlgPrefMixer::slotHiEqSliderChanged);
connect(SliderHiEQ, &QSlider::sliderReleased, this, &DlgPrefMixer::slotHiEqSliderChanged);
connect(SliderLoEQ, &QSlider::valueChanged, this, &DlgPrefMixer::slotLoEqSliderChanged);
connect(SliderLoEQ, &QSlider::sliderMoved, this, &DlgPrefMixer::slotLoEqSliderChanged);
connect(SliderLoEQ, &QSlider::sliderReleased, this, &DlgPrefMixer::slotLoEqSliderChanged);
connect(CheckBoxEqAutoReset,
&QCheckBox::toggled,
this,
&DlgPrefMixer::slotEqAutoResetToggled);
connect(CheckBoxGainAutoReset,
&QCheckBox::toggled,
this,
&DlgPrefMixer::slotGainAutoResetToggled);
connect(CheckBoxBypass,
&QCheckBox::toggled,
this,
&DlgPrefMixer::slotBypassEqToggled);
connect(CheckBoxEqOnly,
&QCheckBox::toggled,
this,
&DlgPrefMixer::slotEqOnlyToggled);
connect(CheckBoxSingleEqEffect,
&QCheckBox::toggled,
this,
&DlgPrefMixer::slotSingleEqToggled);
// Update the QuickEffect selectors when the effect list was changed
// in Effects preferences
connect(m_pChainPresetManager.data(),
&EffectChainPresetManager::quickEffectChainPresetListUpdated,
this,
&DlgPrefMixer::slotPopulateQuickEffectSelectors);
setUpMainEQ();
// Update only after all settings are loaded, except EQs and QuickEffecs.
// slotNumDecksChanged() needs the correct state of 'Same EQ for all decks".
slotUpdate();
// Add drop down lists for current decks and connect to num_decks control
// so new lists are added if new decks are added.
m_pNumDecks->connectValueChanged(this, &DlgPrefMixer::slotNumDecksChanged);
slotNumDecksChanged(m_pNumDecks->get());
setScrollSafeGuard(SliderXFader);
setScrollSafeGuard(SliderHiEQ);
setScrollSafeGuard(SliderLoEQ);
setScrollSafeGuard(comboBoxMainEq);
// This applies the Main EQ and saves default values of previously missing
// ConfigKeys. EQ/QuickEffects are already applied by slotNumDecksChanged().
slotApply();
m_initializing = false;
}
// Create EQ & QuickEffect selectors and deck label for each added deck
void DlgPrefMixer::slotNumDecksChanged(double numDecks) {
while (m_deckEqEffectSelectors.size() < static_cast<int>(numDecks)) {
// 1-based for display
int deckNo = m_deckEqEffectSelectors.size() + 1;
// 0-based for engine
QString deckGroup = PlayerManager::groupForDeck(deckNo - 1);
auto pLabel = make_parented<QLabel>(QObject::tr("Deck %1").arg(deckNo), this);
// Create the EQ selector //////////////////////////////////////////////
auto pEqComboBox = make_parented<QComboBox>(this);
setScrollSafeGuard(pEqComboBox);
m_deckEqEffectSelectors.append(pEqComboBox);
// Migrate EQ from mixxx.cfg, add it to the combobox, remove keys
const ConfigKey groupKey =
ConfigKey(kMixerProfile, kEffectForGroupPrefix + deckGroup);
const QString configuredEffect = m_pConfig->getValueString(groupKey);
// If the EQ key doesn't exist (isNull()), we keeo the default EQ which
// has already been loaded by EffectsManager. Later on
// slotPopulateDeckEqSelectors() will read the effect, so nothing to do.
// Else, we use the uid from the config to load an EQ (or none).
bool loadEQ = false;
EffectManifestPointer pEqManifest;
if (!configuredEffect.isNull()) {
loadEQ = true;
pEqManifest = m_pBackendManager->getManifestFromUniqueId(configuredEffect);
// remove key so we migrate only once
m_pConfig->remove(groupKey);
}
auto pEqChain = m_pEffectsManager->getEqualizerEffectChain(deckGroup);
VERIFY_OR_DEBUG_ASSERT(pEqChain) {
return;
}
auto pEqEffectSlot = pEqChain->getEffectSlot(0);
VERIFY_OR_DEBUG_ASSERT(pEqEffectSlot) {
return;
}
if (loadEQ) {
pEqEffectSlot->loadEffectWithDefaults(pEqManifest);
}
connect(pEqComboBox,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&DlgPrefMixer::slotEQEffectSelectionChanged);
// Update the combobox in case the effect was changed from anywhere else.
// This will wipe pending EQ effect changes.
connect(pEqEffectSlot.data(),
&EffectSlot::effectChanged,
this,
&DlgPrefMixer::slotPopulateDeckEqSelectors);
// Create the QuickEffect selector /////////////////////////////////////
auto pQuickEffectComboBox = make_parented<QComboBox>(this);
setScrollSafeGuard(pQuickEffectComboBox);
m_deckQuickEffectSelectors.append(pQuickEffectComboBox);
connect(pQuickEffectComboBox,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&DlgPrefMixer::slotQuickEffectSelectionChanged);
// Update the combobox when the effect was changed in WEffectChainPresetSelector
// or with controllers. This will wipe pending QuickEffect changes.
EffectChainPointer pChain = m_pEffectsManager->getQuickEffectChain(deckGroup);
DEBUG_ASSERT(pChain);
connect(pChain.data(),
&EffectChain::chainPresetChanged,
this,
&DlgPrefMixer::slotPopulateQuickEffectSelectors);
// Add the new widgets
gridLayout_3->addWidget(pLabel, deckNo, 0);
gridLayout_3->addWidget(pEqComboBox, deckNo, 1);
gridLayout_3->addWidget(pQuickEffectComboBox, deckNo, 2);
gridLayout_3->addItem(
new QSpacerItem(
40, 1, QSizePolicy::Expanding, QSizePolicy::Minimum),
deckNo,
3,
1,
1);
}
// This also selects all currently loaded EQs and QuickEffects
slotPopulateDeckEqSelectors();
slotPopulateQuickEffectSelectors();
// Ensure all newly created but unneeded widgets are hidden
slotSingleEqToggled(m_singleEq);
}
void DlgPrefMixer::slotPopulateDeckEqSelectors() {
if (m_applyingDeckEQs) {
return;
}
m_ignoreEqQuickEffectBoxSignals = true; // prevents a recursive call
const QList<EffectManifestPointer> pManifestList = getDeckEqManifests();
for (int deck = 0; deck < m_deckEqEffectSelectors.size(); deck++) {
auto* pBox = m_deckEqEffectSelectors[deck];
// Populate comboboxes with all available effects
// Get currently loaded EQ effect
auto pChainSlot = m_pEffectsManager->getEqualizerEffectChain(
PlayerManager::groupForDeck(deck));
DEBUG_ASSERT(pChainSlot);
auto pEffectSlot = pChainSlot->getEffectSlot(0);
DEBUG_ASSERT(pEffectSlot);
const EffectManifestPointer pLoadedManifest =
pEffectSlot->getManifest();
pBox->clear();
// Add empty item at the top (no effect)
pBox->addItem(kNoEffectString);
int currentIndex = 0; // store it as default selection
for (const auto& pManifest : pManifestList) {
if (pManifest.isNull()) {
pBox->insertSeparator(pBox->count());
continue;
}
pBox->addItem(pManifest->displayName(), QVariant(pManifest->uniqueId()));
int i = pBox->count() - 1;
// <b> makes the effect name bold. Also, like <span> it serves as hack
// to get Qt to treat the string as rich text so it automatically wraps long lines.
pBox->setItemData(i,
QVariant(QStringLiteral("<b>%1</b><br/>%2")
.arg(pManifest->name(),
pManifest->description())),
Qt::ToolTipRole);
if (pLoadedManifest &&
pLoadedManifest.data() == pManifest.data()) {
currentIndex = i;
}
}
if (pLoadedManifest && currentIndex == 0) {
// Current selection is not part of the new list so we need to add it
pBox->addItem(pLoadedManifest->displayName(),
QVariant(pLoadedManifest->uniqueId()));
currentIndex = pBox->count() - 1;
pBox->setItemData(currentIndex,
QVariant(QStringLiteral("<b>%1</b><br/>%2")
.arg(pLoadedManifest->name(),
pLoadedManifest->description())),
Qt::ToolTipRole);
// Deactivate item to hopefully clarify the item is not an EQ
const QStandardItemModel* pModel =
qobject_cast<QStandardItemModel*>(pBox->model());
DEBUG_ASSERT(pModel);
auto* pItem = pModel->item(currentIndex);
DEBUG_ASSERT(pItem);
pItem->setEnabled(false);
}
pBox->setCurrentIndex(currentIndex);
}
m_ignoreEqQuickEffectBoxSignals = false;
}
void DlgPrefMixer::slotPopulateQuickEffectSelectors() {
if (m_applyingQuickEffects) {
return;
}
m_ignoreEqQuickEffectBoxSignals = true;
QList<EffectChainPresetPointer> presetList =
m_pChainPresetManager->getQuickEffectPresetsSorted();
for (int deck = 0; deck < m_deckQuickEffectSelectors.size(); deck++) {
auto* pBox = m_deckQuickEffectSelectors[deck];
pBox->clear();
int currentIndex = 0; // preselect empty item '---' as default
EffectChainPointer pChain = m_pEffectsManager->getQuickEffectChain(
PlayerManager::groupForDeck(deck));
DEBUG_ASSERT(pChain);
for (const auto& pChainPreset : presetList) {
pBox->addItem(pChainPreset->name());
if (pChain->presetName() == pChainPreset->name()) {
currentIndex = pBox->count() - 1;
}
}
pBox->setCurrentIndex(currentIndex);
}
m_ignoreEqQuickEffectBoxSignals = false;
}
void DlgPrefMixer::slotEqOnlyToggled(bool checked) {
m_eqEffectsOnly = checked;
slotPopulateDeckEqSelectors();
slotSingleEqToggled(m_singleEq);
}
void DlgPrefMixer::slotSingleEqToggled(bool checked) {
m_singleEq = checked;
if (m_deckEqEffectSelectors.isEmpty()) {
return;
}
// If single EQ is checked copy the EQ and QuickEffect of deck 1 to the other
// selectors. In case deck 1 has a non-EQ effect and 'EQs only' is checked we
// need to add it. Then disable EQ selectors except deck 1.
// Else enable all selectors and select currently loaded effects.
if (m_singleEq) {
m_ignoreEqQuickEffectBoxSignals = true;
const QString deck1EqId = m_deckEqEffectSelectors[0]->currentData().toString();
const EffectManifestPointer pManifest =
m_pBackendManager->getManifestFromUniqueId(deck1EqId);
int deck1QuickIndex = m_deckQuickEffectSelectors[0]->currentIndex();
for (int deck = 1; deck < m_deckEqEffectSelectors.size(); ++deck) {
// EQ //////////////////////////////////////////////////////////////
int newIndex = 0;
auto* eqBox = m_deckEqEffectSelectors[deck];
int foundIndex = eqBox->findData(deck1EqId);
if (foundIndex != -1) {
newIndex = foundIndex;
} else if (pManifest) {
// Current selection is not part of the new list so we need to add it
eqBox->addItem(pManifest->displayName(),
QVariant(pManifest->uniqueId()));
newIndex = eqBox->count() - 1;
eqBox->setItemData(newIndex,
QVariant(QStringLiteral("<b>%1</b><br/>%2")
.arg(pManifest->name(),
pManifest->description())),
Qt::ToolTipRole);
// Deactivate item to hopefully clarify the item is not an EQ
const QStandardItemModel* pModel =
qobject_cast<QStandardItemModel*>(eqBox->model());
DEBUG_ASSERT(pModel);
auto* pItem = pModel->item(newIndex);
DEBUG_ASSERT(pItem);
pItem->setEnabled(false);
}
eqBox->setCurrentIndex(newIndex);
eqBox->setDisabled(true);
// QUickEffect /////////////////////////////////////////////////////
auto* quickBox = m_deckQuickEffectSelectors[deck];
quickBox->setCurrentIndex(deck1QuickIndex);
quickBox->setDisabled(true);
}
m_ignoreEqQuickEffectBoxSignals = false;
} else {
for (int deck = 1; deck < m_deckEqEffectSelectors.size(); ++deck) {
auto* eqBox = m_deckEqEffectSelectors[deck];
eqBox->setEnabled(!m_eqBypass);
auto* quickBox = m_deckQuickEffectSelectors[deck];
quickBox->setEnabled(true);
}
slotPopulateDeckEqSelectors();
slotPopulateQuickEffectSelectors();
}
}
QUrl DlgPrefMixer::helpUrl() const {
return QUrl(MIXXX_MANUAL_EQ_URL);
}
void DlgPrefMixer::setDefaultShelves() {
SliderHiEQ->setValue(
getSliderPosition(2500,
SliderHiEQ->minimum(),
SliderHiEQ->maximum()));
SliderLoEQ->setValue(
getSliderPosition(250,
SliderLoEQ->minimum(),
SliderLoEQ->maximum()));
}
void DlgPrefMixer::slotResetToDefaults() {
double sliderVal = RescalerUtils::oneByXToLinear(
EngineXfader::kTransformDefault - EngineXfader::kTransformMin + 1,
EngineXfader::kTransformMax - EngineXfader::kTransformMin + 1,
SliderXFader->minimum(),
SliderXFader->maximum());
SliderXFader->setValue(static_cast<int>(std::round(sliderVal)));
m_xFaderMode = MIXXX_XFADER_ADDITIVE;
radioButtonAdditive->setChecked(true);
checkBoxReverse->setChecked(false);
// EQ & QuickEffects //////////////////////////////////
m_pEffectsManager->loadDefaultEqsAndQuickEffects();
CheckBoxBypass->setChecked(false);
CheckBoxEqOnly->setChecked(true);
CheckBoxSingleEqEffect->setChecked(true);
CheckBoxEqAutoReset->setChecked(false);
CheckBoxGainAutoReset->setChecked(false);
setDefaultShelves();
comboBoxMainEq->setCurrentIndex(0); // '---' no EQ
slotApply();
}
void DlgPrefMixer::slotEQEffectSelectionChanged(int effectIndex) {
Q_UNUSED(effectIndex);
QComboBox* c = qobject_cast<QComboBox*>(sender());
// Check if qobject_cast was successful
if (!c || m_ignoreEqQuickEffectBoxSignals) {
return;
}
// If we are in single-effect mode and the first effect was changed,
// change the others as well.
// TODO Fictional use case: when user changes EQ effect on a deck other than
// deck1 via direct chain controls, we may uncheck single EQ.
if (m_singleEq) {
slotSingleEqToggled(true);
}
}
void DlgPrefMixer::slotQuickEffectSelectionChanged(int effectIndex) {
Q_UNUSED(effectIndex);
QComboBox* c = qobject_cast<QComboBox*>(sender());
// Check if qobject_cast was successful
if (!c || m_ignoreEqQuickEffectBoxSignals) {
return;
}
// If we are in single-effect mode and the first effect was changed,
// change the others as well.
if (m_singleEq) {
slotSingleEqToggled(true);
}
}
void DlgPrefMixer::applyDeckEQs() {
m_applyingDeckEQs = true;
m_ignoreEqQuickEffectBoxSignals = true;
for (int deck = 0; deck < m_deckEqEffectSelectors.size(); deck++) {
auto* pBox = m_deckEqEffectSelectors[deck];
int effectIndex = pBox->currentIndex();
bool needLoad = true;
bool startingUp = m_eqIndiciesOnUpdate.size() < (deck + 1);
if (!startingUp) {
needLoad = effectIndex != m_eqIndiciesOnUpdate[deck];
}
auto pChainSlot = m_pEffectsManager->getEqualizerEffectChain(
PlayerManager::groupForDeck(deck));
DEBUG_ASSERT(pChainSlot);
auto pEffectSlot = pChainSlot->getEffectSlot(0);
DEBUG_ASSERT(pEffectSlot);
pEffectSlot->setEnabled(!m_eqBypass);
const EffectManifestPointer pManifest =
m_pBackendManager->getManifestFromUniqueId(
pBox->currentData().toString());
if (pManifest != nullptr && pManifest->isMixingEQ() && !m_eqBypass) {
pChainSlot->setFilterWaveform(true);
} else {
pChainSlot->setFilterWaveform(false);
}
if (needLoad) {
pEffectSlot->loadEffectWithDefaults(pManifest);
}
if (startingUp) {
m_eqIndiciesOnUpdate.append(effectIndex);
} else {
m_eqIndiciesOnUpdate[deck] = effectIndex;
}
}
m_ignoreEqQuickEffectBoxSignals = false;
m_applyingDeckEQs = false;
}
void DlgPrefMixer::applyQuickEffects() {
m_applyingQuickEffects = true;
m_ignoreEqQuickEffectBoxSignals = true;
for (int deck = 0; deck < m_deckQuickEffectSelectors.size(); deck++) {
auto* pBox = m_deckQuickEffectSelectors[deck];
int effectIndex = pBox->currentIndex();
bool needLoad = true;
bool startingUp = m_quickEffectIndiciesOnUpdate.size() < (deck + 1);
if (!startingUp) {
needLoad = effectIndex != m_quickEffectIndiciesOnUpdate[deck];
}
if (needLoad) {
EffectChainPointer pChain = m_pEffectsManager->getQuickEffectChain(
PlayerManager::groupForDeck(deck));
DEBUG_ASSERT(pChain);
const QList<EffectChainPresetPointer> presetList =
m_pChainPresetManager->getQuickEffectPresetsSorted();
if (effectIndex >= 0 && effectIndex < presetList.size()) {
pChain->loadChainPreset(presetList[effectIndex]);
}
}
if (startingUp) {
m_quickEffectIndiciesOnUpdate.append(effectIndex);
} else {
m_quickEffectIndiciesOnUpdate[deck] = effectIndex;
}
}
m_ignoreEqQuickEffectBoxSignals = false;
m_applyingQuickEffects = false;
}
void DlgPrefMixer::slotHiEqSliderChanged() {
if (SliderHiEQ->value() < SliderLoEQ->value()) {
SliderHiEQ->setValue(SliderLoEQ->value());
}
m_highEqFreq = getEqFreq(SliderHiEQ->value(),
SliderHiEQ->minimum(),
SliderHiEQ->maximum());
validateEQShelves();
if (m_highEqFreq < 1000) {
TextHiEQ->setText(QString("%1 Hz").arg(std::round(m_highEqFreq)));
} else {
TextHiEQ->setText(QString("%1 kHz").arg(std::round(m_highEqFreq) / 1000.));
}
m_COHiFreq.set(m_highEqFreq);
}
void DlgPrefMixer::slotLoEqSliderChanged() {
if (SliderLoEQ->value() > SliderHiEQ->value()) {
SliderLoEQ->setValue(SliderHiEQ->value());
}
m_lowEqFreq = getEqFreq(SliderLoEQ->value(),
SliderLoEQ->minimum(),
SliderLoEQ->maximum());
validateEQShelves();
if (m_lowEqFreq < 1000) {
TextLoEQ->setText(QString("%1 Hz").arg(std::round(m_lowEqFreq)));
} else {
TextLoEQ->setText(QString("%1 kHz").arg(std::round(m_lowEqFreq) / 1000.));
}
m_COLoFreq.set(m_lowEqFreq);
}
void DlgPrefMixer::slotMainEQParameterSliderChanged(int value) {
// Apply parameter, but don't write to config, yet, so Cancel will restore
// the saved state.
EffectSlotPointer pEffectSlot(m_pEffectMainEQ);
if (pEffectSlot.isNull()) {
return;
}
QSlider* pSlider = qobject_cast<QSlider*>(sender());
VERIFY_OR_DEBUG_ASSERT(pSlider) { // no slider, called from elsewhere
return;
}
// Update slider label
int index = m_mainEQSliders.indexOf(pSlider);
QLabel* pValueLabel = m_mainEQValues[index];
VERIFY_OR_DEBUG_ASSERT(pValueLabel) {
return;
}
// hide decimals for large ranges
if (pSlider->property("roundToInt").toBool()) {
pValueLabel->setText(QString::number(std::round(value / 100.0)));
} else {
pValueLabel->setText(QString::number(value / 100.0));
}
int paramIndex = pSlider->property("index").toInt();
auto pParameterSlot = pEffectSlot->getEffectParameterSlot(
EffectManifestParameter::ParameterType::Knob, paramIndex);
VERIFY_OR_DEBUG_ASSERT(pParameterSlot && pParameterSlot->isLoaded()) {
return;
}
// Calculate parameter value from relative slider position
int sValue = pSlider->value();
double paramValue = static_cast<double>(sValue - pSlider->minimum()) /
static_cast<double>(pSlider->maximum() - pSlider->minimum());
// Set the parameter
pParameterSlot->setParameter(paramValue);
}
int DlgPrefMixer::getSliderPosition(double eqFreq, int minValue, int maxValue) {
if (eqFreq >= kFrequencyUpperLimit) {
return maxValue;
} else if (eqFreq <= kFrequencyLowerLimit) {
return minValue;
}
double dsliderPos = (eqFreq - kFrequencyLowerLimit) /
(kFrequencyUpperLimit - kFrequencyLowerLimit);
dsliderPos = pow(dsliderPos, 1.0 / 4.0) * (maxValue - minValue) + minValue;
return static_cast<int>(std::round(dsliderPos));
}
void DlgPrefMixer::slotApply() {
// xfader //////////////////////////////////////////////////////////////////
m_mode.set(m_xFaderMode);
m_curve.set(m_transform);
m_calibration.set(m_cal);
if (checkBoxReverse->isChecked() != m_xFaderReverse) {
m_reverse.set(checkBoxReverse->isChecked());
double position = m_crossfader.get();
m_crossfader.set(0.0 - position);
m_xFaderReverse = checkBoxReverse->isChecked();
}
m_pConfig->set(kXfaderModeKey, ConfigValue(m_xFaderMode));
m_pConfig->set(kXfaderCurveKey, ConfigValue(QString::number(m_transform)));
m_pConfig->set(kXfaderReverseKey, ConfigValue(checkBoxReverse->isChecked() ? 1 : 0));
// EQ & QuickEffect settings ///////////////////////////////////////////////
m_pConfig->set(kEnableEqsKey, ConfigValue(m_eqBypass ? 0 : 1));
m_pConfig->set(kSingleEqKey, ConfigValue(m_singleEq ? 1 : 0));
m_pConfig->set(kEqsOnlyKey, ConfigValue(m_eqEffectsOnly ? 1 : 0));
m_pConfig->set(kEqAutoResetKey, ConfigValue(m_eqAutoReset ? 1 : 0));
m_pConfig->set(kGainAutoResetKey, ConfigValue(m_gainAutoReset ? 1 : 0));
applyDeckEQs();
applyQuickEffects();
storeEqShelves();
}
void DlgPrefMixer::storeEqShelves() {
if (m_initializing) {
return;
}
m_pConfig->set(kHighEqFreqPreciseKey, ConfigValue(QString::number(m_highEqFreq, 'f')));
m_pConfig->set(kLowEqFreqPreciseKey, ConfigValue(QString::number(m_lowEqFreq, 'f')));
}
// Update the widgets with values from config / EffectsManager
void DlgPrefMixer::slotUpdate() {
// xfader //////////////////////////////////////////////////////////////////
m_transform = m_pConfig->getValue(kXfaderCurveKey, EngineXfader::kTransformDefault);
// Range SliderXFader 0 .. 100
double sliderVal = RescalerUtils::oneByXToLinear(
m_transform - EngineXfader::kTransformMin + 1,
EngineXfader::kTransformMax - EngineXfader::kTransformMin + 1,
SliderXFader->minimum(),
SliderXFader->maximum());
SliderXFader->setValue(static_cast<int>(std::round(sliderVal)));
m_xFaderMode = m_pConfig->getValueString(kXfaderModeKey).toInt();
if (m_xFaderMode == MIXXX_XFADER_CONSTPWR) {
radioButtonConstantPower->setChecked(true);
} else {
radioButtonAdditive->setChecked(true);
}
m_xFaderReverse = m_pConfig->getValueString(kXfaderReverseKey).toInt() == 1;
checkBoxReverse->setChecked(m_xFaderReverse);
slotUpdateXFader();
// EQs & QuickEffects //////////////////////////////////////////////////////
QString eqsOnly = m_pConfig->getValueString(kEqsOnlyKey);
m_eqEffectsOnly = eqsOnly != "no" && eqsOnly != "0"; // default true
CheckBoxEqOnly->setChecked(m_eqEffectsOnly);
QString singleEqCfg = m_pConfig->getValueString(kSingleEqKey);
m_singleEq = singleEqCfg != "no" && singleEqCfg != "0"; // default true
if (!m_initializing) {
slotPopulateDeckEqSelectors();
slotPopulateQuickEffectSelectors();
}
if (m_initializing || CheckBoxSingleEqEffect->isChecked() != m_singleEq) {
CheckBoxSingleEqEffect->setChecked(m_singleEq);
slotSingleEqToggled(m_singleEq);
}
m_eqAutoReset = m_pConfig->getValue<bool>(kEqAutoResetKey, false);
CheckBoxEqAutoReset->setChecked(m_eqAutoReset);
m_gainAutoReset = m_pConfig->getValue<bool>(kGainAutoResetKey, false);
CheckBoxGainAutoReset->setChecked(m_gainAutoReset);
QString eqBaypassCfg = m_pConfig->getValueString(kEnableEqsKey);
m_eqBypass = !(eqBaypassCfg == "yes" || eqBaypassCfg == "1" || eqBaypassCfg.isEmpty());
CheckBoxBypass->setChecked(m_eqBypass);
// Deactivate EQ comboboxes when Bypass is enabled
slotBypassEqToggled(m_eqBypass);
// EQ shelves //////////////////////////////////////////////////////////////
QString highEqCoarse = m_pConfig->getValueString(kHighEqFreqKey);
QString highEqPrecise = m_pConfig->getValueString(kHighEqFreqPreciseKey);
QString lowEqCoarse = m_pConfig->getValueString(kLowEqFreqKey);
QString lowEqPrecise = m_pConfig->getValueString(kLowEqFreqPreciseKey);
double lowEqFreq = 0.0;
double highEqFreq = 0.0;
// Precise takes precedence over coarse.
lowEqFreq = lowEqCoarse.isEmpty() ? lowEqFreq : lowEqCoarse.toDouble();
lowEqFreq = lowEqPrecise.isEmpty() ? lowEqFreq : lowEqPrecise.toDouble();
highEqFreq = highEqCoarse.isEmpty() ? highEqFreq : highEqCoarse.toDouble();
highEqFreq = highEqPrecise.isEmpty() ? highEqFreq : highEqPrecise.toDouble();
if (lowEqFreq == 0.0 || highEqFreq == 0.0 || lowEqFreq == highEqFreq) {
setDefaultShelves();
} else {
SliderHiEQ->setValue(
getSliderPosition(highEqFreq,
SliderHiEQ->minimum(),
SliderHiEQ->maximum()));
SliderLoEQ->setValue(
getSliderPosition(lowEqFreq,
SliderLoEQ->minimum(),
SliderLoEQ->maximum()));
}
updateMainEQ();
}
// Draw the crossfader curve graph. Only needs to get drawn when a change
// has been made.
void DlgPrefMixer::drawXfaderDisplay() {
// Initialize or clear scene
if (m_pxfScene) {
m_pxfScene->clear();
} else {
m_pxfScene = make_parented<QGraphicsScene>(this);
// The size of the QGraphicsView doesn't change so we need to do this only once
graphicsViewXfader->setLineWidth(1); // frame width
int sizeX = graphicsViewXfader->width() - 2;
int sizeY = graphicsViewXfader->height() - 2;
m_pxfScene->setSceneRect(0, 0, sizeX, sizeY);
m_pxfScene->setBackgroundBrush(Qt::black);
graphicsViewXfader->setRenderHints(QPainter::Antialiasing);
graphicsViewXfader->setScene(m_pxfScene);
}
// Initialize QPens
QPen gridPen(Qt::darkGray);
QPen gainPen(Qt::white);
QPen totalPen(Qt::red);
// In conjunction with anti-aliasing this gives smooth, solid lines.
totalPen.setWidth(2);
gainPen.setWidth(2);
// For some reason grid lines also appear 2px wide, with the nice side effect
// that gain curves now intersect 'exactly'at the grid center line.
const int sceneW = static_cast<int>(m_pxfScene->width());
const int sceneH = static_cast<int>(m_pxfScene->height());
// Draw grid.
// Height is (grid segments * n)+1, so subtract 1 in order to get int coordinates.
const double kGridHDist = ((sceneH - 1) / (kXfaderGridHLines + 1));
const double kGridVDist = ((sceneW - 1) / (kXfaderGridVLines + 1));
for (int i = 1; i <= kXfaderGridHLines; i++) {
// Shift by .5 to trick anti-aliasing and get sharp lines (1px instead 2px)
const double y = (i * kGridHDist) + .5;
m_pxfScene->addLine(QLineF(0, y, sceneW, y), gridPen);
}
for (int i = 1; i <= kXfaderGridVLines; i++) {
const double x = (i * kGridVDist) + .5;
m_pxfScene->addLine(QLineF(x, 0, x, sceneH), gridPen);
}
// Draw gain curves
// Required to make the curves fit in the view, i.e. not drawn on the left/right edge
const int pointCount = sceneW - 2;
const int vOffset = 1;
const double xfadeStep = 2. / pointCount;
// Align the curves with first (top) horizontal gridline.
const double scaleFactorToAlignWithGrid = static_cast<double>(
kXfaderGridHLines) /
(kXfaderGridHLines + 1)
// Compensate for the added v-offset required to draw curves inside the view
// (not on the edge), especially the thicker, anti-aliased curves.
* (static_cast<double>(sceneH - vOffset) / (sceneH));
QPolygonF polylineTotal;
QPolygonF polylineL;
QPolygonF polylineR;
for (int x = 1; x <= pointCount + 1; x++) {
CSAMPLE_GAIN gainL, gainR;
EngineXfader::getXfadeGains((-1. + (xfadeStep * (x - 1))),
m_transform,
m_cal,
m_xFaderMode,
checkBoxReverse->isChecked(),
&gainL,
&gainR);
const double gainTotal = sqrt(gainL * gainL + gainR * gainR) * scaleFactorToAlignWithGrid;
const double gainLScaled = gainL * scaleFactorToAlignWithGrid;
const double gainRScaled = gainR * scaleFactorToAlignWithGrid;
polylineTotal.append(QPointF(x, (1. - gainTotal) * sceneH - 1));
polylineL.append(QPointF(x, (1. - gainLScaled) * sceneH - vOffset));
polylineR.append(QPointF(x, (1. - gainRScaled) * sceneH - vOffset));
}
QPainterPath pathTotal;
QPainterPath pathL;
QPainterPath pathR;
pathTotal.addPolygon(polylineTotal);
pathL.addPolygon(polylineL);
pathR.addPolygon(polylineR);
m_pxfScene->addPath(pathTotal, totalPen);
m_pxfScene->addPath(pathL, gainPen);
m_pxfScene->addPath(pathR, gainPen);
graphicsViewXfader->show();
graphicsViewXfader->repaint();
}
void DlgPrefMixer::slotUpdateXFader() {
if (radioButtonAdditive->isChecked()) {
m_xFaderMode = MIXXX_XFADER_ADDITIVE;
} else {
m_xFaderMode = MIXXX_XFADER_CONSTPWR;
}
// m_transform is in the range of 1 to 1000 while 50 % slider results
// to ~2, which represents a medium rounded fader curve.
double transform = RescalerUtils::linearToOneByX(
SliderXFader->value(),
SliderXFader->minimum(),
SliderXFader->maximum(),
EngineXfader::kTransformMax) -
1 + EngineXfader::kTransformMin;
// Round to 4 decimal places to avoid round-trip offsets with default 1.0
m_transform = std::round(transform * 10000) / 10000;
m_cal = EngineXfader::getPowerCalibration(m_transform);
drawXfaderDisplay();
}
void DlgPrefMixer::slotEqAutoResetToggled(bool checked) {
m_eqAutoReset = checked;
}
void DlgPrefMixer::slotGainAutoResetToggled(bool checked) {
m_gainAutoReset = checked;
}
void DlgPrefMixer::slotBypassEqToggled(bool checked) {
m_eqBypass = checked;
// De/activate deck EQ comboboxes
for (int deck = 0; deck < m_deckEqEffectSelectors.size(); deck++) {
auto* pBox = m_deckEqEffectSelectors[deck];
if (deck == 0) {
pBox->setEnabled(!m_eqBypass);
} else {
pBox->setEnabled(!m_eqBypass && !m_singleEq);
}
}
}
void DlgPrefMixer::setUpMainEQ() {
auto pChainSlot = m_pEffectsManager->getOutputEffectChain();
DEBUG_ASSERT(pChainSlot);
auto pEffectSlot = pChainSlot->getEffectSlot(0);
DEBUG_ASSERT(pEffectSlot);
m_pEffectMainEQ = pEffectSlot;
// Populate the effect combobox and connect widgets
const QList<EffectManifestPointer> availableMainEQEffects = getMainEqManifests();
// Add empty '---' item at the top
comboBoxMainEq->addItem(kNoEffectString);
for (const auto& pManifest : availableMainEQEffects) {
comboBoxMainEq->addItem(pManifest->name(), QVariant(pManifest->uniqueId()));
// <b> makes the effect name bold. Also, like <span> it serves as hack
// to get Qt to treat the string as rich text so it automatically wraps long lines.
comboBoxMainEq->setItemData(comboBoxMainEq->count() - 1,
QVariant(QStringLiteral("<b>%1</b><br/>%2")
.arg(pManifest->name(),
pManifest->description())),
Qt::ToolTipRole);
}
comboBoxMainEq->setCurrentIndex(0);
// slotMainEqEffectChanged() applies the effect immediately, so connect _after_
// setting the index to not override the current EffectsManager state.
connect(pbResetMainEq, &QPushButton::clicked, this, &DlgPrefMixer::slotMainEQToDefault);
connect(comboBoxMainEq,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&DlgPrefMixer::slotMainEqEffectChanged);
// Since 2.4 the main EQ is stored in effects.xml, so try to load settings
// from mixxx.cfg and apply immediately.
// If no settings were read, the state from EffectsManager is adopted when
// slotUpdate() is called later during initialization.
const QString configuredEffectId =
m_pConfig->getValueString(ConfigKey(kMixerProfile, kEffectGroupForMaster));
if (configuredEffectId.isNull() || configuredEffectId.isEmpty()) {
// Effect key doesn't exist or effect uid is empty. Nothing to do, keep
// the state loaded from effects.xml
// Remove all main EQ key residues
const QList<ConfigKey> mixerKeys = m_pConfig->getKeysWithGroup(kMixerProfile);
for (const auto& key : mixerKeys) {
if (key.item.contains(kEffectGroupForMaster)) {
m_pConfig->remove(key);
}
}
return;
}
const EffectManifestPointer configuredEffectManifest =
m_pBackendManager->getManifestFromUniqueId(configuredEffectId);
if (!configuredEffectManifest) {
return;
}
int configuredIndex = comboBoxMainEq->findData(configuredEffectManifest->uniqueId());
if (configuredIndex == -1) {
return;
}
// Set index and create required sliders and labels
comboBoxMainEq->setCurrentIndex(configuredIndex);
// Load parameters from preferences and set sliders
for (QSlider* pSlider : std::as_const(m_mainEQSliders)) {
int paramIndex = pSlider->property("index").toInt();
QString strValue = m_pConfig->getValueString(
ConfigKey(kMixerProfile,
kMainEQParameterKey + QString::number(paramIndex + 1)));
bool ok;
double paramValue = strValue.toDouble(&ok);
if (!ok) {