Repository navigation
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
6589 lines (5381 loc) · 278 KB
/
Copy pathmainwindow.cpp
File metadata and controls
6589 lines (5381 loc) · 278 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
// =========================================================
// INCLUDES & DEPENDENCIES
// =========================================================
#include "ModularSynth.h"
#include "mainwindow.h"
#include <QHBoxLayout>
#include <QGridLayout>
#include <QFileDialog>
#include <QFile>
#include <QScrollArea>
#include <cmath>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <QRegularExpression>
#include <QProgressDialog>
#include <QtXml/QDomDocument>
#include "pcmeditortab.h"
#include "melodyrenderertab.h"
#include "effectstab.h"
#include "vocalgenerator.h"
// =========================================================
// MAIN CONSTRUCTOR
// =========================================================
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
initSamLibrary(); // InitialiSe the new SAM library
m_ghostSynth = new SynthEngine(this);
setupUI();
setWindowTitle("Xpressive Sound Design Suite - Ewan Pettigrew - Uses parts of SAM phonetics code for text to speech test");
}
// =========================================================
// CUSTOM WIDGET IMPLEMENTATIONS
// =========================================================
void WaveformDisplay::updateData(const std::vector<SidSegment>& segments) {
m_segments = segments;
update();
}
void WaveformDisplay::paintEvent(QPaintEvent *) {
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
int w = width(), h = height(), midY = h / 2;
painter.setPen(QColor(200, 200, 200, 100));
painter.drawLine(0, midY, w, midY);
if (m_segments.empty()) return;
double totalDur = 0;
for (const auto& s : m_segments) totalDur += s.duration->value();
double xPos = 0;
for (const auto& s : m_segments) {
double dur = s.duration->value();
double segWidth = (dur / (totalDur > 0 ? totalDur : 1.0)) * w;
QString type = s.waveType->currentText();
painter.setPen(QPen(QColor(0, 120, 215), 2));
QPolygonF poly;
for (int x = 0; x <= (int)segWidth; ++x) {
double localX = (double)x / (segWidth > 0 ? segWidth : 1.0);
double env = std::exp(-localX * dur * s.decay->value());
double phase = x * 0.2;
double osc = (type.contains("square") || type.contains("PWM")) ? ((std::sin(phase) > 0) ? 1 : -1) :
(type.contains("saw") ? (fmod(phase, 6.28) / 3.14) - 1.0 :
(type.contains("triangle") ? (asin(sin(phase)) * (2.0/3.14159)) :
(type.contains("randv") ? ((double)std::rand() / RAND_MAX) * 2 - 1 : std::sin(phase))));
poly << QPointF(xPos + x, midY + (osc * env * (midY - 20)));
}
painter.drawPolyline(poly);
xPos += segWidth;
}
}
// =========================================================
// UI INITIALISATION & SETUP
// =========================================================
void MainWindow::setupUI() {
auto *centralWidget = new QWidget(this);
auto *mainHLayout = new QHBoxLayout(centralWidget);
auto *sidebarGroup = new QGroupBox("Modulation & Arps");
auto *sideScroll = new QScrollArea();
auto *sideContent = new QWidget();
auto *sideLayout = new QVBoxLayout(sideContent);
QStringList mults = {"0.5x", "1x", "2x", "4x"};
for (int i = 0; i < 5; ++i) {
auto *mGroup = new QGroupBox(QString(i < 3 ? "Mod %1" : "PWM Mod %1").arg(i + 1));
auto *mForm = new QFormLayout(mGroup);
mods[i].shape = new QComboBox(); mods[i].shape->addItems({"sinew", "saww", "squarew", "trianglew"});
mods[i].rate = new QDoubleSpinBox(); mods[i].rate->setRange(0.1, 100.0);
mods[i].depth = new QDoubleSpinBox(); mods[i].depth->setRange(0, 1.0);
mods[i].sync = new QCheckBox("Sync to Tempo");
mods[i].multiplier = new QComboBox(); mods[i].multiplier->addItems(mults);
mForm->addRow("Rate:", mods[i].rate); mForm->addRow(mods[i].sync); mForm->addRow("Mult:", mods[i].multiplier); mForm->addRow("Depth:", mods[i].depth);
sideLayout->addWidget(mGroup);
}
for (int i = 0; i < 2; ++i) {
auto *aGroup = new QGroupBox(QString("Arp %1").arg(i + 1));
auto *aForm = new QFormLayout(aGroup);
arps[i].wave = new QComboBox(); arps[i].wave->addItems({"squarew", "trianglew", "saww"});
arps[i].chord = new QComboBox(); arps[i].chord->addItems({"Major", "Minor", "Dim", "Aug"});
arps[i].speed = new QDoubleSpinBox(); arps[i].speed->setRange(1.0, 128.0); arps[i].speed->setValue(16.0);
arps[i].sync = new QCheckBox("Sync to Tempo");
arps[i].multiplier = new QComboBox(); arps[i].multiplier->addItems(mults);
aForm->addRow("Wave:", arps[i].wave); aForm->addRow("Chord:", arps[i].chord); aForm->addRow("Speed:", arps[i].speed); aForm->addRow(arps[i].sync); aForm->addRow("Mult:", arps[i].multiplier);
sideLayout->addWidget(aGroup);
}
chaosSlider = new QSlider(Qt::Horizontal); chaosSlider->setRange(0, 100);
sideScroll->setWidget(sideContent); sideScroll->setWidgetResizable(true);
auto *containerLayout = new QVBoxLayout(sidebarGroup); containerLayout->addWidget(sideScroll);
mainHLayout->addWidget(sidebarGroup, 1);
auto *rightLayout = new QVBoxLayout();
modeTabs = new QTabWidget(this);
mainHLayout->addLayout(rightLayout, 3);
rightLayout->addWidget(modeTabs);
// ------------------------------------
// TAB 0: ABOUT / INFO TAB
// ------------------------------------
QWidget *tab00 = new QWidget();
auto *layout00 = new QVBoxLayout(tab00);
QTextEdit *infoText = new QTextEdit();
infoText->setReadOnly(true);
infoText->setHtml(
"<h2 style='color:#2c3e50;'>Xpressive Companion</h2>"
"<p><b>For LMMS Xpressive</b></p>"
"<hr>"
"<p><b>Author:</b> Ewan Pettigrew<br>"
"<b></b> <br>"
"<b></b> </p>"
"<p><i>This software is 100% Freeware. Do whatever you wish with the code and results.</i></p>"
"<br>"
"<h3>Project Background</h3>"
"<p>Xpressive allows users to program a synthesiser "
"or instrument like an arbitrary waveform generator.</p>"
"<p>Please save your project each time before pasting an expression in as bad expressions can cause crashes"
"</p>"
"<div style='background-color:#f0f8ff; padding:10px; border:1px solid #b0c4de;'>"
"<b></b><br>"
" "
" "
""
""
"</div>"
"<h3>Status & Disclaimers</h3>"
"<ul>"
"<li><b>Status:</b> Work In Progress (WIP). Updated regularly. May contain bugs which I may be aware of.</li>"
"<li><b>Compatibility:</b> Tested on Windows only so far.</li>"
"<li><b>Audio Accuracy:</b> The audio previews are not working properly yet which is on the to do list.</li>"
"</ul>"
);
layout00->addWidget(infoText);
modeTabs->addTab(tab00, "00");
// ------------------------------------
// TAB 1: SID ARCHITECT
// ------------------------------------
QWidget *sidTab = new QWidget(); auto *sidLayout = new QVBoxLayout(sidTab);
auto *sidOptGrid = new QGridLayout();
buildModeSid = new QComboBox(); buildModeSid->addItems({"Modern", "Legacy"});
sidOptGrid->addWidget(new QLabel("Build Mode:"), 0, 0); sidOptGrid->addWidget(buildModeSid, 0, 1);
sidLayout->addLayout(sidOptGrid);
waveVisualizer = new WaveformDisplay(); sidLayout->addWidget(waveVisualizer);
auto *legend = new QLabel("LEGEND: [Wave] [Dur(s)] [Freq Off] [Decay]");
legend->setStyleSheet("font-weight: bold; background: #eee; padding: 5px;");
sidLayout->addWidget(legend);
auto *scroll = new QScrollArea(); auto *scrollW = new QWidget();
sidSegmentsLayout = new QVBoxLayout(scrollW); scroll->setWidget(scrollW); scroll->setWidgetResizable(true);
sidLayout->addWidget(scroll);
auto *sidBtns = new QHBoxLayout();
auto *btnAdd = new QPushButton("Add (+)");
auto *btnClear = new QPushButton("Clear All");
auto *btnSaveSid = new QPushButton("Export SID Chain");
sidBtns->addWidget(btnAdd); sidBtns->addWidget(btnClear); sidBtns->addWidget(btnSaveSid);
sidLayout->addLayout(sidBtns);
modeTabs->addTab(sidTab, "SID Architect");
// ------------------------------------
// TAB 2: PCM SAMPLER
// ------------------------------------
QWidget *pcmTab = new QWidget();
auto *pcmLayout = new QVBoxLayout(pcmTab);
// VISUALISER
pcmScope = new UniversalScope();
pcmLayout->addWidget(pcmScope);
// ZOOM SLIDER
auto *pcmZoomLay = new QHBoxLayout();
pcmZoomLay->addWidget(new QLabel("Scope Zoom:"));
pcmZoomSlider = new QSlider(Qt::Horizontal);
pcmZoomSlider->setRange(0, 100);
pcmZoomSlider->setValue(10);
pcmZoomLay->addWidget(pcmZoomSlider);
pcmLayout->addLayout(pcmZoomLay);
//DISCLAIMER (The Warning)
pcmDisclaimer = new QLabel("\n"
"\n"
"");
pcmDisclaimer->setStyleSheet("QLabel { color: red; font-weight: bold; font-size: 14px; border: 2px solid red; padding: 10px; background-color: #ffeeee; }");
pcmDisclaimer->setAlignment(Qt::AlignCenter);
pcmDisclaimer->setFixedHeight(80);
pcmLayout->addWidget(pcmDisclaimer);
// CONTROLS
auto *btnLoad = new QPushButton("Load WAV");
btnSave = new QPushButton("Generate String");
btnCopy = new QPushButton("Copy Clipboard");
pcmLayout->addWidget(btnLoad);
pcmLayout->addWidget(btnSave);
pcmLayout->addWidget(btnCopy);
auto *pcmGrid = new QGridLayout();
buildModeCombo = new QComboBox(); buildModeCombo->addItems({"Modern", "Legacy"});
sampleRateCombo = new QComboBox(); sampleRateCombo->addItems({"16000", "8000", "4000", "2000"});
bitDepthCombo = new QComboBox(); bitDepthCombo->addItems({"4-bit (Gritty)", "8-bit (Clean)", "Uncompressed (Raw)"});
maxDurSpin = new QDoubleSpinBox(); maxDurSpin->setRange(0.01, 600.0); maxDurSpin->setValue(2.0);
normalizeCheck = new QCheckBox("Normalize Audio"); normalizeCheck->setChecked(true);
pcmGrid->addWidget(new QLabel("Build Mode:"), 0, 0); pcmGrid->addWidget(buildModeCombo, 0, 1);
pcmGrid->addWidget(new QLabel("Rate:"), 1, 0); pcmGrid->addWidget(sampleRateCombo, 1, 1);
pcmGrid->addWidget(new QLabel("Bit Depth:"), 2, 0); pcmGrid->addWidget(bitDepthCombo, 2, 1);
pcmGrid->addWidget(new QLabel("Max(s):"), 3, 0); pcmGrid->addWidget(maxDurSpin, 3, 1);
pcmLayout->addLayout(pcmGrid);
pcmLayout->addWidget(normalizeCheck);
modeTabs->addTab(pcmTab, "PCM Sampler");
// SCOPE ZOOM LOGIC
connect(pcmZoomSlider, &QSlider::valueChanged, [=]() {
if(originalData.empty()) return;
double dur = (double)originalData.size() / fileFs;
double zoom = pcmZoomSlider->value() / 100.0;
pcmScope->updateScope([=](double t){
int idx = (int)(t * fileFs);
if(idx >= 0 && idx < originalData.size()) return originalData[idx];
return 0.0;
}, dur, zoom);
});
// ------------------------------------
// TAB 3 : CONSOLE LAB
// ------------------------------------
QWidget *consoleTab = new QWidget();
auto *consoleLayout = new QVBoxLayout(consoleTab);
//OSCILLOSCOPE
consoleScope = new UniversalScope();
consoleScope->setMinimumHeight(150);
consoleLayout->addWidget(consoleScope);
//CONTROLS
auto *cForm = new QFormLayout();
buildModeConsole = new QComboBox(); buildModeConsole->addItems({"Modern", "Legacy"});
consoleWaveType = new QComboBox();
consoleWaveType->addItems({
"00. NES Triangle (Pseudo-Tri)",
"01. NES Pulse 12.5% (Thin)",
"02. NES Pulse 25% (Classic)",
"03. NES Pulse 50% (Square)",
"04. Gameboy Soft Saw (No DC)",
"05. Gameboy Noise (Polynomial)",
"06. C64 Sawtooth (Ramp)",
"07. C64 Triangle (Analogue)",
"08. C64 Pulse (Width Sweep)",
"09. C64 Ring Mod (Bell)",
"10. VRC6 Sawtooth (Expanded)",
"11. VRC6 Pulse (Duty Cycle)",
"12. Famicom Disk System (Mod)",
"13. Master System Tone (Flat)",
"14. PC Engine Organ (50/50)",
"15. 2600 Pitched Noise",
"16. 2600 Pure Square",
"17. Konami SCC (Wavetable Sim)",
"18. Namco 163 (4-bit Sine)",
"19. Sega Genesis (FM Bass)",
"20. Sega Genesis (FM Bell)",
"21. Amiga 500 (Sample Hold)"
});
consoleSteps = new QDoubleSpinBox(); consoleSteps->setValue(16);
cForm->addRow("Build Mode:", buildModeConsole);
cForm->addRow("Type:", consoleWaveType);
cForm->addRow("Quantize Steps:", consoleSteps);
consoleLayout->addLayout(cForm);
//PLAY / GENERATE BUTTONS
auto *cBtnLayout = new QHBoxLayout();
auto *btnPlayConsole = new QPushButton("▶ Play A-5 (880Hz)");
btnPlayConsole->setCheckable(true);
btnPlayConsole->setStyleSheet("background-color: #335533; color: white; font-weight: bold;");
auto *btnGenConsole = new QPushButton("Generate String");
cBtnLayout->addWidget(btnPlayConsole);
cBtnLayout->addWidget(btnGenConsole);
consoleLayout->addLayout(cBtnLayout);
consoleLayout->addStretch();
modeTabs->addTab(consoleTab, "Console Lab");
//LOGIC EXTRACTION
auto updateConsole = [=]() {
int type = consoleWaveType->currentIndex();
double steps = consoleSteps->value();
double f = 880.0; // A-5 Frequency
// THE MATH ROUTINE
std::function<double(double)> audioRoutine = [=](double t) {
double signal = 0.0;
double pi = 3.14159;
double ph = t * f; // Basic Phase
//Pulse Width
auto pulse = [&](double w) { return std::sin(2.0*pi*ph) > w ? 1.0 : -1.0; };
auto tri = [&]() { return (2.0/pi)*std::asin(std::sin(2.0*pi*ph)); };
auto saw = [&]() { return 2.0 * (ph - std::floor(0.5 + ph)); };
switch(type) {
case 0: signal = tri(); break; // NES Tri
case 1: signal = pulse(0.75); break; // 12.5%
case 2: signal = pulse(0.5); break; // 25%
case 3: signal = pulse(0.0); break; // 50%
case 4: signal = saw() * 0.8; break; // Soft Saw
case 5: signal = ((std::rand() % 100) / 50.0) - 1.0; break; // Noise
case 6: signal = saw(); break; // Sharp Saw
case 7: signal = tri() + (0.1 * saw()); break; // Dirty Tri
case 8: signal = pulse(std::sin(t * 3.0)); break; // PWM Sweep
case 9: signal = pulse(0.0) * pulse(0.95); break; // Ring Mod
case 10: signal = (saw() * 0.5) + (pulse(0.0) * 0.5); break; // VRC Saw
case 11: signal = pulse(0.8); break; // VRC Pulse
case 12: signal = std::sin(2.0*pi*ph + std::sin(2.0*pi*t*6.0)); break; // FDS
case 13: signal = pulse(-0.2); break; // Master System
case 14: signal = (pulse(0.0) + pulse(0.1)) * 0.5; break; // PC Engine
case 15: signal = ((std::rand()%100 > 50 ? 1 : -1) * pulse(0.0)); break; // 2600
case 16: signal = pulse(0.0); break; // 2600 Square
case 17: signal = saw() * (tri() > 0 ? 1 : -1); break; // SCC
case 18: signal = std::sin(2.0*pi*ph); break; // Namco Sine
case 19: signal = std::sin(2.0*pi*ph + 3.0*std::sin(2.0*pi*ph*0.5)); break; // Genesis Bass
case 20: signal = std::sin(2.0*pi*ph) * std::exp(-t*10.0); break; // Genesis Bell
case 21: signal = saw(); break; // Amiga
}
// Bit-Crush
if (steps > 0) signal = std::floor(signal * steps) / steps;
return signal;
};
//Update VisualiSer
// Slower "fake" frequency for the scope so the wave shape is visible
std::function<double(double)> visRoutine = [=](double t) {
double ratio = 80.0 / f; // Scale 880Hz down to 80Hz for viewing
return audioRoutine(t * ratio);
};
consoleScope->updateScope(visRoutine, 1.0, 0.1);
// Update Audio (Only if playing)
if(btnPlayConsole->isChecked()) {
m_ghostSynth->setAudioSource(audioRoutine);
}
};
// CONNECTIONS
connect(consoleWaveType, QOverload<int>::of(&QComboBox::currentIndexChanged), updateConsole);
connect(consoleSteps, &QDoubleSpinBox::valueChanged, updateConsole);
// PLAY BUTTON LOGIC
connect(btnPlayConsole, &QPushButton::toggled, [=](bool checked){
if(!checked) {
m_ghostSynth->setAudioSource([](double){ return 0.0; });
m_ghostSynth->stop();
btnPlayConsole->setText("▶ Play A-5 (880Hz)");
btnPlayConsole->setStyleSheet("background-color: #335533; color: white;");
} else {
btnPlayConsole->setText("⏹ Stop");
btnPlayConsole->setStyleSheet("background-color: #338833; color: white;");
m_ghostSynth->start();
// Trigger the update logic to start the sound
updateConsole();
}
});
connect(btnGenConsole, &QPushButton::clicked, this, &MainWindow::generateConsoleWave);
// Initial Trigger to draw the default wave
QTimer::singleShot(100, updateConsole);
// ------------------------------------
// TAB 4: SFX MACRO
// ------------------------------------
QWidget *sfxTab = new QWidget();
auto *sfxLayout = new QVBoxLayout(sfxTab);
// OSCILLOSCOPE
sfxScope = new UniversalScope();
sfxScope->setMinimumHeight(150);
sfxLayout->addWidget(sfxScope);
// CONTROLS
auto *sfxForm = new QFormLayout();
buildModeSFX = new QComboBox(); buildModeSFX->addItems({"Modern", "Legacy"});
sfxStartFreq = new QDoubleSpinBox(); sfxStartFreq->setRange(20, 20000); sfxStartFreq->setValue(880);
sfxEndFreq = new QDoubleSpinBox(); sfxEndFreq->setRange(20, 20000); sfxEndFreq->setValue(110);
sfxDur = new QDoubleSpinBox(); sfxDur->setValue(0.2);
sfxForm->addRow("Build Mode:", buildModeSFX);
sfxForm->addRow("Start (Hz):", sfxStartFreq);
sfxForm->addRow("End (Hz):", sfxEndFreq);
sfxForm->addRow("Dur (s):", sfxDur);
sfxLayout->addLayout(sfxForm);
// PLAY / GENERATE BUTTONS
auto *sfxBtnLay = new QHBoxLayout();
auto *btnPlaySFX = new QPushButton("▶ Play SFX Loop");
btnPlaySFX->setCheckable(true);
btnPlaySFX->setStyleSheet("background-color: #335533; color: white; font-weight: bold; height: 40px;");
auto *btnGenSFX = new QPushButton("Generate SFX String");
btnGenSFX->setStyleSheet("height: 40px;");
sfxBtnLay->addWidget(btnPlaySFX);
sfxBtnLay->addWidget(btnGenSFX);
sfxLayout->addLayout(sfxBtnLay);
sfxLayout->addStretch();
modeTabs->addTab(sfxTab, "SFX Macro");
auto updateSFX = [=]() {
double fStart = sfxStartFreq->value();
double fEnd = sfxEndFreq->value();
double dur = sfxDur->value();
std::function<double(double)> sfxAlgo = [=](double t) {
// Silence after duration
if (t > dur) return 0.0;
if (t < 0) return 0.0;
if (dur <= 0.001) return 0.0;
// Calculate 'k' for the exponential curve: f(t) = fStart * exp(k*t)
// If fEnd < fStart, k will be negative (decay)
double k = std::log(fEnd / fStart) / dur;
// Handle constant pitch (k ~= 0) to avoid divide-by-zero
if (std::abs(k) < 0.0001) {
return std::sin(t * fStart * 2.0 * 3.14159);
}
// Integral of f(t) is (1/k) * f(t)
double phase = (fStart / k) * (std::exp(k * t) - 1.0);
return std::sin(phase * 2.0 * 3.14159);
};
// Update Scope
sfxScope->updateScope(sfxAlgo, dur * 1.2, 1.0);
// Update Audio (If Playing)
if (btnPlaySFX->isChecked()) {
// Create a loop with a small silence gap so you can hear the attack again
double loopLen = dur + 0.5;
m_ghostSynth->setAudioSource([=](double t){
return sfxAlgo(std::fmod(t, loopLen));
});
}
};
// CONNECTIONS
connect(sfxStartFreq, &QDoubleSpinBox::valueChanged, updateSFX);
connect(sfxEndFreq, &QDoubleSpinBox::valueChanged, updateSFX);
connect(sfxDur, &QDoubleSpinBox::valueChanged, updateSFX);
connect(btnPlaySFX, &QPushButton::toggled, [=](bool checked){
if(!checked) {
m_ghostSynth->setAudioSource([](double){ return 0.0; });
m_ghostSynth->stop();
btnPlaySFX->setText("▶ Play SFX Loop");
btnPlaySFX->setStyleSheet("background-color: #335533; color: white; font-weight: bold; height: 40px;");
} else {
m_ghostSynth->start();
btnPlaySFX->setText("⏹ Stop");
btnPlaySFX->setStyleSheet("background-color: #338833; color: white; font-weight: bold; height: 40px;");
updateSFX(); // Trigger the sound immediately
}
});
connect(btnGenSFX, &QPushButton::clicked, this, &MainWindow::generateSFXMacro);
QTimer::singleShot(200, updateSFX);
// ------------------------------------
// TAB 5: ARP ANIMATOR
// ------------------------------------
QWidget *arpTab = new QWidget();
auto *arpLayout = new QVBoxLayout(arpTab);
// VISUALISER
arpScope = new UniversalScope();
arpScope->setMinimumHeight(150);
arpLayout->addWidget(arpScope);
// OSCILLATOR
auto *oscGroup = new QGroupBox("SID Oscillator");
auto *oscForm = new QFormLayout(oscGroup);
buildModeArp = new QComboBox();
buildModeArp->addItems({"Nightly (Nested - Clean)", "Legacy (Additive)"});
arpWave = new QComboBox();
arpWave->addItems({"Pulse (Classic)", "Sawtooth", "Triangle", "Noise (Percussion)", "Metal (Ring Mod)"});
arpPwmSlider = new QSlider(Qt::Horizontal);
arpPwmSlider->setRange(1, 99);
arpPwmSlider->setValue(50); // Square wave default
oscForm->addRow("Build Mode:", buildModeArp);
oscForm->addRow("Waveform:", arpWave);
oscForm->addRow("Pulse Width:", arpPwmSlider);
arpLayout->addWidget(oscGroup);
// THE CHORD
auto *seqGroup = new QGroupBox("Chord Sequence (0 -> Step 2 -> Step 3)");
auto *seqForm = new QFormLayout(seqGroup);
QStringList intervals = {
"0 (Root)", "+3 (Minor 3rd)", "+4 (Major 3rd)", "+5 (4th)",
"+7 (Perfect 5th)", "+12 (Octave)", "-12 (Sub Octave)",
"+19 (Octave+5th)", "+24 (2 Octaves)"
};
arpInterval1 = new QComboBox(); arpInterval1->addItems(intervals);
arpInterval1->setCurrentIndex(2); // Major 3rd default
arpInterval2 = new QComboBox(); arpInterval2->addItems(intervals);
arpInterval2->setCurrentIndex(4); // Perfect 5th default
seqForm->addRow("Step 2 Note:", arpInterval1);
seqForm->addRow("Step 3 Note:", arpInterval2);
arpLayout->addWidget(seqGroup);
//SPEED & SYNC ---
auto *spdGroup = new QGroupBox("Speed / Tempo");
auto *spdForm = new QFormLayout(spdGroup);
arpBpmSync = new QCheckBox("Sync to BPM");
arpBpmSync->setChecked(true);
arpBpmVal = new QDoubleSpinBox();
arpBpmVal->setRange(40, 300);
arpBpmVal->setValue(125); // Classic Techno/Chiptune tempo
arpSpeedDiv = new QComboBox();
arpSpeedDiv->addItems({"1/16 (Standard)", "1/32 (Fast)", "1/48 (Triplets)", "1/64 (Hubbard Speed)", "50Hz (PAL Frame)"});
arpSpeedDiv->setCurrentIndex(3); // Default to "Hubbard Speed"
arpSpeed = new QDoubleSpinBox();
arpSpeed->setRange(0.1, 1000);
arpSpeed->setValue(50);
arpSpeed->setVisible(false);
spdForm->addRow(arpBpmSync);
spdForm->addRow("Song BPM:", arpBpmVal);
spdForm->addRow("Grid Size:", arpSpeedDiv);
spdForm->addRow("Manual Hz:", arpSpeed);
arpLayout->addWidget(spdGroup);
// BUTTONS LAYOUT
auto *arpBtnLay = new QHBoxLayout();
btnPlayArp = new QPushButton("▶ Play Arp");
btnPlayArp->setCheckable(true);
btnPlayArp->setStyleSheet("background-color: #335533; color: white; font-weight: bold; height: 40px;");
auto *btnGenArp = new QPushButton("GENERATE C64 ARP");
btnGenArp->setStyleSheet("font-weight: bold; background-color: #444; color: white; height: 40px;");
arpBtnLay->addWidget(btnPlayArp);
arpBtnLay->addWidget(btnGenArp);
arpLayout->addLayout(arpBtnLay);
// LOGIC TO TOGGLE INPUTS
connect(arpBpmSync, &QCheckBox::toggled, [=](bool checked){
arpBpmVal->setVisible(checked);
arpSpeedDiv->setVisible(checked);
arpSpeed->setVisible(!checked);
});
modeTabs->addTab(arpTab, "Arp Animator");
// LIVE PREVIEW LOGIC
auto updateArpPreview = [=]() {
// Calculate Frequency (Speed)
double hz = 0;
if (arpBpmSync->isChecked()) {
double bpm = arpBpmVal->value();
int divIdx = arpSpeedDiv->currentIndex();
if (divIdx == 4) hz = 50.0; // PAL Frame
else {
double multiplier = (divIdx == 0) ? 4.0 : (divIdx == 1) ? 8.0 : (divIdx == 2) ? 12.0 : 16.0;
hz = (bpm / 60.0) * multiplier;
}
} else {
hz = arpSpeed->value();
}
// Get Intervals
auto getSemi = [](QString s) { return s.split(" ")[0].toInt(); };
int semi1 = 0;
int semi2 = getSemi(arpInterval1->currentText());
int semi3 = getSemi(arpInterval2->currentText());
double p1 = 1.0;
double p2 = std::pow(2.0, semi2 / 12.0);
double p3 = std::pow(2.0, semi3 / 12.0);
// Get Waveform Parameters
int wType = arpWave->currentIndex(); // 0=Pulse, 1=Saw, 2=Tri, 3=Noise, 4=Metal
double pwm = (arpPwmSlider->value() / 100.0) * 2.0 - 1.0; // Map -1 to 1
// Build Lambda
std::function<double(double)> arpFunc = [=](double t) {
// Determine Step (0, 1, 2)
// Using a slightly offset time to ensure step 0 starts immediately
int step = (int)(t * hz) % 3;
double mult = (step == 0) ? p1 : (step == 1 ? p2 : p3);
double f = 220.0; // Preview Pitch (A3)
double pi = 3.14159;
double ph = t * f * mult; // Phase
// Oscillators
if (wType == 0) { // Pulse
return (std::sin(ph * 2 * pi) > pwm) ? 1.0 : -1.0;
}
else if (wType == 1) { // Saw
double x = std::fmod(ph, 1.0);
return 2.0 * x - 1.0;
}
else if (wType == 2) { // Triangle
return (2.0 / pi) * std::asin(std::sin(ph * 2 * pi));
}
else if (wType == 3) { // Noise
return ((double)std::rand() / RAND_MAX) * 2.0 - 1.0;
}
else { // Metal (Ring Mod)
// Square * Detuned Square (approx 2.41 ratio)
double sq1 = (std::sin(ph * 2 * pi) > 0) ? 1.0 : -1.0;
double sq2 = (std::sin(ph * 2.41 * 2 * pi) > 0) ? 1.0 : -1.0;
return sq1 * sq2;
}
};
// Update Scope (Show 4 beats worth or enough to see pattern)
double viewDur = (hz > 0) ? (4.0 / hz) : 1.0;
arpScope->updateScope(arpFunc, viewDur, 1.0);
// Update Audio
if(btnPlayArp->isChecked()) {
m_ghostSynth->setAudioSource(arpFunc);
}
};
// --- CONNECTIONS ---
connect(btnGenArp, &QPushButton::clicked, this, &MainWindow::generateArpAnimator);
// Connect Play Button
connect(btnPlayArp, &QPushButton::toggled, [=](bool checked){
if(!checked) {
m_ghostSynth->setAudioSource([](double){ return 0.0; });
m_ghostSynth->stop();
btnPlayArp->setText("▶ Play Arp");
btnPlayArp->setStyleSheet("background-color: #335533; color: white; font-weight: bold; height: 40px;");
} else {
m_ghostSynth->start();
btnPlayArp->setText("⏹ Stop");
btnPlayArp->setStyleSheet("background-color: #338833; color: white; font-weight: bold; height: 40px;");
updateArpPreview();
}
});
// Connect Inputs to Update Logic
QList<QWidget*> arpWidgets = {
arpWave, arpInterval1, arpInterval2, arpSpeedDiv, arpBpmSync,
arpBpmVal, arpSpeed, arpPwmSlider
};
for(auto *w : arpWidgets) {
if(auto *cb = qobject_cast<QComboBox*>(w)) connect(cb, QOverload<int>::of(&QComboBox::currentIndexChanged), updateArpPreview);
if(auto *sb = qobject_cast<QDoubleSpinBox*>(w)) connect(sb, &QDoubleSpinBox::valueChanged, updateArpPreview);
if(auto *sl = qobject_cast<QSlider*>(w)) connect(sl, &QSlider::valueChanged, updateArpPreview);
if(auto *chk = qobject_cast<QCheckBox*>(w)) connect(chk, &QCheckBox::toggled, updateArpPreview);
}
// Initial Trigger
QTimer::singleShot(200, updateArpPreview);
// ------------------------------------
// TAB 6: WAVETABLE FORGE
// ------------------------------------
QWidget *wtTab = new QWidget();
auto *wtLayout = new QVBoxLayout(wtTab);
// SCOPE
wtScope = new UniversalScope();
wtScope->setMinimumHeight(150);
wtLayout->addWidget(wtScope);
// HEADER
auto *wtHeader = new QHBoxLayout();
wtHeader->addWidget(new QLabel("Build Mode:"));
buildModeWavetable = new QComboBox();
buildModeWavetable->addItems({"Nightly (Nested)", "Legacy (Additive)"});
wtHeader->addWidget(buildModeWavetable);
wtHeader->addWidget(new QLabel("| Master Library:"));
wtPresetCombo = new QComboBox();
QStringList presets;
presets << "--- INIT ---" << "00. Empty / Init";
presets << "--- ROB HUBBARD ---" << "01. Commando Bass (Glissando)" << "02. Monty Lead (Pulse+Vib)" << "03. Delta Snare (Tri-Noise)" << "04. Zoids Metal (Ring Mod)" << "05. Ace 2 Kick (Deep)" << "06. Crazy Comets (Echo)";
presets << "--- MARTIN GALWAY ---" << "07. Wizball Arp (Bubble)" << "08. Parallax Bass (Slap)" << "09. Comic Bakery (Lead)" << "10. Arkanoid (Dotted Echo)" << "11. Green Beret (Military Snare)";
presets << "--- JEROEN TEL ---" << "12. Cybernoid Metal Drum" << "13. Supremacy Lead (Vibrato)" << "14. Turbo Outrun (Bass)" << "15. RoboCop 3 (Title Arp)";
presets << "--- CHRIS HUELSBECK ---" << "16. Turrican I (Huge Arp)" << "17. Turrican II (Pad)" << "18. Katakis (Space Lead)" << "19. Great Giana (Bass)";
presets << "--- TIM FOLLIN ---" << "20. Solstice (Intro Lead)" << "21. Ghouls'n'Ghosts (Rain)" << "22. Silver Surfer (Arp)" << "23. LED Storm (Bass)";
presets << "--- BEN DAGLISH ---" << "24. Last Ninja (Dark Bass)" << "25. Deflektor (Lead)" << "26. Trap (Fast Arp)";
presets << "--- DAVID WHITTAKER ---" << "27. Glider Rider (Square)" << "28. Lazy Jones (Laser)";
presets << "--- YM / ATARI ST MASTERS ---" << "29. YM Buzzer Envelope" << "30. YM Metal Bass" << "31. YM 3-Voice Chord" << "32. Digi-Drum (SID-Style)";
presets << "--- FX / DRUMS (Utility) ---" << "33. Coin (Mario Style)" << "34. Power Up" << "35. Explosion (Noise Decay)" << "36. Laser (Pew Pew)" << "37. 8-Bit Hi-Hat (Closed)" << "38. 8-Bit Hi-Hat (Open)" << "39. Fake Chord (Minor)" << "40. Fake Chord (Major)" << "--- SID DRUMS EXPANSION ---" << "41. Heavy SID Kick (Square Drop)" << "42. Snappy Snare (Tri+Noise)" << "43. Tech Kick (Metal+Pulse)" << "44. Glitch Snare (Ring Mod)";
wtPresetCombo->addItems(presets);
wtHeader->addWidget(wtPresetCombo);
wtLoopCheck = new QCheckBox("Loop Sequence");
wtHeader->addWidget(wtLoopCheck);
wtLayout->addLayout(wtHeader);
// TABLE
wtTrackerTable = new QTableWidget();
wtTrackerTable->setColumnCount(4);
wtTrackerTable->setHorizontalHeaderLabels({"Waveform", "Pitch (+/-)", "PWM %", "Dur (s)"});
wtTrackerTable->setSelectionBehavior(QAbstractItemView::SelectRows);
wtTrackerTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
wtLayout->addWidget(wtTrackerTable);
// BUTTONS
auto *wtBtnLayout = new QHBoxLayout();
auto *btnAddStep = new QPushButton("Add Step (+)");
auto *btnRemStep = new QPushButton("Remove Step (-)");
auto *btnPlayWT = new QPushButton("▶ Play Sequence");
btnPlayWT->setCheckable(true);
btnPlayWT->setStyleSheet("background-color: #335533; color: white; font-weight: bold; height: 40px;");
auto *btnGenWT = new QPushButton("GENERATE SEQUENCE");
btnGenWT->setStyleSheet("font-weight: bold; background-color: #444; color: white; height: 40px;");
wtBtnLayout->addWidget(btnPlayWT);
wtBtnLayout->addWidget(btnAddStep);
wtBtnLayout->addWidget(btnRemStep);
wtLayout->addLayout(wtBtnLayout);
wtLayout->addWidget(btnGenWT);
modeTabs->addTab(wtTab, "Wavetable Forge");
// UPDATE LOGIC
auto updateWavetable = [=]() {
int rows = wtTrackerTable->rowCount();
if (rows == 0) return;
struct StepData { int type; double pitchMult; double pwm; double duration; };
std::vector<StepData> sequence;
double totalDur = 0;
for(int i=0; i<rows; ++i) {
if (!wtTrackerTable->item(i, 0) || !wtTrackerTable->item(i, 1) ||
!wtTrackerTable->item(i, 2) || !wtTrackerTable->item(i, 3))
continue;
QString tStr = wtTrackerTable->item(i, 0)->text().toLower();
int pVal = wtTrackerTable->item(i, 1)->text().toInt();
double pwmVal = wtTrackerTable->item(i, 2)->text().toDouble() / 100.0;
double durVal = wtTrackerTable->item(i, 3)->text().toDouble();
totalDur += durVal;
int type = 0;
if (tStr.contains("tri") && tStr.contains("noise")) type = 5;
else if (tStr.contains("tri")) type = 1;
else if (tStr.contains("pulse")) type = 2;
else if (tStr.contains("noise")) type = 3;
else if (tStr.contains("metal")) type = 4;
else if (tStr.contains("sync")) type = 6;
sequence.push_back({type, std::pow(2.0, pVal/12.0), pwmVal, durVal});
}
bool loop = wtLoopCheck->isChecked();
// Audio Function
std::function<double(double)> audioRoutine = [=](double t) {
double localT = t;
if (loop && totalDur > 0) localT = std::fmod(t, totalDur);
else if (t > totalDur) return 0.0;
double scanT = 0;
int activeStep = -1;
for(size_t i=0; i<sequence.size(); ++i) {
if (localT >= scanT && localT < (scanT + sequence[i].duration)) {
activeStep = i; break;
}
scanT += sequence[i].duration;
}
if (activeStep == -1) return 0.0;
const StepData& s = sequence[activeStep];
double f = 440.0; double pi = 3.14159;
double ph = localT * f * s.pitchMult;
auto saw = [](double x) { return 2.0 * (x - std::floor(0.5 + x)); };
auto tri = [&](double x) { return (2.0/pi)*std::asin(std::sin(2.0*pi*x)); };
auto pulse = [&](double x, double w) { return std::sin(2.0*pi*x) > w ? 1.0 : -1.0; };
// Thread-Safe Noise
auto noise = [](double x) { return std::sin(x * 43758.5453) * std::sin(x * 12.9898); };
switch(s.type) {
case 0: return saw(ph);
case 1: return tri(ph);
case 2: return pulse(ph, (s.pwm * 2.0) - 1.0);
case 3: return noise(localT * 10000.0);
case 4: return pulse(ph, 0.0) * pulse(ph * 2.41, 0.0);
case 5: return tri(ph) + (0.5 * noise(localT * 10000.0));
case 6: return saw(ph) * saw(ph * 0.5);
}
return 0.0;
};
wtScope->updateScope(audioRoutine, totalDur > 0 ? totalDur : 1.0, 1.0);
if(btnPlayWT->isChecked()) {
m_ghostSynth->setAudioSource(audioRoutine);
}
};
// CONNECTIONS
connect(wtPresetCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int i){
loadWavetablePreset(i);
// Force the scope to update with the new data
updateWavetable();
});
connect(btnGenWT, &QPushButton::clicked, this, &MainWindow::generateWavetableForge);
connect(wtTrackerTable, &QTableWidget::cellChanged, updateWavetable);
connect(btnPlayWT, &QPushButton::toggled, [=](bool checked){
if(!checked) {
m_ghostSynth->setAudioSource([](double){ return 0.0; });
m_ghostSynth->stop();
btnPlayWT->setText("▶ Play Sequence");
btnPlayWT->setStyleSheet("background-color: #335533; color: white;");
} else {
m_ghostSynth->start();
btnPlayWT->setText("⏹ Stop");
btnPlayWT->setStyleSheet("background-color: #338833; color: white;");
updateWavetable();
}
});
connect(btnAddStep, &QPushButton::clicked, [=](){
int row = wtTrackerTable->rowCount();
wtTrackerTable->insertRow(row);
wtTrackerTable->setItem(row, 0, new QTableWidgetItem("Saw"));
wtTrackerTable->setItem(row, 1, new QTableWidgetItem("0"));
wtTrackerTable->setItem(row, 2, new QTableWidgetItem("50"));
wtTrackerTable->setItem(row, 3, new QTableWidgetItem("0.05"));
updateWavetable();
});
connect(btnRemStep, &QPushButton::clicked, [=](){
if (wtTrackerTable->rowCount() > 0) {
wtTrackerTable->removeRow(wtTrackerTable->rowCount()-1);
updateWavetable();
}
});
// Initial Load
loadWavetablePreset(1);
QTimer::singleShot(200, updateWavetable);
// ------------------------------------
// TAB 7: BESSEL FM
// ------------------------------------
QWidget *besselTab = new QWidget(); auto *besselLayout = new QVBoxLayout(besselTab);
besselSpectrum = new UniversalSpectrum();
besselLayout->addWidget(besselSpectrum);
auto *bForm = new QFormLayout();
buildModeBessel = new QComboBox(); buildModeBessel->addItems({"Modern", "Legacy"});
besselPresetCombo = new QComboBox();
besselPresetCombo->addItems({
"-- CATEGORY: KEYS --", "01. DX7 Electric Piano", "02. Glass Tines", "03. Dig-it-al Harp", "04. 80s FM Organ", "05. Toy Piano", "06. Celestial Keys", "07. Polished Brass", "08. Log Drum Keys",
"-- CATEGORY: BASS --", "09. LatelyBass (TX81Z)", "10. Solid Bass", "11. Rubber Bass", "12. Wood Bass", "13. Slap FM Bass", "14. Sub-Thump", "15. Metallic Drone", "16. Acid FM",
"-- CATEGORY: BELLS/PERC --", "17. Tubular Bells", "18. Gamelan", "19. Marimba FM", "20. Cowbell (808 style)", "21. FM Snare Crack", "22. Metallic Tom", "23. Wind Chimes", "24. Ice Bell", "25. Church Bell",
"-- CATEGORY: PADS/LEAD --", "26. Arctic Pad", "27. FM Flute", "28. Oboe-ish", "29. Sync-Lead FM", "30. Space Reed", "31. Harmonic Swell", "32. Thin Pulse Lead", "33. Bottle Blow",
"-- CATEGORY: FX/NOISE --", "34. Laser Harp", "35. Sci-Fi Computer", "36. Industrial Clang", "37. Digital Rain", "38. Alarm Pulse", "39. Glitch Burst", "40. 8-Bit Explosion"
});
besselCarrierWave = new QComboBox(); besselCarrierWave->addItems({"sinew", "saww", "squarew", "trianglew"});
besselModWave = new QComboBox(); besselModWave->addItems({"sinew", "saww", "squarew", "trianglew"});
besselCarrierMult = new QDoubleSpinBox(); besselCarrierMult->setRange(0, 64); besselCarrierMult->setValue(1.0);
besselModMult = new QDoubleSpinBox(); besselModMult->setRange(0, 64); besselModMult->setValue(2.0);
besselModIndex = new QDoubleSpinBox(); besselModIndex->setRange(0, 100); besselModIndex->setValue(2.0);
bForm->addRow("Build Mode:", buildModeBessel);
bForm->addRow("80s LIBRARY:", besselPresetCombo);
bForm->addRow("Carrier Wave:", besselCarrierWave);
bForm->addRow("Carrier Mult (C):", besselCarrierMult);
bForm->addRow("Modulator Wave:", besselModWave);
bForm->addRow("Modulator Mult (M):", besselModMult);
bForm->addRow("Mod Index (I):", besselModIndex);
besselLayout->addLayout(bForm);
auto *btnBes = new QPushButton("Generate Bessel FM");
besselLayout->addWidget(btnBes);
// FM math for the visualiser
auto updateBesselVisual = [=]() {
if (!besselSpectrum) return;
// Get values from the UI
double cMult = besselCarrierMult->value();
double mMult = besselModMult->value();
double index = besselModIndex->value();
// Define the Math (Standard FM Synthesis)
// t = time, f = frequency (we use 220Hz for visualization)
std::function<double(double)> fmAlgo = [=](double t) {
double f = 220.0;
double twoPi = 6.283185;
// Simple Sine FM: sin( c*t + I*sin(m*t) )
double modulator = index * std::sin(t * f * mMult * twoPi);
double carrier = std::sin((t * f * cMult * twoPi) + modulator);
return carrier;
};
// Send to Spectrum (Sample Rate 44100 for high detail)
besselSpectrum->updateSpectrum(fmAlgo, 44100.0);
};
// Connect Sliders so it updates instantly
connect(besselCarrierMult, &QDoubleSpinBox::valueChanged, updateBesselVisual);
connect(besselModMult, &QDoubleSpinBox::valueChanged, updateBesselVisual);
connect(besselModIndex, &QDoubleSpinBox::valueChanged, updateBesselVisual);
// Run once to initialize
QTimer::singleShot(100, updateBesselVisual);
modeTabs->addTab(besselTab, "Bessel FM");
// ------------------------------------
// TAB 8: HARMONIC LAB
// ------------------------------------
QWidget *harTab = new QWidget();
auto *harLayout = new QVBoxLayout(harTab);
harmonicSpectrum = new UniversalSpectrum();
harLayout->addWidget(harmonicSpectrum);
buildModeHarmonic = new QComboBox();
buildModeHarmonic->addItems({"Modern", "Legacy"});
harLayout->addWidget(new QLabel("Build Mode:"));
harLayout->addWidget(buildModeHarmonic);
auto *harGrid = new QGridLayout();
auto updateHarmonicVisual = [=]() {
if (!harmonicSpectrum) return;
std::function<double(double)> additiveAlgo = [=](double t) {
double signal = 0.0;
double f = 220.0; // Base frequency (A3) for visualization
double twoPi = 6.283185;