-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainComponent.h
More file actions
488 lines (430 loc) · 19.7 KB
/
MainComponent.h
File metadata and controls
488 lines (430 loc) · 19.7 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
// Super Timecode Converter
// Copyright (c) 2026 Fiverecords -- MIT License
// https://github.com/fiverecords/SuperTimecodeConverter
#pragma once
#include <JuceHeader.h>
#include "TimecodeCore.h"
#include "TimecodeDisplay.h"
#include "TimecodeEngine.h"
#include "AppSettings.h"
#include "CustomLookAndFeel.h"
#include "LevelMeter.h"
#include "TrackMapEditor.h"
#include "MixerMapEditor.h"
#include "NetworkUtils.h"
#include "UpdateChecker.h"
#include "MediaDisplay.h"
#include "ProDJLinkView.h"
#include <vector>
#include <memory>
//==============================================================================
class GainSlider : public juce::Slider
{
public:
GainSlider()
{
setDoubleClickReturnValue(true, 100.0);
setTooltip("Right-click or double-click to reset");
}
void mouseDown(const juce::MouseEvent& e) override
{
if (e.mods.isRightButtonDown() || e.mods.isPopupMenu())
{ setValue(getDoubleClickReturnValue(), juce::sendNotificationAsync); return; }
juce::Slider::mouseDown(e);
}
};
//==============================================================================
class PanelContent : public juce::Component
{
public:
PanelContent() { setOpaque(false); }
void setContentHeight(int h)
{
if (getHeight() != h) setSize(getWidth(), h);
}
/// Add a section separator at the given Y position with optional label.
void addSectionSeparator(int y, const juce::String& label = {})
{
sectionSeps.push_back({ y, label });
}
/// Clear all separators (call at start of resized before re-adding)
void clearSectionSeparators() { sectionSeps.clear(); }
void paint(juce::Graphics& g) override
{
for (auto& sep : sectionSeps)
{
if (sep.label.isNotEmpty())
{
// Labeled separator: draw label text only (acts as visual divider)
g.setColour(juce::Colour(0xFF37474F));
g.setFont(juce::Font(juce::FontOptions(getMonoFontName(), 9.0f, juce::Font::bold)));
g.drawText(sep.label, 12, sep.y + 2, getWidth() - 24, 12,
juce::Justification::centredLeft);
}
else
{
// Unlabeled separator: subtle horizontal line
g.setColour(juce::Colour(0xFF1E2028));
g.drawHorizontalLine(sep.y, 12.0f, (float)(getWidth() - 12));
}
}
}
private:
struct SectionSep { int y; juce::String label; };
std::vector<SectionSep> sectionSeps;
};
//==============================================================================
class MainComponent : public juce::Component,
public juce::Timer
{
public:
MainComponent();
~MainComponent() override;
void paint(juce::Graphics&) override;
void resized() override;
void timerCallback() override;
bool keyPressed(const juce::KeyPress& key) override;
void onAudioScanComplete(const juce::Array<AudioDeviceEntry>& inputs,
const juce::Array<AudioDeviceEntry>& outputs);
/// Main window bounds persistence (called by MainWindow in Main.cpp)
juce::String getSavedMainWindowBounds() const { return settings.mainWindowBounds; }
void saveMainWindowBounds(const juce::String& bounds)
{
settings.mainWindowBounds = bounds;
settings.save();
}
private:
//==============================================================================
// Background audio device scanner
//==============================================================================
class AudioScanThread : public juce::Thread
{
public:
AudioScanThread(MainComponent* owner);
void run() override;
// Created on message thread before startThread() -- JUCE 8.x requires
// AudioDeviceManager construction on the message thread.
std::unique_ptr<juce::AudioDeviceManager> tempManager;
private:
juce::Component::SafePointer<MainComponent> safeOwner;
};
std::unique_ptr<AudioScanThread> scanThread;
bool settingsLoaded = false;
juce::Array<AudioDeviceEntry> scannedAudioInputs;
juce::Array<AudioDeviceEntry> scannedAudioOutputs;
juce::Array<int> filteredInputIndices;
juce::Array<int> filteredOutputIndices;
// --- Custom Look & Feel ---
CustomLookAndFeel customLookAndFeel;
// --- Colours ---
juce::Colour bgDark { 0xFF12141A };
juce::Colour bgPanel { 0xFF14161C };
juce::Colour bgDarker { 0xFF0D0E12 };
juce::Colour borderCol { 0xFF1E2028 };
juce::Colour textDim { 0xFF37474F };
juce::Colour textMid { 0xFF546E7A };
juce::Colour textLight { 0xFF78909C };
juce::Colour textBright { 0xFFCFD8DC };
juce::Colour accentRed { 0xFFC62828 };
juce::Colour accentOrange{ 0xFFE65100 };
juce::Colour accentGreen { 0xFF2E7D32 };
juce::Colour accentPurple{ 0xFF6A1B9A };
juce::Colour accentCyan { 0xFF00838F };
juce::Colour accentBlue { 0xFF1565C0 };
//==============================================================================
// ENGINE MANAGEMENT
//==============================================================================
std::vector<std::unique_ptr<TimecodeEngine>> engines;
int selectedEngine = 0;
ProDJLinkInput sharedProDJLinkInput; // shared across all engines
MixerMap sharedMixerMap; // shared DJM parameter mapping
DbServerClient sharedDbClient; // shared across all engines (Phase 2)
TimecodeEngine& currentEngine() { return *engines[(size_t)selectedEngine]; }
const TimecodeEngine& currentEngine() const { return *engines[(size_t)selectedEngine]; }
void addEngine();
void removeEngine(int index);
void selectEngine(int index);
void renameEngine(int index);
//==============================================================================
// TAB BAR
//==============================================================================
class TabButton : public juce::TextButton
{
public:
TabButton(const juce::String& name) : juce::TextButton(name) {}
std::function<void()> onRightClick;
void mouseDown(const juce::MouseEvent& e) override
{
if (e.mods.isRightButtonDown() || e.mods.isPopupMenu())
{ if (onRightClick) onRightClick(); return; }
juce::TextButton::mouseDown(e);
}
};
std::vector<std::unique_ptr<TabButton>> tabButtons;
juce::TextButton btnAddEngine { "+" };
static constexpr int kTabBarHeight = 28;
static constexpr int kMiniStripRowH = 30;
void rebuildTabButtons();
void updateTabAppearance();
void showTabContextMenu(int index);
int getMiniStripHeight() const;
juce::Rectangle<int> miniStripArea; // cached from resized()
void paintMiniStrip(juce::Graphics& g);
void mouseDown(const juce::MouseEvent& e) override;
//==============================================================================
// SYNC UI <-> ENGINE
//==============================================================================
// Prevents onChange callbacks from firing during sync
bool syncing = false;
void syncUIFromEngine(); // Load engine state into UI controls
void syncEngineFromUI(); // Save UI state into engine settings
//==============================================================================
// UI COMPONENTS (single set, bound to selected engine)
//==============================================================================
TimecodeDisplay timecodeDisplay;
// Bottom bar repaint tracking
juce::String lastBottomBarStatus;
bool lastBottomBarActive = false;
// FPS auto-detect change tracking (for button state updates)
FrameRate lastDisplayedFps = FrameRate::FPS_30;
FrameRate lastDisplayedOutFps = FrameRate::FPS_30;
// --- Collapse state (per-view, not per-engine) ---
bool inputConfigExpanded = true;
bool mtcOutExpanded = true;
bool artnetOutExpanded = true;
bool ltcOutExpanded = true;
bool thruOutExpanded = true;
// --- Input buttons ---
juce::TextButton btnMtcIn { "MTC" };
juce::TextButton btnArtnetIn { "ART-NET" };
juce::TextButton btnSysTime { "SYSTEM" };
juce::TextButton btnLtcIn { "LTC" };
juce::TextButton btnProDJLinkIn { "PRO DJ LINK" };
// --- Output toggles ---
juce::ToggleButton btnMtcOut { "MTC OUT" };
juce::ToggleButton btnArtnetOut { "ART-NET OUT" };
juce::ToggleButton btnLtcOut { "LTC OUT" };
juce::ToggleButton btnThruOut { "AUDIO THRU" };
// --- FPS buttons ---
juce::TextButton btnFps2398 { "23.976" };
juce::TextButton btnFps24 { "24" };
juce::TextButton btnFps25 { "25" };
juce::TextButton btnFps2997 { "29.97" };
juce::TextButton btnFps30 { "30" };
// --- FPS conversion ---
juce::ToggleButton btnFpsConvert { "FPS CONVERT" };
juce::TextButton btnOutFps2398 { "23.976" };
juce::TextButton btnOutFps24 { "24" };
juce::TextButton btnOutFps25 { "25" };
juce::TextButton btnOutFps2997 { "29.97" };
juce::TextButton btnOutFps30 { "30" };
// --- Collapse toggle buttons ---
juce::TextButton btnCollapseInput { "SETTINGS" };
juce::TextButton btnCollapseMtcOut { "" };
juce::TextButton btnCollapseArtnetOut { "" };
juce::TextButton btnCollapseLtcOut { "" };
juce::TextButton btnCollapseThruOut { "" };
// --- Left panel (input config) ---
juce::ComboBox cmbAudioInputTypeFilter; juce::Label lblAudioInputTypeFilter;
juce::ComboBox cmbSampleRate; juce::Label lblSampleRate;
juce::ComboBox cmbBufferSize; juce::Label lblBufferSize;
juce::ComboBox cmbMidiInputDevice; juce::Label lblMidiInputDevice;
juce::ComboBox cmbArtnetInputInterface; juce::Label lblArtnetInputInterface;
// Pro DJ Link controls
juce::ComboBox cmbProDJLinkInterface; juce::Label lblProDJLinkInterface;
juce::ComboBox cmbProDJLinkPlayer; juce::Label lblProDJLinkPlayer;
// BPM Multiplier buttons (per-player, ProDJLink only)
// Single click: session override (temporary, cleared on track change).
// Double click: save to TrackMap (persistent, auto-loaded on track change).
// 0=off, 1=x2, 2=x4, -1=/2, -2=/4.
juce::TextButton btnBpmOff { "1x" };
juce::TextButton btnBpmX2 { "x2" };
juce::TextButton btnBpmX4 { "x4" };
juce::TextButton btnBpmD2 { "/2" };
juce::TextButton btnBpmD4 { "/4" };
void updateBpmMultButtonStates();
void saveBpmMultToTrackMap(int clickedMult);
juce::int64 lastBpmClickMs = 0;
int lastBpmClickMult = -999;
juce::Label lblProDJLinkTrackInfo;
juce::Label lblProDJLinkMetadata;
juce::Label lblMixerStatus; // DJM model + fader values
ArtworkDisplay artworkDisplay; // Phase 2c: album art from CDJ
WaveformDisplay waveformDisplay; // Phase 3: color waveform from CDJ
uint32_t displayedWaveformTrackId = 0; // currently displayed waveform track
uint32_t displayedArtworkId = 0; // currently displayed artwork ID
// Features: TrackMap, MIDI Clock, OSC BPM, Ableton Link
juce::ToggleButton btnTrackMap { "TRACK MAP" };
juce::TextButton btnTrackMapEdit { "Track Map" };
juce::ToggleButton btnMidiClock { "MIDI CLOCK" };
juce::ToggleButton btnOscFwdBpm { "OSC BPM FWD" };
juce::TextEditor edOscFwdBpmAddr;
juce::Label lblOscFwdBpmAddr;
juce::ToggleButton btnOscMixerFwd { "OSC MIXER FWD" };
juce::ToggleButton btnMidiMixerFwd { "MIDI MIXER FWD" };
juce::ToggleButton btnArtnetMixerFwd { "ARTNET MIXER FWD" };
juce::ComboBox cmbArtMixNet, cmbArtMixSub, cmbArtMixUni;
juce::Label lblArtMixAddr;
juce::ComboBox cmbMidiMixCCCh;
juce::Label lblMidiMixCCCh;
juce::ComboBox cmbMidiMixNoteCh;
juce::Label lblMidiMixNoteCh;
juce::ToggleButton btnLink { "ABLETON LINK" };
juce::Label lblLinkStatus;
juce::Component::SafePointer<juce::DocumentWindow> trackMapWindow;
juce::TextButton btnMixerMapEdit { "Mixer Map" };
juce::Component::SafePointer<juce::DocumentWindow> mixerMapWindow;
juce::TextButton btnProDJLinkView { "PDL View" };
juce::TextButton btnBackup { "Backup" };
juce::TextButton btnRestore { "Restore" };
std::unique_ptr<juce::FileChooser> configFileChooser;
juce::ScopedMessageBox importConfirmBox;
std::unique_ptr<ProDJLinkViewWindow> proDJLinkViewWindow;
// Track change triggers
juce::ToggleButton btnTriggerMidi { "MIDI Trigger" };
juce::ComboBox cmbTriggerMidiDevice;
juce::ToggleButton btnTriggerOsc { "OSC Trigger" };
juce::TextEditor edOscIp;
juce::TextEditor edOscPort;
juce::ToggleButton btnArtnetTrigger { "ARTNET Trigger" };
juce::ComboBox cmbArtTrigNet, cmbArtTrigSub, cmbArtTrigUni;
juce::Label lblArtTrigAddr;
juce::ComboBox cmbArtnetDmxInterface; juce::Label lblArtnetDmxInterface;
juce::ComboBox cmbAudioInputDevice; juce::Label lblAudioInputDevice;
juce::ComboBox cmbAudioInputChannel; juce::Label lblAudioInputChannel;
GainSlider sldLtcInputGain; juce::Label lblLtcInputGain;
LevelMeter mtrLtcInput;
juce::ComboBox cmbThruInputChannel; juce::Label lblThruInputChannel;
GainSlider sldThruInputGain; juce::Label lblThruInputGain;
LevelMeter mtrThruInput;
juce::Label lblInputStatus;
// --- Left panel (scrollable, like right) ---
juce::Viewport leftViewport;
PanelContent leftContent;
// --- Right panel (scrollable) ---
juce::Viewport rightViewport;
PanelContent rightContent;
juce::ComboBox cmbAudioOutputTypeFilter; juce::Label lblAudioOutputTypeFilter;
juce::ComboBox cmbMidiOutputDevice; juce::Label lblMidiOutputDevice;
juce::ComboBox cmbArtnetOutputInterface; juce::Label lblArtnetOutputInterface;
juce::ComboBox cmbAudioOutputDevice; juce::Label lblAudioOutputDevice;
juce::ComboBox cmbAudioOutputChannel; juce::Label lblAudioOutputChannel;
GainSlider sldLtcOutputGain; juce::Label lblLtcOutputGain;
LevelMeter mtrLtcOutput;
juce::ComboBox cmbThruOutputDevice; juce::Label lblThruOutputDevice;
juce::ComboBox cmbThruOutputChannel; juce::Label lblThruOutputChannel;
GainSlider sldThruOutputGain; juce::Label lblThruOutputGain;
LevelMeter mtrThruOutput;
juce::Label lblOutputMtcStatus;
GainSlider sldMtcOffset; juce::Label lblMtcOffset;
juce::Label lblOutputArtnetStatus;
GainSlider sldArtnetOffset; juce::Label lblArtnetOffset;
juce::Label lblOutputLtcStatus;
GainSlider sldLtcOffset; juce::Label lblLtcOffset;
juce::Label lblOutputThruStatus;
juce::TextButton btnRefreshDevices { "Refresh Devices" };
juce::HyperlinkButton btnGitHub { "github.com/fiverecords/SuperTimecodeConverter",
juce::URL("https://github.com/fiverecords/SuperTimecodeConverter") };
// --- Update checker ---
UpdateChecker updateChecker;
juce::HyperlinkButton btnUpdateAvailable { "", juce::URL() };
juce::TextButton btnCheckUpdates { "Check for updates" };
int updateCheckDelay = 0; // ticks to wait before checking
bool updateNotificationShown = false; // true once UI is updated
int updateResetCountdown = 0; // ticks to reset button text
AppSettings settings;
static constexpr int kStereoItemId = 10000;
static constexpr int kPlaceholderItemId = 10001;
// --- Save debounce ---
bool settingsDirty = false;
int settingsSaveCountdown = 0;
static constexpr int kSaveDelayTicks = 30;
// --- Methods ---
void startAudioDeviceScan();
void populateMidiAndNetworkCombos();
void populateAudioCombos();
void populateTypeFilterCombos();
void populateFilteredInputDeviceCombo();
void populateFilteredOutputDeviceCombos();
juce::String getDeviceInUseMarker(const juce::String& devName, const juce::String& typeName, bool isInput);
juce::StringArray getUniqueTypeNames(const juce::Array<AudioDeviceEntry>& entries) const;
juce::String getInputTypeFilter() const;
juce::String getOutputTypeFilter() const;
void loadAndApplyNonAudioSettings();
void applyAudioSettings();
void populateSampleRateCombo();
void populateBufferSizeCombo();
double getPreferredSampleRate() const;
int getPreferredBufferSize() const;
void restartAllAudioDevices();
int findFilteredIndex(const juce::Array<int>& filteredIndices,
const juce::Array<AudioDeviceEntry>& entries,
const juce::String& typeName, const juce::String& deviceName);
AudioDeviceEntry getSelectedAudioInput() const;
AudioDeviceEntry getSelectedAudioOutput() const;
AudioDeviceEntry getSelectedThruOutput() const;
// Engine-level start/stop (gathers params from UI, calls engine methods)
void startCurrentMtcInput();
void startCurrentArtnetInput();
void startCurrentLtcInput();
void startCurrentProDJLinkInput();
void openTrackMapEditor();
void openMixerMapEditor();
void openProDJLinkView();
void exportConfig();
void importConfig();
void applyTriggerSettings();
void propagateGlobalSettings();
void startCurrentThruOutput();
void startCurrentMtcOutput();
void startCurrentArtnetOutput();
void startCurrentLtcOutput();
void updateCurrentOutputStates();
void populateAudioInputChannels();
void populateAudioOutputChannels();
void populateThruOutputChannels();
int getChannelFromCombo(const juce::ComboBox& cmb) const;
void updateInputButtonStates();
void updateFpsButtonStates();
void updateOutputFpsButtonStates();
void updateDeviceSelectorVisibility();
void updateStatusLabels();
void layoutLeftPanel();
void layoutRightPanel();
void saveSettings();
void flushSettings();
int findDeviceByName(const juce::ComboBox& cmb, const juce::String& name);
juce::Colour getInputColour(TimecodeEngine::InputSource source) const;
void styleInputButton(juce::TextButton& btn, bool active, juce::Colour colour);
void styleFpsButton(juce::TextButton& btn, bool active);
void styleOutputToggle(juce::ToggleButton& btn, juce::Colour colour);
void styleComboBox(juce::ComboBox& cmb);
void styleLabel(juce::Label& lbl, float fontSize = 10.0f);
void styleGainSlider(GainSlider& sld);
void styleOffsetSlider(GainSlider& sld);
void styleCollapseButton(juce::TextButton& btn);
void updateCollapseButtonText(juce::TextButton& btn, bool expanded);
// Art-Net port-address helpers (15-bit: Net[7] | Subnet[4] | Universe[4])
static int packArtNetAddress(int net, int sub, int uni)
{
return ((net & 0x7F) << 8) | ((sub & 0x0F) << 4) | (uni & 0x0F);
}
static void unpackArtNetAddress(int addr, int& net, int& sub, int& uni)
{
net = (addr >> 8) & 0x7F;
sub = (addr >> 4) & 0x0F;
uni = addr & 0x0F;
}
void setupArtNetAddressCombos(juce::ComboBox& cmbNet, juce::ComboBox& cmbSub,
juce::ComboBox& cmbUni, juce::Label& lbl,
const juce::String& labelText,
std::function<void()> onChange);
void setArtNetCombosFromAddress(juce::ComboBox& cmbNet, juce::ComboBox& cmbSub,
juce::ComboBox& cmbUni, int portAddress);
int getArtNetAddressFromCombos(const juce::ComboBox& cmbNet, const juce::ComboBox& cmbSub,
const juce::ComboBox& cmbUni);
#if JUCE_WINDOWS
juce::OpenGLContext glContext; // GPU-accelerated rendering (Windows only)
#endif
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainComponent)
};