-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainComponent.cpp
More file actions
4607 lines (4083 loc) · 197 KB
/
MainComponent.cpp
File metadata and controls
4607 lines (4083 loc) · 197 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
// Super Timecode Converter
// Copyright (c) 2026 Fiverecords -- MIT License
// https://github.com/fiverecords/SuperTimecodeConverter
#include "MainComponent.h"
using InputSource = TimecodeEngine::InputSource;
//==============================================================================
// Remove " *" or " [Engine N]" markers from combo item text to get the
// underlying device name. Used when saving device names to settings.
//==============================================================================
static juce::String stripComboMarker(const juce::String& text)
{
static const juce::String dotSuffix = juce::String(" ") + juce::String::charToString(0x25CF);
auto s = text;
if (s.endsWith(dotSuffix))
s = s.dropLastCharacters(dotSuffix.length());
int bracket = s.lastIndexOf(" [");
if (bracket >= 0 && s.endsWith("]"))
s = s.substring(0, bracket);
return s.trimEnd();
}
//==============================================================================
// BACKGROUND AUDIO DEVICE SCANNER
//==============================================================================
MainComponent::AudioScanThread::AudioScanThread(MainComponent* owner)
: juce::Thread("AudioScanThread"), safeOwner(owner) {}
void MainComponent::AudioScanThread::run()
{
juce::Array<AudioDeviceEntry> inputs, outputs;
if (!tempManager)
return;
for (auto* type : tempManager->getAvailableDeviceTypes())
{
if (threadShouldExit()) return;
auto typeName = type->getTypeName();
type->scanForDevices();
for (auto& name : type->getDeviceNames(true))
inputs.add({ typeName, name, AudioDeviceEntry::makeDisplayName(typeName, name) });
for (auto& name : type->getDeviceNames(false))
outputs.add({ typeName, name, AudioDeviceEntry::makeDisplayName(typeName, name) });
}
juce::MessageManager::callAsync([safeOwner = this->safeOwner, inputs, outputs]()
{
if (auto* comp = safeOwner.getComponent())
comp->onAudioScanComplete(inputs, outputs);
});
}
//==============================================================================
// SAMPLE RATE / BUFFER SIZE helpers (same as v1.3)
//==============================================================================
static int sampleRateToComboId(double sr)
{
if (sr <= 0) return 1;
if (std::abs(sr - 44100) < 1) return 2;
if (std::abs(sr - 48000) < 1) return 3;
if (std::abs(sr - 88200) < 1) return 4;
if (std::abs(sr - 96000) < 1) return 5;
return 1;
}
static int bufferSizeToComboId(int bs)
{
if (bs <= 0) return 1;
if (bs <= 32) return 2;
if (bs <= 64) return 3;
if (bs <= 128) return 4;
if (bs <= 256) return 5;
if (bs <= 512) return 6;
if (bs <= 1024) return 7;
return 8;
}
//==============================================================================
// CONSTRUCTOR / DESTRUCTOR
//==============================================================================
MainComponent::MainComponent()
{
setLookAndFeel(&customLookAndFeel);
// --- Create initial engine BEFORE setSize, because setSize triggers
// resized() which calls currentEngine() ---
engines.push_back(std::make_unique<TimecodeEngine>(0));
engines[0]->setSharedProDJLinkInput(&sharedProDJLinkInput);
engines[0]->setDbServerClient(&sharedDbClient);
engines[0]->setTrackMap(&settings.trackMap);
engines[0]->setMixerMap(&sharedMixerMap);
setSize(900, 700);
setWantsKeyboardFocus(true); // enable Ctrl+D diagnostic shortcut
// --- Tab bar ---
addAndMakeVisible(btnAddEngine);
btnAddEngine.setColour(juce::TextButton::buttonColourId, juce::Colour(0xFF1A1D23));
btnAddEngine.setColour(juce::TextButton::textColourOffId, accentBlue);
btnAddEngine.onClick = [this] { addEngine(); };
rebuildTabButtons();
// --- Left panel scrollable viewport ---
addAndMakeVisible(leftViewport);
leftViewport.setViewedComponent(&leftContent, false);
leftViewport.setScrollBarsShown(true, false);
// --- Right panel scrollable viewport ---
addAndMakeVisible(rightViewport);
rightViewport.setViewedComponent(&rightContent, false);
rightViewport.setScrollBarsShown(true, false);
// --- Input buttons ---
for (auto* btn : { &btnMtcIn, &btnArtnetIn, &btnSysTime, &btnLtcIn, &btnProDJLinkIn })
{ leftContent.addAndMakeVisible(btn); btn->setClickingTogglesState(false); }
btnMtcIn.onClick = [this] {
if (syncing) return;
auto& eng = currentEngine();
if (eng.getActiveInput() == InputSource::MTC) { inputConfigExpanded = !inputConfigExpanded; updateDeviceSelectorVisibility(); }
else { inputConfigExpanded = true; eng.setInputSource(InputSource::MTC); startCurrentMtcInput(); updateInputButtonStates(); updateDeviceSelectorVisibility(); saveSettings(); }
};
btnArtnetIn.onClick = [this] {
if (syncing) return;
auto& eng = currentEngine();
if (eng.getActiveInput() == InputSource::ArtNet) { inputConfigExpanded = !inputConfigExpanded; updateDeviceSelectorVisibility(); }
else { inputConfigExpanded = true; eng.setInputSource(InputSource::ArtNet); startCurrentArtnetInput(); updateInputButtonStates(); updateDeviceSelectorVisibility(); saveSettings(); }
};
btnSysTime.onClick = [this] {
if (syncing) return;
auto& eng = currentEngine();
if (eng.getActiveInput() == InputSource::SystemTime) { inputConfigExpanded = !inputConfigExpanded; updateDeviceSelectorVisibility(); }
else { inputConfigExpanded = true; eng.setInputSource(InputSource::SystemTime); updateInputButtonStates(); updateDeviceSelectorVisibility(); saveSettings(); }
};
btnLtcIn.onClick = [this] {
if (syncing) return;
auto& eng = currentEngine();
if (eng.getActiveInput() == InputSource::LTC) { inputConfigExpanded = !inputConfigExpanded; updateDeviceSelectorVisibility(); }
else { inputConfigExpanded = true; eng.setInputSource(InputSource::LTC); if (!scannedAudioInputs.isEmpty()) startCurrentLtcInput(); updateInputButtonStates(); updateDeviceSelectorVisibility(); saveSettings(); }
};
btnProDJLinkIn.onClick = [this] {
if (syncing) return;
auto& eng = currentEngine();
if (eng.getActiveInput() == InputSource::ProDJLink) { inputConfigExpanded = !inputConfigExpanded; updateDeviceSelectorVisibility(); }
else { inputConfigExpanded = true; eng.setInputSource(InputSource::ProDJLink); startCurrentProDJLinkInput(); updateInputButtonStates(); updateDeviceSelectorVisibility(); saveSettings(); }
};
// --- Output toggles ---
for (auto* btn : { &btnMtcOut, &btnArtnetOut, &btnLtcOut, &btnThruOut })
rightContent.addAndMakeVisible(btn);
styleOutputToggle(btnMtcOut, accentRed);
styleOutputToggle(btnArtnetOut, accentOrange);
styleOutputToggle(btnLtcOut, accentPurple);
styleOutputToggle(btnThruOut, accentCyan);
auto outputToggleHandler = [this]
{
if (syncing) return;
auto& eng = currentEngine();
eng.setOutputMtcEnabled(btnMtcOut.getToggleState());
eng.setOutputArtnetEnabled(btnArtnetOut.getToggleState());
eng.setOutputLtcEnabled(btnLtcOut.getToggleState());
eng.setOutputThruEnabled(btnThruOut.getToggleState());
updateCurrentOutputStates();
updateDeviceSelectorVisibility();
saveSettings();
};
btnMtcOut.onClick = btnArtnetOut.onClick = btnLtcOut.onClick = btnThruOut.onClick = outputToggleHandler;
// --- Collapse toggle buttons for outputs ---
for (auto* btn : { &btnCollapseMtcOut, &btnCollapseArtnetOut, &btnCollapseLtcOut, &btnCollapseThruOut })
{
rightContent.addAndMakeVisible(btn);
styleCollapseButton(*btn);
}
auto makeCollapseHandler = [this](bool& expandedFlag, juce::TextButton& collapseBtn) {
return [this, &expandedFlag, &collapseBtn] {
expandedFlag = !expandedFlag;
updateCollapseButtonText(collapseBtn, expandedFlag);
updateDeviceSelectorVisibility();
};
};
btnCollapseMtcOut.onClick = makeCollapseHandler(mtcOutExpanded, btnCollapseMtcOut);
btnCollapseArtnetOut.onClick = makeCollapseHandler(artnetOutExpanded, btnCollapseArtnetOut);
btnCollapseLtcOut.onClick = makeCollapseHandler(ltcOutExpanded, btnCollapseLtcOut);
btnCollapseThruOut.onClick = makeCollapseHandler(thruOutExpanded, btnCollapseThruOut);
updateCollapseButtonText(btnCollapseMtcOut, mtcOutExpanded);
updateCollapseButtonText(btnCollapseArtnetOut, artnetOutExpanded);
updateCollapseButtonText(btnCollapseLtcOut, ltcOutExpanded);
updateCollapseButtonText(btnCollapseThruOut, thruOutExpanded);
// Input collapse button
leftContent.addAndMakeVisible(btnCollapseInput);
styleCollapseButton(btnCollapseInput);
btnCollapseInput.onClick = [this] {
inputConfigExpanded = !inputConfigExpanded;
updateCollapseButtonText(btnCollapseInput, inputConfigExpanded);
updateDeviceSelectorVisibility();
};
updateCollapseButtonText(btnCollapseInput, inputConfigExpanded);
// --- FPS buttons ---
for (auto* btn : { &btnFps2398, &btnFps24, &btnFps25, &btnFps2997, &btnFps30 })
{ addAndMakeVisible(btn); btn->setClickingTogglesState(false); }
btnFps2398.onClick = [this] {
if (syncing) return;
auto& eng = currentEngine();
if (eng.getActiveInput() == InputSource::LTC) eng.setUserOverrodeLtcFps(true);
eng.setFrameRate(FrameRate::FPS_2398); updateFpsButtonStates(); saveSettings();
};
btnFps24.onClick = [this] {
if (syncing) return;
currentEngine().setUserOverrodeLtcFps(false);
currentEngine().setFrameRate(FrameRate::FPS_24); updateFpsButtonStates(); saveSettings();
};
btnFps25.onClick = [this] {
if (syncing) return;
currentEngine().setUserOverrodeLtcFps(false);
currentEngine().setFrameRate(FrameRate::FPS_25); updateFpsButtonStates(); saveSettings();
};
btnFps2997.onClick = [this] {
if (syncing) return;
auto& eng = currentEngine();
if (eng.getActiveInput() == InputSource::LTC) eng.setUserOverrodeLtcFps(true);
eng.setFrameRate(FrameRate::FPS_2997); updateFpsButtonStates(); saveSettings();
};
btnFps30.onClick = [this] {
if (syncing) return;
currentEngine().setUserOverrodeLtcFps(false);
currentEngine().setFrameRate(FrameRate::FPS_30); updateFpsButtonStates(); saveSettings();
};
// --- FPS Conversion ---
addAndMakeVisible(btnFpsConvert);
styleOutputToggle(btnFpsConvert, accentGreen);
btnFpsConvert.onClick = [this]
{
if (syncing) return;
auto& eng = currentEngine();
eng.setFpsConvertEnabled(btnFpsConvert.getToggleState());
updateOutputFpsButtonStates();
resized(); repaint();
saveSettings();
};
for (auto* btn : { &btnOutFps2398, &btnOutFps24, &btnOutFps25, &btnOutFps2997, &btnOutFps30 })
{ addAndMakeVisible(btn); btn->setClickingTogglesState(false); }
btnOutFps2398.onClick = [this] { if (!syncing) { currentEngine().setOutputFrameRate(FrameRate::FPS_2398); updateOutputFpsButtonStates(); saveSettings(); } };
btnOutFps24.onClick = [this] { if (!syncing) { currentEngine().setOutputFrameRate(FrameRate::FPS_24); updateOutputFpsButtonStates(); saveSettings(); } };
btnOutFps25.onClick = [this] { if (!syncing) { currentEngine().setOutputFrameRate(FrameRate::FPS_25); updateOutputFpsButtonStates(); saveSettings(); } };
btnOutFps2997.onClick = [this] { if (!syncing) { currentEngine().setOutputFrameRate(FrameRate::FPS_2997); updateOutputFpsButtonStates(); saveSettings(); } };
btnOutFps30.onClick = [this] { if (!syncing) { currentEngine().setOutputFrameRate(FrameRate::FPS_30); updateOutputFpsButtonStates(); saveSettings(); } };
addAndMakeVisible(timecodeDisplay);
// =====================================================================
// LEFT PANEL -- INPUT SELECTORS
// =====================================================================
auto addLabelAndCombo = [this](juce::Label& lbl, juce::ComboBox& cmb, const juce::String& text)
{
leftContent.addAndMakeVisible(lbl); leftContent.addAndMakeVisible(cmb);
lbl.setText(text, juce::dontSendNotification);
styleLabel(lbl); styleComboBox(cmb);
};
auto addRightLabelAndCombo = [this](juce::Label& lbl, juce::ComboBox& cmb, const juce::String& text)
{
rightContent.addAndMakeVisible(lbl); rightContent.addAndMakeVisible(cmb);
lbl.setText(text, juce::dontSendNotification);
styleLabel(lbl); styleComboBox(cmb);
};
addLabelAndCombo(lblAudioInputTypeFilter, cmbAudioInputTypeFilter, "AUDIO DRIVER:");
cmbAudioInputTypeFilter.onChange = [this]
{
if (syncing) return;
populateFilteredInputDeviceCombo();
if (currentEngine().getActiveInput() == InputSource::LTC)
startCurrentLtcInput();
saveSettings();
};
addLabelAndCombo(lblSampleRate, cmbSampleRate, "SAMPLE RATE / BUFFER:");
populateSampleRateCombo();
cmbSampleRate.onChange = [this] { if (!syncing) { restartAllAudioDevices(); saveSettings(); } };
addLabelAndCombo(lblBufferSize, cmbBufferSize, "BUFFER SIZE:");
populateBufferSizeCombo();
cmbBufferSize.onChange = [this] { if (!syncing) { restartAllAudioDevices(); saveSettings(); } };
addLabelAndCombo(lblMidiInputDevice, cmbMidiInputDevice, "MIDI INPUT DEVICE:");
cmbMidiInputDevice.onChange = [this]
{
if (syncing) return;
int sel = cmbMidiInputDevice.getSelectedId() - 1;
if (sel >= 0 && currentEngine().getActiveInput() == InputSource::MTC)
{
currentEngine().stopMtcInput();
currentEngine().getMtcInput().refreshDeviceList();
currentEngine().startMtcInput(sel);
populateMidiAndNetworkCombos(); // refresh markers (auto-restores selections)
saveSettings();
}
};
addLabelAndCombo(lblArtnetInputInterface, cmbArtnetInputInterface, "ART-NET INPUT DEVICE:");
cmbArtnetInputInterface.onChange = [this]
{
if (syncing) return;
if (currentEngine().getActiveInput() == InputSource::ArtNet)
{
int sel = cmbArtnetInputInterface.getSelectedId() - 1;
currentEngine().stopArtnetInput();
currentEngine().startArtnetInput(sel);
// If bind fell back, update combo to actual interface before repopulate
int actualId = currentEngine().getArtnetInput().getSelectedInterface() + 1;
cmbArtnetInputInterface.setSelectedId(actualId, juce::dontSendNotification);
populateMidiAndNetworkCombos(); // refresh markers (auto-restores all selections)
saveSettings();
}
};
// --- Pro DJ Link controls ---
addLabelAndCombo(lblProDJLinkInterface, cmbProDJLinkInterface, "PRO DJ LINK INTERFACE:");
cmbProDJLinkInterface.onChange = [this]
{
if (syncing) return;
if (currentEngine().getActiveInput() == InputSource::ProDJLink)
{
startCurrentProDJLinkInput();
saveSettings();
}
};
addLabelAndCombo(lblProDJLinkPlayer, cmbProDJLinkPlayer, "PLAYER:");
for (int i = 1; i <= ProDJLink::kMaxPlayers; ++i)
cmbProDJLinkPlayer.addItem("PLAYER " + juce::String(i), i);
cmbProDJLinkPlayer.addItem("XF-A", 7);
cmbProDJLinkPlayer.addItem("XF-B", 8);
cmbProDJLinkPlayer.setSelectedId(1, juce::dontSendNotification);
cmbProDJLinkPlayer.onChange = [this]
{
if (syncing) return;
if (currentEngine().getActiveInput() == InputSource::ProDJLink)
{
int player = cmbProDJLinkPlayer.getSelectedId();
if (player >= 1)
{
currentEngine().setProDJLinkPlayer(player);
// Reset UI display so stale data from previous player doesn't linger
displayedArtworkId = 0;
artworkDisplay.clearImage();
displayedWaveformTrackId = 0;
waveformDisplay.clearWaveform();
lblProDJLinkTrackInfo.setText("", juce::dontSendNotification);
lblProDJLinkMetadata.setText("", juce::dontSendNotification);
}
saveSettings();
}
};
leftContent.addAndMakeVisible(lblProDJLinkMetadata);
styleLabel(lblProDJLinkMetadata, 9.0f);
lblProDJLinkMetadata.setVisible(false);
leftContent.addAndMakeVisible(lblMixerStatus);
lblMixerStatus.setFont(juce::Font(juce::FontOptions(juce::Font::getDefaultMonospacedFontName(), 9.0f, juce::Font::plain)));
lblMixerStatus.setColour(juce::Label::textColourId, juce::Colour(0xFF888888));
lblMixerStatus.setVisible(false);
leftContent.addAndMakeVisible(artworkDisplay);
artworkDisplay.setVisible(false);
leftContent.addAndMakeVisible(waveformDisplay);
waveformDisplay.setVisible(false);
leftContent.addAndMakeVisible(lblProDJLinkTrackInfo);
styleLabel(lblProDJLinkTrackInfo, 8.0f);
lblProDJLinkTrackInfo.setVisible(false);
// --- ProDJLink features: TrackMap, MIDI Clock, OSC BPM, Ableton Link ---
auto pdlAccent = juce::Colour(0xFF00AAFF);
leftContent.addAndMakeVisible(btnTrackMap);
btnTrackMap.setVisible(false);
btnTrackMap.setColour(juce::ToggleButton::textColourId, textMid);
btnTrackMap.setColour(juce::ToggleButton::tickColourId, pdlAccent);
btnTrackMap.onClick = [this]
{
if (syncing) return;
currentEngine().setTrackMapEnabled(btnTrackMap.getToggleState());
updateDeviceSelectorVisibility();
saveSettings();
};
leftContent.addAndMakeVisible(btnTrackMapEdit);
btnTrackMapEdit.setVisible(false);
btnTrackMapEdit.setColour(juce::TextButton::buttonColourId, pdlAccent.withAlpha(0.15f));
btnTrackMapEdit.setColour(juce::TextButton::textColourOffId, pdlAccent.brighter(0.3f));
btnTrackMapEdit.onClick = [this] { openTrackMapEditor(); };
leftContent.addAndMakeVisible(btnProDJLinkView);
btnProDJLinkView.setVisible(false);
btnProDJLinkView.setColour(juce::TextButton::buttonColourId, pdlAccent.withAlpha(0.15f));
btnProDJLinkView.setColour(juce::TextButton::textColourOffId, pdlAccent.brighter(0.3f));
btnProDJLinkView.onClick = [this] { openProDJLinkView(); };
leftContent.addAndMakeVisible(btnMixerMapEdit);
btnMixerMapEdit.setVisible(false);
btnMixerMapEdit.setColour(juce::TextButton::buttonColourId, pdlAccent.withAlpha(0.15f));
btnMixerMapEdit.setColour(juce::TextButton::textColourOffId, pdlAccent.brighter(0.3f));
btnMixerMapEdit.onClick = [this] { openMixerMapEditor(); };
addAndMakeVisible(btnBackup);
btnBackup.setColour(juce::TextButton::buttonColourId, juce::Colour(0xFF1A1D23));
btnBackup.setColour(juce::TextButton::textColourOffId, juce::Colour(0xFF66CC66));
btnBackup.onClick = [this] { exportConfig(); };
addAndMakeVisible(btnRestore);
btnRestore.setColour(juce::TextButton::buttonColourId, juce::Colour(0xFF1A1D23));
btnRestore.setColour(juce::TextButton::textColourOffId, juce::Colour(0xFFFF9966));
btnRestore.onClick = [this] { importConfig(); };
leftContent.addAndMakeVisible(btnMidiClock);
btnMidiClock.setVisible(false);
btnMidiClock.setColour(juce::ToggleButton::textColourId, textMid);
btnMidiClock.setColour(juce::ToggleButton::tickColourId, pdlAccent);
btnMidiClock.onClick = [this]
{
if (syncing) return;
bool wantClock = btnMidiClock.getToggleState();
currentEngine().setMidiClockEnabled(wantClock); // set flag (clock may not start yet if device not open)
applyTriggerSettings(); // ensure MIDI device is opened/closed based on needs
if (wantClock)
currentEngine().setMidiClockEnabled(true); // re-try now that device is open
propagateGlobalSettings();
updateDeviceSelectorVisibility();
saveSettings();
};
leftContent.addAndMakeVisible(btnOscFwdBpm);
btnOscFwdBpm.setVisible(false);
btnOscFwdBpm.setColour(juce::ToggleButton::textColourId, textMid);
btnOscFwdBpm.setColour(juce::ToggleButton::tickColourId, pdlAccent);
btnOscFwdBpm.onClick = [this]
{
if (syncing) return;
currentEngine().setOscForward(btnOscFwdBpm.getToggleState(), edOscFwdBpmAddr.getText());
applyTriggerSettings(); // ensure OSC connection is opened/closed
propagateGlobalSettings();
updateDeviceSelectorVisibility();
saveSettings();
};
leftContent.addAndMakeVisible(lblOscFwdBpmAddr);
lblOscFwdBpmAddr.setText("Addr:", juce::dontSendNotification);
lblOscFwdBpmAddr.setFont(juce::Font(juce::FontOptions(10.0f)));
lblOscFwdBpmAddr.setColour(juce::Label::textColourId, textDim);
lblOscFwdBpmAddr.setVisible(false);
leftContent.addAndMakeVisible(edOscFwdBpmAddr);
edOscFwdBpmAddr.setVisible(false);
edOscFwdBpmAddr.setText("/composition/tempocontroller/tempo");
edOscFwdBpmAddr.setFont(juce::Font(juce::FontOptions(10.0f)));
edOscFwdBpmAddr.setColour(juce::TextEditor::backgroundColourId, juce::Colour(0xFF2A2A2A));
edOscFwdBpmAddr.setColour(juce::TextEditor::textColourId, textLight);
edOscFwdBpmAddr.setColour(juce::TextEditor::outlineColourId, juce::Colour(0xFF444444));
edOscFwdBpmAddr.onReturnKey = [this]
{
if (!syncing) { currentEngine().setOscForward(btnOscFwdBpm.getToggleState(), edOscFwdBpmAddr.getText()); propagateGlobalSettings(); saveSettings(); }
};
edOscFwdBpmAddr.onFocusLost = [this]
{
if (!syncing) { currentEngine().setOscForward(btnOscFwdBpm.getToggleState(), edOscFwdBpmAddr.getText()); propagateGlobalSettings(); saveSettings(); }
};
leftContent.addAndMakeVisible(btnOscMixerFwd);
btnOscMixerFwd.setVisible(false);
btnOscMixerFwd.setColour(juce::ToggleButton::textColourId, textMid);
btnOscMixerFwd.setColour(juce::ToggleButton::tickColourId, pdlAccent);
btnOscMixerFwd.onClick = [this]
{
currentEngine().setOscMixerForward(btnOscMixerFwd.getToggleState());
applyTriggerSettings();
propagateGlobalSettings();
saveSettings();
};
leftContent.addAndMakeVisible(btnMidiMixerFwd);
btnMidiMixerFwd.setVisible(false);
btnMidiMixerFwd.setColour(juce::ToggleButton::textColourId, textMid);
btnMidiMixerFwd.setColour(juce::ToggleButton::tickColourId, pdlAccent);
btnMidiMixerFwd.onClick = [this]
{
currentEngine().setMidiMixerForward(btnMidiMixerFwd.getToggleState(),
cmbMidiMixCCCh.getSelectedId(),
cmbMidiMixNoteCh.getSelectedId());
applyTriggerSettings();
propagateGlobalSettings();
updateDeviceSelectorVisibility();
saveSettings();
};
auto setupMidiChCombo = [this](juce::ComboBox& cmb, juce::Label& lbl, const juce::String& labelText)
{
leftContent.addAndMakeVisible(lbl);
lbl.setVisible(false);
lbl.setText(labelText, juce::dontSendNotification);
lbl.setFont(juce::Font(juce::FontOptions(10.0f)));
lbl.setColour(juce::Label::textColourId, textDim);
leftContent.addAndMakeVisible(cmb);
cmb.setVisible(false);
for (int ch = 1; ch <= 16; ++ch)
cmb.addItem("Ch " + juce::String(ch), ch);
cmb.setSelectedId(1, juce::dontSendNotification);
styleComboBox(cmb);
cmb.onChange = [this]
{
currentEngine().setMidiMixerForward(btnMidiMixerFwd.getToggleState(),
cmbMidiMixCCCh.getSelectedId(),
cmbMidiMixNoteCh.getSelectedId());
propagateGlobalSettings();
saveSettings();
};
};
setupMidiChCombo(cmbMidiMixCCCh, lblMidiMixCCCh, "CC CH:");
setupMidiChCombo(cmbMidiMixNoteCh, lblMidiMixNoteCh, "NOTE CH:");
leftContent.addAndMakeVisible(btnArtnetMixerFwd);
btnArtnetMixerFwd.setVisible(false);
btnArtnetMixerFwd.setColour(juce::ToggleButton::textColourId, textMid);
btnArtnetMixerFwd.setColour(juce::ToggleButton::tickColourId, pdlAccent);
btnArtnetMixerFwd.onClick = [this]
{
currentEngine().setArtnetMixerForward(btnArtnetMixerFwd.getToggleState(),
getArtNetAddressFromCombos(cmbArtMixNet, cmbArtMixSub, cmbArtMixUni));
// Ensure ArtNet output is running -- DMX uses the same socket.
// If ArtNet timecode out is already running, this is a no-op.
if (btnArtnetMixerFwd.getToggleState() && !currentEngine().getArtnetOutput().getIsRunning())
{
int iface = cmbArtnetDmxInterface.getSelectedId() - 2; // -1=All, 0+=NIC
currentEngine().startArtnetOutput(iface);
}
propagateGlobalSettings();
updateDeviceSelectorVisibility();
saveSettings();
};
setupArtNetAddressCombos(cmbArtMixNet, cmbArtMixSub, cmbArtMixUni, lblArtMixAddr,
"MIXER:", [this]
{
currentEngine().setArtnetMixerForward(btnArtnetMixerFwd.getToggleState(),
getArtNetAddressFromCombos(cmbArtMixNet, cmbArtMixSub, cmbArtMixUni));
propagateGlobalSettings();
saveSettings();
});
leftContent.addAndMakeVisible(btnLink);
btnLink.setVisible(false);
btnLink.setColour(juce::ToggleButton::textColourId, textMid);
btnLink.setColour(juce::ToggleButton::tickColourId, pdlAccent);
btnLink.onClick = [this]
{
if (syncing) return;
currentEngine().getLinkBridge().setEnabled(btnLink.getToggleState());
propagateGlobalSettings();
updateDeviceSelectorVisibility();
saveSettings();
};
leftContent.addAndMakeVisible(lblLinkStatus);
lblLinkStatus.setVisible(false);
lblLinkStatus.setFont(juce::Font(juce::FontOptions(10.0f)));
lblLinkStatus.setColour(juce::Label::textColourId, textMid);
lblLinkStatus.setJustificationType(juce::Justification::centredLeft);
// --- BPM Multiplier buttons (per-player, ProDJLink only) ---
// Single click: session override (temporary). Double click: save to TrackMap (persistent).
{
auto setupBpmBtn = [this, pdlAccent](juce::TextButton& btn, int mult)
{
leftContent.addAndMakeVisible(btn);
btn.setVisible(false);
btn.setColour(juce::TextButton::buttonColourId, bgPanel);
btn.setColour(juce::TextButton::textColourOffId, textMid);
btn.setColour(juce::TextButton::buttonOnColourId, pdlAccent.withAlpha(0.30f));
btn.setColour(juce::TextButton::textColourOnId, pdlAccent.brighter(0.3f));
btn.setClickingTogglesState(false);
btn.onClick = [this, mult]
{
if (syncing) return;
auto now = (juce::int64)juce::Time::getMillisecondCounter();
bool isDouble = (mult == lastBpmClickMult
&& (now - lastBpmClickMs) < 400);
lastBpmClickMs = now;
lastBpmClickMult = mult;
if (isDouble)
{
// Double click: persist to TrackMap (toggle)
saveBpmMultToTrackMap(mult);
}
else
{
// Single click: set session override (skip if already effective)
auto& eng = currentEngine();
if (eng.getEffectiveBpmMultiplier() != mult)
eng.setBpmPlayerOverride(mult);
}
updateBpmMultButtonStates();
};
};
setupBpmBtn(btnBpmOff, 0);
setupBpmBtn(btnBpmX2, 1);
setupBpmBtn(btnBpmX4, 2);
setupBpmBtn(btnBpmD2, -1);
setupBpmBtn(btnBpmD4, -2);
}
// --- Track change trigger controls ---
auto accentAmber = juce::Colour(0xFFFFAB00);
leftContent.addAndMakeVisible(btnTriggerMidi);
btnTriggerMidi.setVisible(false);
btnTriggerMidi.setColour(juce::ToggleButton::textColourId, textMid);
btnTriggerMidi.setColour(juce::ToggleButton::tickColourId, accentAmber);
btnTriggerMidi.onClick = [this]
{
if (syncing) return;
applyTriggerSettings();
saveSettings();
};
leftContent.addAndMakeVisible(cmbTriggerMidiDevice);
cmbTriggerMidiDevice.setVisible(false);
styleComboBox(cmbTriggerMidiDevice);
cmbTriggerMidiDevice.onChange = [this]
{
if (syncing) return;
applyTriggerSettings();
saveSettings();
};
leftContent.addAndMakeVisible(btnTriggerOsc);
btnTriggerOsc.setVisible(false);
btnTriggerOsc.setColour(juce::ToggleButton::textColourId, textMid);
btnTriggerOsc.setColour(juce::ToggleButton::tickColourId, accentAmber);
btnTriggerOsc.onClick = [this]
{
if (syncing) return;
applyTriggerSettings();
saveSettings();
};
leftContent.addAndMakeVisible(edOscIp);
edOscIp.setVisible(false);
edOscIp.setFont(juce::Font(juce::FontOptions(10.0f)));
edOscIp.setColour(juce::TextEditor::backgroundColourId, bgDarker);
edOscIp.setColour(juce::TextEditor::textColourId, textBright);
edOscIp.setColour(juce::TextEditor::outlineColourId, borderCol);
edOscIp.setTextToShowWhenEmpty("127.0.0.1", textDim);
edOscIp.onFocusLost = [this] { applyTriggerSettings(); saveSettings(); };
edOscIp.onReturnKey = [this] { applyTriggerSettings(); saveSettings(); };
leftContent.addAndMakeVisible(edOscPort);
edOscPort.setVisible(false);
edOscPort.setFont(juce::Font(juce::FontOptions(10.0f)));
edOscPort.setColour(juce::TextEditor::backgroundColourId, bgDarker);
edOscPort.setColour(juce::TextEditor::textColourId, textBright);
edOscPort.setColour(juce::TextEditor::outlineColourId, borderCol);
edOscPort.setTextToShowWhenEmpty("53000", textDim);
edOscPort.setInputRestrictions(5, "0123456789");
edOscPort.onFocusLost = [this] { applyTriggerSettings(); saveSettings(); };
edOscPort.onReturnKey = [this] { applyTriggerSettings(); saveSettings(); };
leftContent.addAndMakeVisible(btnArtnetTrigger);
btnArtnetTrigger.setVisible(false);
btnArtnetTrigger.setColour(juce::ToggleButton::textColourId, textMid);
btnArtnetTrigger.setColour(juce::ToggleButton::tickColourId, accentAmber);
btnArtnetTrigger.onClick = [this]
{
if (syncing) return;
currentEngine().setArtnetTriggerEnabled(btnArtnetTrigger.getToggleState());
// Ensure ArtNet output is running if enabled
if (btnArtnetTrigger.getToggleState() && !currentEngine().getArtnetOutput().getIsRunning())
{
int iface = cmbArtnetDmxInterface.getSelectedId() - 2; // -1=All, 0+=NIC
currentEngine().startArtnetOutput(iface);
}
updateDeviceSelectorVisibility();
saveSettings();
};
setupArtNetAddressCombos(cmbArtTrigNet, cmbArtTrigSub, cmbArtTrigUni, lblArtTrigAddr,
"TRIGGER:", [this]
{
currentEngine().setArtnetTriggerUniverse(getArtNetAddressFromCombos(cmbArtTrigNet, cmbArtTrigSub, cmbArtTrigUni));
saveSettings();
});
// Default universe 1 (Net=0, Sub=0, Uni=1)
cmbArtTrigUni.setSelectedId(2, juce::dontSendNotification);
// Art-Net DMX interface selector (for triggers and mixer forward)
addLabelAndCombo(lblArtnetDmxInterface, cmbArtnetDmxInterface, "ART-NET DMX INTERFACE:");
cmbArtnetDmxInterface.onChange = [this]
{
if (syncing) return;
auto& eng = currentEngine();
bool needsArtnet = eng.isArtnetMixerForwardEnabled() || eng.isArtnetTriggerEnabled();
if (needsArtnet)
{
int sel = cmbArtnetDmxInterface.getSelectedId() - 2; // -1=All, 0+=NIC
// Restart ArtnetOutput on the new interface (only if timecode output isn't controlling it)
if (!eng.isOutputArtnetEnabled() || !eng.getArtnetOutput().getIsRunning())
eng.startArtnetOutput(sel);
}
saveSettings();
};
addLabelAndCombo(lblAudioInputDevice, cmbAudioInputDevice, "AUDIO INPUT DEVICE:");
cmbAudioInputDevice.onChange = [this]
{
if (syncing) return;
if (currentEngine().getActiveInput() == InputSource::LTC
&& cmbAudioInputDevice.getSelectedId() > 0
&& cmbAudioInputDevice.getSelectedId() != kPlaceholderItemId)
{
startCurrentLtcInput();
populateFilteredInputDeviceCombo(); // refresh markers (auto-restores selection)
populateAudioInputChannels();
saveSettings();
}
};
addLabelAndCombo(lblAudioInputChannel, cmbAudioInputChannel, "LTC CHANNEL:");
cmbAudioInputChannel.onChange = [this] { if (!syncing && currentEngine().getActiveInput() == InputSource::LTC) { startCurrentLtcInput(); saveSettings(); } };
leftContent.addAndMakeVisible(sldLtcInputGain); styleGainSlider(sldLtcInputGain);
leftContent.addAndMakeVisible(lblLtcInputGain); lblLtcInputGain.setText("LTC INPUT GAIN:", juce::dontSendNotification); styleLabel(lblLtcInputGain);
leftContent.addAndMakeVisible(mtrLtcInput); mtrLtcInput.setMeterColour(accentPurple);
sldLtcInputGain.onValueChange = [this] { if (!syncing) { currentEngine().getLtcInput().setInputGain((float)sldLtcInputGain.getValue() / 100.0f); saveSettings(); } };
addLabelAndCombo(lblThruInputChannel, cmbThruInputChannel, "AUDIO THRU CHANNEL:");
cmbThruInputChannel.onChange = [this] { if (!syncing && currentEngine().getActiveInput() == InputSource::LTC) { startCurrentLtcInput(); saveSettings(); } };
leftContent.addAndMakeVisible(sldThruInputGain); styleGainSlider(sldThruInputGain);
leftContent.addAndMakeVisible(lblThruInputGain); lblThruInputGain.setText("AUDIO THRU INPUT GAIN:", juce::dontSendNotification); styleLabel(lblThruInputGain);
leftContent.addAndMakeVisible(mtrThruInput); mtrThruInput.setMeterColour(accentCyan);
sldThruInputGain.onValueChange = [this] { if (!syncing) { currentEngine().getLtcInput().setPassthruGain((float)sldThruInputGain.getValue() / 100.0f); saveSettings(); } };
leftContent.addAndMakeVisible(lblInputStatus); styleLabel(lblInputStatus); lblInputStatus.setColour(juce::Label::textColourId, accentGreen);
// =====================================================================
// RIGHT PANEL -- OUTPUT SELECTORS
// =====================================================================
addRightLabelAndCombo(lblMidiOutputDevice, cmbMidiOutputDevice, "MIDI OUTPUT DEVICE:");
cmbMidiOutputDevice.onChange = [this]
{
if (syncing) return;
int sel = cmbMidiOutputDevice.getSelectedId() - 1;
auto& eng = currentEngine();
if (sel >= 0 && eng.isOutputMtcEnabled())
{
// Clear sharing before stopping old MTC device
eng.getTriggerOutput().setSharedMidiOutput(nullptr);
eng.stopMtcOutput();
// Release trigger's own handle if it matches the new device
eng.getMtcOutput().refreshDeviceList();
auto mtcNames = eng.getMtcOutput().getDeviceNames();
if (sel < mtcNames.size()
&& eng.getTriggerOutput().hasOwnMidiOpen()
&& eng.getTriggerOutput().getCurrentMidiDeviceName() == mtcNames[sel])
{
eng.getTriggerOutput().releaseOwnMidi();
}
eng.startMtcOutput(sel);
// Re-establish sharing if devices match
if (eng.getMtcOutput().getIsRunning())
{
auto trigDevName = stripComboMarker(cmbTriggerMidiDevice.getText());
if (trigDevName == eng.getMtcOutput().getCurrentDeviceName())
eng.getTriggerOutput().setSharedMidiOutput(eng.getMtcOutput().getMidiOutputPtr());
else
applyTriggerSettings(); // reopen trigger on its own device
}
populateMidiAndNetworkCombos();
saveSettings();
}
};
rightContent.addAndMakeVisible(lblOutputMtcStatus); styleLabel(lblOutputMtcStatus); lblOutputMtcStatus.setColour(juce::Label::textColourId, accentRed);
rightContent.addAndMakeVisible(sldMtcOffset); styleOffsetSlider(sldMtcOffset);
rightContent.addAndMakeVisible(lblMtcOffset); lblMtcOffset.setText("MTC OFFSET:", juce::dontSendNotification); styleLabel(lblMtcOffset);
sldMtcOffset.onValueChange = [this] { if (!syncing) { currentEngine().setMtcOutputOffset((int)sldMtcOffset.getValue()); saveSettings(); } };
addRightLabelAndCombo(lblArtnetOutputInterface, cmbArtnetOutputInterface, "ART-NET OUTPUT DEVICE:");
cmbArtnetOutputInterface.onChange = [this]
{
if (syncing) return;
auto& eng = currentEngine();
if (eng.isOutputArtnetEnabled())
{
int sel = cmbArtnetOutputInterface.getSelectedId() - 2;
eng.stopArtnetOutput();
eng.startArtnetOutput(sel);
// Update combo to actual interface before repopulate (handles fallback)
int actualId = eng.getArtnetOutput().getSelectedInterface() + 2;
cmbArtnetOutputInterface.setSelectedId(actualId, juce::dontSendNotification);
populateMidiAndNetworkCombos(); // refresh markers (auto-restores all selections)
saveSettings();
}
};
rightContent.addAndMakeVisible(lblOutputArtnetStatus); styleLabel(lblOutputArtnetStatus); lblOutputArtnetStatus.setColour(juce::Label::textColourId, accentOrange);
rightContent.addAndMakeVisible(sldArtnetOffset); styleOffsetSlider(sldArtnetOffset);
rightContent.addAndMakeVisible(lblArtnetOffset); lblArtnetOffset.setText("ART-NET OFFSET:", juce::dontSendNotification); styleLabel(lblArtnetOffset);
sldArtnetOffset.onValueChange = [this] { if (!syncing) { currentEngine().setArtnetOutputOffset((int)sldArtnetOffset.getValue()); saveSettings(); } };
addRightLabelAndCombo(lblAudioOutputTypeFilter, cmbAudioOutputTypeFilter, "AUDIO DRIVER:");
cmbAudioOutputTypeFilter.onChange = [this]
{
if (syncing) return;
populateFilteredOutputDeviceCombos();
auto& eng = currentEngine();
if (eng.isOutputLtcEnabled()) startCurrentLtcOutput();
if (eng.isOutputThruEnabled()) startCurrentThruOutput();
saveSettings();
};
addRightLabelAndCombo(lblAudioOutputDevice, cmbAudioOutputDevice, "LTC OUTPUT DEVICE:");
cmbAudioOutputDevice.onChange = [this]
{
if (syncing) return;
if (cmbAudioOutputDevice.getSelectedId() > 0
&& cmbAudioOutputDevice.getSelectedId() != kPlaceholderItemId && currentEngine().isOutputLtcEnabled())
{
startCurrentLtcOutput();
populateFilteredOutputDeviceCombos(); // refresh markers (auto-restores both combos)
saveSettings();
}
};
addRightLabelAndCombo(lblAudioOutputChannel, cmbAudioOutputChannel, "LTC CHANNEL:");
cmbAudioOutputChannel.onChange = [this]
{
if (syncing) return;
if (currentEngine().isOutputLtcEnabled() && cmbAudioOutputDevice.getSelectedId() > 0
&& cmbAudioOutputDevice.getSelectedId() != kPlaceholderItemId)
{ startCurrentLtcOutput(); saveSettings(); }
};
rightContent.addAndMakeVisible(sldLtcOutputGain); styleGainSlider(sldLtcOutputGain);
rightContent.addAndMakeVisible(lblLtcOutputGain); lblLtcOutputGain.setText("LTC OUTPUT GAIN:", juce::dontSendNotification); styleLabel(lblLtcOutputGain);
rightContent.addAndMakeVisible(mtrLtcOutput); mtrLtcOutput.setMeterColour(accentPurple);
sldLtcOutputGain.onValueChange = [this] { if (!syncing) { currentEngine().getLtcOutput().setOutputGain((float)sldLtcOutputGain.getValue() / 100.0f); saveSettings(); } };
rightContent.addAndMakeVisible(lblOutputLtcStatus); styleLabel(lblOutputLtcStatus); lblOutputLtcStatus.setColour(juce::Label::textColourId, accentPurple);
rightContent.addAndMakeVisible(sldLtcOffset); styleOffsetSlider(sldLtcOffset);
rightContent.addAndMakeVisible(lblLtcOffset); lblLtcOffset.setText("LTC OFFSET:", juce::dontSendNotification); styleLabel(lblLtcOffset);
sldLtcOffset.onValueChange = [this] { if (!syncing) { currentEngine().setLtcOutputOffset((int)sldLtcOffset.getValue()); saveSettings(); } };
// AudioThru controls visible for all engines in the panel but only functional for engine 0
addRightLabelAndCombo(lblThruOutputDevice, cmbThruOutputDevice, "AUDIO THRU OUTPUT DEVICE:");
cmbThruOutputDevice.onChange = [this]
{
if (syncing) return;
if (currentEngine().isOutputThruEnabled() && cmbThruOutputDevice.getSelectedId() != kPlaceholderItemId)
{
startCurrentThruOutput();
populateFilteredOutputDeviceCombos(); // refresh markers (auto-restores both combos)
saveSettings();
}
};
addRightLabelAndCombo(lblThruOutputChannel, cmbThruOutputChannel, "AUDIO THRU OUTPUT CHANNEL:");
cmbThruOutputChannel.onChange = [this]
{
if (syncing) return;
if (currentEngine().isOutputThruEnabled() && cmbThruOutputDevice.getSelectedId() != kPlaceholderItemId)
{ startCurrentThruOutput(); saveSettings(); }
};
rightContent.addAndMakeVisible(sldThruOutputGain); styleGainSlider(sldThruOutputGain);
rightContent.addAndMakeVisible(lblThruOutputGain); lblThruOutputGain.setText("AUDIO THRU OUTPUT GAIN:", juce::dontSendNotification); styleLabel(lblThruOutputGain);
rightContent.addAndMakeVisible(mtrThruOutput); mtrThruOutput.setMeterColour(accentCyan);
sldThruOutputGain.onValueChange = [this] {
if (!syncing && currentEngine().getAudioThru())
{ currentEngine().getAudioThru()->setOutputGain((float)sldThruOutputGain.getValue() / 100.0f); saveSettings(); }
};
rightContent.addAndMakeVisible(lblOutputThruStatus); styleLabel(lblOutputThruStatus); lblOutputThruStatus.setColour(juce::Label::textColourId, accentCyan);
rightContent.addAndMakeVisible(btnRefreshDevices);
btnRefreshDevices.onClick = [this] { populateMidiAndNetworkCombos(); startAudioDeviceScan(); };
btnRefreshDevices.setColour(juce::TextButton::buttonColourId, juce::Colour(0xFF1A1D23));
btnRefreshDevices.setColour(juce::TextButton::textColourOffId, textMid);
addAndMakeVisible(btnGitHub);
btnGitHub.setFont(juce::Font(juce::FontOptions(getMonoFontName(), 9.0f, juce::Font::plain)), false);
btnGitHub.setColour(juce::HyperlinkButton::textColourId, juce::Colour(0xFF546E7A));
// --- Update checker button (hidden until update found) ---
addChildComponent(btnUpdateAvailable); // hidden by default
btnUpdateAvailable.setFont(juce::Font(juce::FontOptions(getMonoFontName(), 10.0f, juce::Font::bold)), false);
btnUpdateAvailable.setColour(juce::HyperlinkButton::textColourId, juce::Colour(0xFF4FC3F7)); // cyan
addAndMakeVisible(btnCheckUpdates);
btnCheckUpdates.setColour(juce::TextButton::buttonColourId, juce::Colours::transparentBlack);
btnCheckUpdates.setColour(juce::TextButton::textColourOffId, juce::Colour(0xFF546E7A));
btnCheckUpdates.onClick = [this]
{
auto appVer = juce::JUCEApplication::getInstance()->getApplicationVersion();
updateNotificationShown = false;
updateCheckDelay = 0;
btnUpdateAvailable.setVisible(false);
btnCheckUpdates.setButtonText("Checking...");
btnCheckUpdates.setColour(juce::TextButton::textColourOffId, juce::Colour(0xFF78909C));
updateChecker.checkAsync(appVer);
};
updateCheckDelay = 180; // ~3 seconds at 60Hz before first check
// =====================================================================
// STARTUP
// =====================================================================
populateMidiAndNetworkCombos();
loadAndApplyNonAudioSettings();
for (auto* cmb : { &cmbAudioInputDevice, &cmbAudioOutputDevice, &cmbThruOutputDevice })
cmb->addItem("Scanning...", kPlaceholderItemId);
startTimerHz(60);
startAudioDeviceScan();
// GPU-accelerated rendering (Windows only).
// On Windows, JUCE's OpenGL context offloads image compositing from GDI
// to the GPU, reducing message-thread load from repaint().
// On macOS, this is DISABLED: JUCE still renders into software images
// and then uploads them as textures through Apple's deprecated
// OpenGL-to-Metal translation layer, which adds overhead rather than
// reducing it. CoreGraphics already uses Metal internally for
// compositing, so native rendering is faster without OpenGL.
#if JUCE_WINDOWS
glContext.attachTo(*this);
#endif
}
MainComponent::~MainComponent()
{
// 0. Detach OpenGL before destroying any components (Windows only)
#if JUCE_WINDOWS
glContext.detach();
#endif
// 1. Stop our UI timer first -- no more timerCallback() after this
stopTimer();
// 2. Detach LookAndFeel before destroying any child components
setLookAndFeel(nullptr);
// 3. Save settings while engines are still alive
flushSettings();
// 4. UpdateChecker thread stops in its own destructor (10s timeout)
// 5. Stop AudioScanThread
if (scanThread)
{
scanThread->signalThreadShouldExit();
if (scanThread->isThreadRunning())
{
if (!scanThread->stopThread(2000))
{ DBG("WARNING: AudioScanThread did not stop within 2s timeout"); }
}
scanThread->tempManager = nullptr; // release AudioDeviceManager early
scanThread = nullptr;
}
// 6. Capture window bounds before closing (delete doesn't call closeButtonPressed)
if (trackMapWindow != nullptr)
{
auto b = trackMapWindow->getBounds();
settings.trackMapBounds = juce::String(b.getX()) + " " + juce::String(b.getY())
+ " " + juce::String(b.getWidth()) + " " + juce::String(b.getHeight());
delete trackMapWindow.getComponent();
}
if (mixerMapWindow != nullptr)
{
auto b = mixerMapWindow->getBounds();
settings.mixerMapBounds = juce::String(b.getX()) + " " + juce::String(b.getY())
+ " " + juce::String(b.getWidth()) + " " + juce::String(b.getHeight());
delete mixerMapWindow.getComponent();