-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainComponent.cpp
More file actions
2530 lines (2205 loc) · 109 KB
/
MainComponent.cpp
File metadata and controls
2530 lines (2205 loc) · 109 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;
//==============================================================================
// 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));
setSize(900, 700);
// --- Tab bar ---
addAndMakeVisible(btnAddEngine);
btnAddEngine.setColour(juce::TextButton::buttonColourId, juce::Colour(0xFF1A1D23));
btnAddEngine.setColour(juce::TextButton::textColourOffId, accentBlue);
btnAddEngine.onClick = [this] { addEngine(); };
rebuildTabButtons();
// --- Right panel scrollable viewport ---
addAndMakeVisible(rightViewport);
rightViewport.setViewedComponent(&rightContent, false);
rightViewport.setScrollBarsShown(true, false);
// --- Input buttons ---
for (auto* btn : { &btnMtcIn, &btnArtnetIn, &btnSysTime, &btnLtcIn })
{ 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(); }
};
// --- 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
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)
{
addAndMakeVisible(lbl); 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);
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);
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(); populateAudioInputChannels(); }
};
addLabelAndCombo(lblAudioInputChannel, cmbAudioInputChannel, "LTC CHANNEL:");
cmbAudioInputChannel.onChange = [this] { if (!syncing && currentEngine().getActiveInput() == InputSource::LTC) { startCurrentLtcInput(); saveSettings(); } };
addAndMakeVisible(sldLtcInputGain); styleGainSlider(sldLtcInputGain);
addAndMakeVisible(lblLtcInputGain); lblLtcInputGain.setText("LTC INPUT GAIN:", juce::dontSendNotification); styleLabel(lblLtcInputGain);
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(); } };
addAndMakeVisible(sldThruInputGain); styleGainSlider(sldThruInputGain);
addAndMakeVisible(lblThruInputGain); lblThruInputGain.setText("AUDIO THRU INPUT GAIN:", juce::dontSendNotification); styleLabel(lblThruInputGain);
addAndMakeVisible(mtrThruInput); mtrThruInput.setMeterColour(accentCyan);
sldThruInputGain.onValueChange = [this] { if (!syncing) { currentEngine().getLtcInput().setPassthruGain((float)sldThruInputGain.getValue() / 100.0f); saveSettings(); } };
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())
{
eng.stopMtcOutput();
eng.getMtcOutput().refreshDeviceList();
eng.startMtcOutput(sel);
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() - 1;
eng.stopArtnetOutput();
eng.startArtnetOutput(sel);
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(); 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(); 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();
}
MainComponent::~MainComponent()
{
setLookAndFeel(nullptr);
flushSettings();
stopTimer();
if (scanThread && scanThread->isThreadRunning())
{
if (!scanThread->stopThread(2000))
{ DBG("WARNING: AudioScanThread did not stop within 2s timeout (destructor)"); }
}
// NOTE: Any pending callAsync from AudioScanThread::run() is safe here because
// callAsync dispatches on the message thread, and the destructor also runs on the
// message thread, so there is no interleaving between engines.clear() and the
// async callback. The SafePointer guard would also catch a fully-deleted component.
engines.clear();
}
//==============================================================================
// ENGINE MANAGEMENT
//==============================================================================
void MainComponent::addEngine()
{
if ((int)engines.size() >= kMaxEngines)
return;
// Generate a unique name
int nameNum = (int)engines.size() + 1;
auto nameExists = [this](const juce::String& name) {
for (auto& e : engines)
if (e->getName() == name) return true;
return false;
};
juce::String newName;
do { newName = "ENGINE " + juce::String(nameNum++); } while (nameExists(newName));
int newIndex = (int)engines.size();
engines.push_back(std::make_unique<TimecodeEngine>(newIndex, newName));
rebuildTabButtons();
selectEngine(newIndex);
saveSettings();
}
void MainComponent::removeEngine(int index)
{
if (engines.size() <= 1 || index < 0 || index >= (int)engines.size())
return;
// Flush pending settings before modifying arrays
if (settingsDirty)
flushSettings();
// Remember if the deleted engine was the primary and had thru enabled,
// so we can restart AudioThru on the new primary after reindexing.
bool deletedWasPrimary = engines[(size_t)index]->isPrimary();
bool deletedHadThru = deletedWasPrimary
&& engines[(size_t)index]->isOutputThruEnabled();
// Explicitly stop all protocols on the engine being deleted BEFORE
// erasing it, so destructors don't race with any pending callbacks.
engines[(size_t)index]->stopMtcOutput();
engines[(size_t)index]->stopArtnetOutput();
engines[(size_t)index]->stopLtcOutput();
engines[(size_t)index]->stopThruOutput();
engines[(size_t)index]->stopMtcInput();
engines[(size_t)index]->stopArtnetInput();
engines[(size_t)index]->stopLtcInput();
engines.erase(engines.begin() + index);
// Re-index remaining engines so isPrimary() and getIndex() stay correct.
// This also creates AudioThru on the new primary engine if engine 0 was deleted.
for (int i = 0; i < (int)engines.size(); i++)
engines[(size_t)i]->reindex(i);
// Keep settings.engines in sync with engines vector
if (index < (int)settings.engines.size())
settings.engines.erase(settings.engines.begin() + index);
// Fix selectedEngine to track the same engine after shift
if (index < selectedEngine)
selectedEngine--; // engine we were on shifted left
else if (selectedEngine >= (int)engines.size())
selectedEngine = (int)engines.size() - 1; // we deleted the one we were on (or last)
rebuildTabButtons();
syncUIFromEngine();
// If the deleted engine was the primary with AudioThru active,
// the new primary engine (index 0) got a fresh AudioThru instance
// from reindex() but it's not started. Attempt to restart it if
// the new primary's LTC input is running and thru settings exist.
if (deletedHadThru && !engines.empty())
{
auto& newPrimary = *engines[0];
if (newPrimary.getActiveInput() == InputSource::LTC
&& newPrimary.getLtcInput().getIsRunning()
&& !settings.engines.empty()
&& settings.engines[0].thruOutEnabled)
{
newPrimary.setOutputThruEnabled(true);
// If engine 0 is currently selected, use UI combos; otherwise use saved settings
if (selectedEngine == 0)
{
startCurrentThruOutput();
}
else if (!settings.engines[0].thruOutputDevice.isEmpty())
{
int ch = settings.engines[0].thruOutputStereo ? -1 : settings.engines[0].thruOutputChannel;
newPrimary.startThruOutput(settings.engines[0].thruOutputType,
settings.engines[0].thruOutputDevice, ch,
getPreferredSampleRate(), getPreferredBufferSize());
}
}
}
saveSettings();
}
void MainComponent::selectEngine(int index)
{
if (index < 0 || index >= (int)engines.size() || index == selectedEngine)
return;
// Flush any pending settings from the current engine before switching
if (settingsDirty)
flushSettings();
selectedEngine = index;
inputConfigExpanded = true;
mtcOutExpanded = artnetOutExpanded = ltcOutExpanded = thruOutExpanded = true;
// Reset FPS tracking so buttons update immediately for new engine
lastDisplayedFps = engines[(size_t)index]->getCurrentFps();
lastDisplayedOutFps = engines[(size_t)index]->getEffectiveOutputFps();
syncUIFromEngine();
updateTabAppearance();
repaint();
}
void MainComponent::renameEngine(int index)
{
if (index < 0 || index >= (int)engines.size()) return;
auto alertWindow = std::make_shared<juce::AlertWindow>("Rename Engine",
"Enter a name for this engine:",
juce::MessageBoxIconType::NoIcon, this);
alertWindow->addTextEditor("name", engines[(size_t)index]->getName());
alertWindow->addButton("OK", 1);
alertWindow->addButton("Cancel", 0);
juce::Component::SafePointer<MainComponent> safeThis(this);
alertWindow->enterModalState(true, juce::ModalCallbackFunction::create(
[safeThis, index, alertWindow](int result)
{
if (result == 1 && safeThis != nullptr)
{
auto newName = alertWindow->getTextEditorContents("name").trim();
if (newName.isNotEmpty() && index < (int)safeThis->engines.size())
{
safeThis->engines[(size_t)index]->setName(newName);
// Only update text — don't rebuild buttons (avoids heap
// corruption from destroying components during modal callback)
safeThis->updateTabAppearance();
safeThis->resized(); // reposition in case text width changed
safeThis->saveSettings();
}
}
// alertWindow is destroyed automatically when shared_ptr goes out of scope
}), true);
}
//==============================================================================
// TAB BAR
//==============================================================================
void MainComponent::rebuildTabButtons()
{
for (auto& tb : tabButtons)
removeChildComponent(tb.get());
tabButtons.clear();
for (int i = 0; i < (int)engines.size(); i++)
{
auto btn = std::make_unique<TabButton>(engines[(size_t)i]->getName());
btn->setClickingTogglesState(false);
int idx = i;
btn->onClick = [this, idx] { selectEngine(idx); };
btn->onRightClick = [this, idx] { showTabContextMenu(idx); };
addAndMakeVisible(btn.get());
tabButtons.push_back(std::move(btn));
}
updateTabAppearance();
resized();
// Disable "+" button when at max engines
btnAddEngine.setEnabled((int)engines.size() < kMaxEngines);
btnAddEngine.setAlpha((int)engines.size() < kMaxEngines ? 1.0f : 0.3f);
}
void MainComponent::updateTabAppearance()
{
for (int i = 0; i < (int)tabButtons.size(); i++)
{
bool active = (i == selectedEngine);
auto& btn = *tabButtons[(size_t)i];
btn.setButtonText(engines[(size_t)i]->getName());
btn.setColour(juce::TextButton::buttonColourId, active ? accentBlue.withAlpha(0.2f) : juce::Colour(0xFF1A1D23));
btn.setColour(juce::TextButton::textColourOffId, active ? textBright : textMid);
}
}
void MainComponent::showTabContextMenu(int index)
{
juce::PopupMenu menu;
menu.addItem(1, "Rename");
if (engines.size() > 1)
menu.addItem(2, "Delete");
juce::Component::SafePointer<MainComponent> safeThis(this);
menu.showMenuAsync(juce::PopupMenu::Options(), [safeThis, index](int result) {
if (safeThis == nullptr) return;
if (result == 1) safeThis->renameEngine(index);
else if (result == 2) safeThis->removeEngine(index);
});
}
//==============================================================================
// SYNC UI <-> ENGINE
//==============================================================================
void MainComponent::syncUIFromEngine()
{
syncing = true;
auto& eng = currentEngine();
// Input buttons
updateInputButtonStates();
// FPS
updateFpsButtonStates();
btnFpsConvert.setToggleState(eng.isFpsConvertEnabled(), juce::dontSendNotification);
updateOutputFpsButtonStates();
// Output toggles
btnMtcOut.setToggleState(eng.isOutputMtcEnabled(), juce::dontSendNotification);
btnArtnetOut.setToggleState(eng.isOutputArtnetEnabled(), juce::dontSendNotification);
btnLtcOut.setToggleState(eng.isOutputLtcEnabled(), juce::dontSendNotification);
// AudioThru toggle: only show for primary engine
btnThruOut.setToggleState(eng.isOutputThruEnabled(), juce::dontSendNotification);
btnThruOut.setVisible(eng.isPrimary());
// Offsets
sldMtcOffset.setValue(eng.getMtcOutputOffset(), juce::dontSendNotification);
sldArtnetOffset.setValue(eng.getArtnetOutputOffset(), juce::dontSendNotification);
sldLtcOffset.setValue(eng.getLtcOutputOffset(), juce::dontSendNotification);
// Gains
sldLtcInputGain.setValue(eng.getLtcInput().getInputGain() * 100.0f, juce::dontSendNotification);
sldThruInputGain.setValue(eng.getLtcInput().getPassthruGain() * 100.0f, juce::dontSendNotification);
sldLtcOutputGain.setValue(eng.getLtcOutput().getOutputGain() * 100.0f, juce::dontSendNotification);
if (eng.getAudioThru())
sldThruOutputGain.setValue(eng.getAudioThru()->getOutputGain() * 100.0f, juce::dontSendNotification);
// Repopulate device combos so in-use markers reflect the new engine context
populateMidiAndNetworkCombos();
populateFilteredInputDeviceCombo();
populateFilteredOutputDeviceCombos();
// MIDI device selections — find matching device in combo
{
int idx = findDeviceByName(cmbMidiInputDevice, eng.getMtcInput().getCurrentDeviceName());
if (idx >= 0) cmbMidiInputDevice.setSelectedId(idx + 1, juce::dontSendNotification);
}
{
int idx = findDeviceByName(cmbMidiOutputDevice, eng.getMtcOutput().getCurrentDeviceName());
if (idx >= 0) cmbMidiOutputDevice.setSelectedId(idx + 1, juce::dontSendNotification);
}
// ArtNet interface selections — restore from saved settings
if (selectedEngine < (int)settings.engines.size())
{
auto& es = settings.engines[(size_t)selectedEngine];
int artInId = es.artnetInputInterface + 1; // combo id is 1-based (1 = All Interfaces)
if (artInId < 1) artInId = 1; // handle legacy -1 default
if (artInId <= cmbArtnetInputInterface.getNumItems())
cmbArtnetInputInterface.setSelectedId(artInId, juce::dontSendNotification);
int artOutId = es.artnetOutputInterface + 1;
if (artOutId < 1) artOutId = 1; // handle legacy -1 default
if (artOutId <= cmbArtnetOutputInterface.getNumItems())
cmbArtnetOutputInterface.setSelectedId(artOutId, juce::dontSendNotification);
}
// Audio device selections — find matching device in filtered list
if (selectedEngine < (int)settings.engines.size())
{
auto& es = settings.engines[(size_t)selectedEngine];
int audioInIdx = findFilteredIndex(filteredInputIndices, scannedAudioInputs,
es.audioInputType, es.audioInputDevice);
if (audioInIdx >= 0)
cmbAudioInputDevice.setSelectedId(audioInIdx + 1, juce::dontSendNotification);
int audioOutIdx = findFilteredIndex(filteredOutputIndices, scannedAudioOutputs,
es.audioOutputType, es.audioOutputDevice);
if (audioOutIdx >= 0)
cmbAudioOutputDevice.setSelectedId(audioOutIdx + 1, juce::dontSendNotification);
int thruOutIdx = findFilteredIndex(filteredOutputIndices, scannedAudioOutputs,
es.thruOutputType, es.thruOutputDevice);
if (thruOutIdx >= 0)
cmbThruOutputDevice.setSelectedId(thruOutIdx + 1, juce::dontSendNotification);
}
// Audio channel selections based on running engines
if (eng.getLtcInput().getIsRunning())
{
int ch = eng.getLtcInput().getSelectedChannel();
if (ch >= 0) cmbAudioInputChannel.setSelectedId(ch + 1, juce::dontSendNotification);
if (eng.getLtcInput().hasPassthruChannel())
{
int thruCh = eng.getLtcInput().getPassthruChannel();
if (thruCh >= 0) cmbThruInputChannel.setSelectedId(thruCh + 1, juce::dontSendNotification);
}
}
else if (selectedEngine < (int)settings.engines.size())
{
auto& es = settings.engines[(size_t)selectedEngine];
cmbAudioInputChannel.setSelectedId(es.audioInputChannel + 1, juce::dontSendNotification);
cmbThruInputChannel.setSelectedId(es.thruInputChannel + 1, juce::dontSendNotification);
}
if (eng.getLtcOutput().getIsRunning())
{
int ch = eng.getLtcOutput().getSelectedChannel();
if (ch == -1)
cmbAudioOutputChannel.setSelectedId(kStereoItemId, juce::dontSendNotification);
else if (ch >= 0)
cmbAudioOutputChannel.setSelectedId(ch + 1, juce::dontSendNotification);
}
else if (selectedEngine < (int)settings.engines.size())
{
auto& es = settings.engines[(size_t)selectedEngine];
if (es.audioOutputStereo)
cmbAudioOutputChannel.setSelectedId(kStereoItemId, juce::dontSendNotification);
else
cmbAudioOutputChannel.setSelectedId(es.audioOutputChannel + 1, juce::dontSendNotification);
}
if (eng.getAudioThru() && eng.getAudioThru()->getIsRunning())
{
int ch = eng.getAudioThru()->getSelectedChannel();
if (ch == -1)
cmbThruOutputChannel.setSelectedId(kStereoItemId, juce::dontSendNotification);
else if (ch >= 0)
cmbThruOutputChannel.setSelectedId(ch + 1, juce::dontSendNotification);
}
else if (selectedEngine < (int)settings.engines.size())
{
auto& es = settings.engines[(size_t)selectedEngine];
if (es.thruOutputStereo)
cmbThruOutputChannel.setSelectedId(kStereoItemId, juce::dontSendNotification);
else
cmbThruOutputChannel.setSelectedId(es.thruOutputChannel + 1, juce::dontSendNotification);
}
updateDeviceSelectorVisibility();
resized();
repaint();
syncing = false;
}
//==============================================================================
// ENGINE-LEVEL START/STOP (gathers params from UI)
//==============================================================================
void MainComponent::startCurrentMtcInput()
{
auto& eng = currentEngine();
int sel = cmbMidiInputDevice.getSelectedId() - 1;
eng.startMtcInput(sel);
}
void MainComponent::startCurrentArtnetInput()
{
auto& eng = currentEngine();
int sel = cmbArtnetInputInterface.getSelectedId() - 1;
eng.startArtnetInput(sel);
}
void MainComponent::startCurrentLtcInput()
{
auto& eng = currentEngine();
auto entry = getSelectedAudioInput();
if (entry.deviceName.isEmpty() && !filteredInputIndices.isEmpty())
{ cmbAudioInputDevice.setSelectedId(1, juce::dontSendNotification); entry = getSelectedAudioInput(); }
int ltcCh = cmbAudioInputChannel.getSelectedId() - 1;
if (ltcCh < 0) ltcCh = 0;
int thruCh = -1;
if (eng.isPrimary() && eng.isOutputThruEnabled())
{ thruCh = cmbThruInputChannel.getSelectedId() - 1; if (thruCh < 0) thruCh = 1; }
if (eng.startLtcInput(entry.typeName, entry.deviceName, ltcCh, thruCh,
getPreferredSampleRate(), getPreferredBufferSize()))
{
eng.getLtcInput().setInputGain((float)sldLtcInputGain.getValue() / 100.0f);
eng.getLtcInput().setPassthruGain((float)sldThruInputGain.getValue() / 100.0f);
populateAudioInputChannels();
if (eng.isPrimary() && eng.isOutputThruEnabled())
startCurrentThruOutput();
}
saveSettings();
}
void MainComponent::startCurrentThruOutput()
{
auto& eng = currentEngine();
if (!eng.isPrimary()) return;
auto entry = getSelectedThruOutput();
if (entry.deviceName.isEmpty() && !filteredOutputIndices.isEmpty())
{ cmbThruOutputDevice.setSelectedId(1, juce::dontSendNotification); entry = getSelectedThruOutput(); }
int outCh = getChannelFromCombo(cmbThruOutputChannel);
eng.startThruOutput(entry.typeName, entry.deviceName, outCh,
getPreferredSampleRate(), getPreferredBufferSize());
if (eng.getAudioThru() && eng.getAudioThru()->getIsRunning())
{
eng.getAudioThru()->setOutputGain((float)sldThruOutputGain.getValue() / 100.0f);
populateThruOutputChannels();
}
}
void MainComponent::startCurrentMtcOutput()
{
auto& eng = currentEngine();
int sel = cmbMidiOutputDevice.getSelectedId() - 1;
eng.startMtcOutput(sel);
}
void MainComponent::startCurrentArtnetOutput()
{
auto& eng = currentEngine();
int sel = cmbArtnetOutputInterface.getSelectedId() - 1;
eng.startArtnetOutput(sel);
}
void MainComponent::startCurrentLtcOutput()
{
auto& eng = currentEngine();
eng.stopLtcOutput();
auto entry = getSelectedAudioOutput();
if (entry.deviceName.isEmpty() && !filteredOutputIndices.isEmpty())
{ cmbAudioOutputDevice.setSelectedId(1, juce::dontSendNotification); entry = getSelectedAudioOutput(); }
int channel = getChannelFromCombo(cmbAudioOutputChannel);
if (eng.startLtcOutput(entry.typeName, entry.deviceName, channel,
getPreferredSampleRate(), getPreferredBufferSize()))
{
eng.getLtcOutput().setOutputGain((float)sldLtcOutputGain.getValue() / 100.0f);
populateAudioOutputChannels();
// Restart thru if it was stopped due to a previous device conflict
if (eng.isPrimary() && eng.isOutputThruEnabled()
&& eng.getAudioThru() && !eng.getAudioThru()->getIsRunning())
{
auto thruEntry = getSelectedThruOutput();
if (thruEntry.deviceName.isNotEmpty()
&& !(thruEntry.deviceName == entry.deviceName && thruEntry.typeName == entry.typeName))
startCurrentThruOutput();
}
}
}
void MainComponent::updateCurrentOutputStates()
{
auto& eng = currentEngine();
if (eng.isOutputMtcEnabled() && !eng.getMtcOutput().getIsRunning()) startCurrentMtcOutput();
else if (!eng.isOutputMtcEnabled() && eng.getMtcOutput().getIsRunning()) eng.stopMtcOutput();
if (eng.isOutputArtnetEnabled() && !eng.getArtnetOutput().getIsRunning()) startCurrentArtnetOutput();
else if (!eng.isOutputArtnetEnabled() && eng.getArtnetOutput().getIsRunning()) eng.stopArtnetOutput();
if (eng.isOutputLtcEnabled() && !eng.getLtcOutput().getIsRunning() && !scannedAudioOutputs.isEmpty()) startCurrentLtcOutput();
else if (!eng.isOutputLtcEnabled() && eng.getLtcOutput().getIsRunning()) eng.stopLtcOutput();
if (eng.isPrimary())
{
if (eng.isOutputThruEnabled() && eng.getAudioThru() && !eng.getAudioThru()->getIsRunning())
{
if (eng.getActiveInput() == InputSource::LTC)
startCurrentLtcInput();
else
startCurrentThruOutput();
}
else if (!eng.isOutputThruEnabled() && eng.getAudioThru() && eng.getAudioThru()->getIsRunning())
{
eng.stopThruOutput();
}
}
}
//==============================================================================
// BACKGROUND AUDIO SCAN
//==============================================================================
void MainComponent::startAudioDeviceScan()
{
if (scanThread && scanThread->isThreadRunning())
{
if (!scanThread->stopThread(2000))
{ DBG("WARNING: AudioScanThread did not stop within 2s timeout — skipping new scan"); return; }
}
scanThread = std::make_unique<AudioScanThread>(this);
// Create AudioDeviceManager on the message thread — JUCE 8.x internally
// registers a MIDI device-change listener that requires JUCE_ASSERT_MESSAGE_THREAD.
scanThread->tempManager = std::make_unique<juce::AudioDeviceManager>();
scanThread->tempManager->initialise(128, 128, nullptr, false);
scanThread->startThread();
}
void MainComponent::onAudioScanComplete(const juce::Array<AudioDeviceEntry>& inputs,
const juce::Array<AudioDeviceEntry>& outputs)
{