-
Notifications
You must be signed in to change notification settings - Fork 404
/
SurgePatch.cpp
1450 lines (1311 loc) · 60.3 KB
/
SurgePatch.cpp
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
//-------------------------------------------------------------------------------------------------------
// Copyright 2005 Claes Johanson & Vember Audio
//-------------------------------------------------------------------------------------------------------
#include "SurgeStorage.h"
#include "Oscillator.h"
#include "SurgeParamConfig.h"
#include "effect/Effect.h"
#include <list>
#include <vt_dsp/vt_dsp_endian.h>
using namespace std;
const int hmargin = 6;
// const int gui_topbar = 44;
const int gui_topbar = 64;
const int gui_sec_width = 150;
const int gui_col1_x = hmargin, gui_col2_x = hmargin + gui_sec_width,
gui_col3_x = hmargin + gui_sec_width * 2;
const int gui_col4_x = hmargin + gui_sec_width * 3, gui_col5_x = hmargin + gui_sec_width * 4,
gui_col6_x = hmargin + gui_sec_width * 5 + 3;
const int gui_vfader_dist = 20, gui_hfader_dist = 21;
const int gui_sendfx_y = gui_topbar + 60;
const int gui_uppersec_y = gui_topbar + 14; // scene out, filterblock-conf & osc conf etc
const int gui_mainsec_y = gui_topbar + 128; // osc & filter parameters
const int gui_mainsec_slider_y =
gui_mainsec_y + gui_hfader_dist; // where the osc & filter sliders begin
const int gui_envsec_x = 309, gui_envsec_y = 236 + gui_topbar;
const int gui_oscmix_x = 154, gui_oscmix_y = gui_envsec_y;
const int gui_voicemode_x = 184, gui_voicemode_y = gui_topbar + 20;
const int gui_modsec_x = 6, gui_modsec_y = 398 + gui_topbar;
const int gui_mid_topbar_y = 17;
// XML storage fileformat revision
// 0 -> 1 new EG attack shapes (0>1, 1>2, 2>2)
// 1 -> 2 new LFO EG stages (if (decay == max) sustain = max else sustain = min
// 2 -> 3 filter subtypes added comb should default to 1 and moog to 3
// 3 -> 4 comb+/- combined into 1 filtertype (subtype 0,0->0 0,1->1 1,0->2 1,1->3 )
// 4 -> 5 stereo filterconf now have seperate pan controls
// 5 -> 6 new filter sound in v1.2 (same parameters, but different sound & changed resonance
// response). 6 -> 7 custom controller state now stored (in seq. recall) 7 -> 8 larger resonance
// range (old filters are set to subtype 1), pan2 -> width 8 -> 9 now 8 controls (offset ids larger
// than ctrl7 by +1), custom controllers have names (guess for pre-rev9 patches) 9 -> 10 added
// character parameter
const int ff_revision = 10;
SurgePatch::SurgePatch(SurgeStorage* storage)
{
this->storage = storage;
patchptr = nullptr;
int p_id = 0;
{
int px = gui_col6_x, py = gui_sendfx_y;
param_ptr.push_back(fx[4].return_level.assign(p_id++, 0, "volume_FX1", "FX1 Return",
ct_amplitude, px, py, 0, cg_GLOBAL, 0, true,
Surge::ParamConfig::kHorizontal));
py += gui_hfader_dist;
param_ptr.push_back(fx[5].return_level.assign(p_id++, 0, "volume_FX2", "FX2 Return",
ct_amplitude, px, py, 0, cg_GLOBAL, 0, true,
Surge::ParamConfig::kHorizontal));
py += gui_hfader_dist;
// TODO don't store in the patch ?
param_ptr.push_back(volume.assign(
p_id++, 0, "volume", "Master Volume", ct_decibel_attenuation, hmargin + gui_sec_width * 5,
gui_mid_topbar_y + 12, 0, cg_GLOBAL, 0, true, Surge::ParamConfig::kHorizontal | kEasy));
}
param_ptr.push_back(scene_active.assign(p_id++, 0, "scene_active", "Active Scene", ct_scenesel,
7, gui_mid_topbar_y - 2, 0, cg_GLOBAL, 0, false,
Surge::ParamConfig::kHorizontal));
param_ptr.push_back(scenemode.assign(p_id++, 0, "scenemode", "Scene Mode", ct_scenemode,
8 + 51 + 3, gui_mid_topbar_y - 2, 0, cg_GLOBAL, 0, false,
Surge::ParamConfig::kHorizontal | kNoPopup));
// param_ptr.push_back(scenemorph.assign(p_id++,0,"scenemorph","scenemorph",ct_percent,hmargin+gui_sec_width,gui_mid_topbar_y,0,0,0,false,Surge::ParamConfig::kHorizontal));
param_ptr.push_back(splitkey.assign(p_id++, 0, "splitkey", "Split Key", ct_midikey, 8 + 91,
gui_mid_topbar_y - 3, 0, cg_GLOBAL, 0, false,
Surge::ParamConfig::kHorizontal | kNoPopup));
param_ptr.push_back(fx_disable.assign(p_id++, 0, "fx_disable", "FX Disable", ct_none, 0, 0, 0,
cg_GLOBAL, 0, false));
// shouldnt't be stored in the patch
param_ptr.push_back(polylimit.assign(p_id++, 0, "polylimit", "Poly Limit", ct_polylimit, 8 + 91,
gui_mid_topbar_y + 13, 0, cg_GLOBAL, 0, false,
Surge::ParamConfig::kHorizontal | kNoPopup));
param_ptr.push_back(fx_bypass.assign(p_id++, 0, "fx_bypass", "FX Bypass", ct_fxbypass, 607,
gui_mid_topbar_y - 6, 0, cg_GLOBAL, 0, false,
Surge::ParamConfig::kHorizontal | kNoPopup));
polylimit.val.i = 8;
splitkey.val.i = 60;
volume.val.f = 0;
for (int fx = 0; fx < 8; fx++)
{
int px = gui_col6_x, py = gui_sendfx_y + 20 * 3;
param_ptr.push_back(this->fx[fx].type.assign(p_id++, 0, "type", "FX type", ct_fxtype, px,
py - 2, 0, cg_FX, fx, false, Surge::ParamConfig::kHorizontal));
py += 20;
for (int p = 0; p < n_fx_params; p++)
{
char label[16];
sprintf(label, "p%i", p);
param_ptr.push_back(
this->fx[fx].p[p].assign(p_id++, 0, label, "param", ct_none, px, py, 0, cg_FX, fx,
true, Surge::ParamConfig::kHorizontal | kHide | ((fx == 0) ? kEasy : 0)));
py += 20;
}
}
int globparams = p_id;
for (int sc = 0; sc < 2; sc++)
{
int sceasy =
(sc == 0) ? kEasy
: 0; // only consider parameters in the first scene as non-expertmode parameters
int px, py;
int id_s = 0;
vector<Parameter*>* a;
a = ¶m_ptr;
int sc_id = (sc & 1) + 1;
scene_start[sc] = p_id;
px = gui_col2_x;
py = gui_mainsec_y;
a->push_back(scene[sc].octave.assign(p_id++, id_s++, "octave", "Octave", ct_pitch_octave,
px + 46, py + 1, sc_id, cg_GLOBAL, 0, false,
Surge::ParamConfig::kHorizontal | kNoPopup));
py = gui_mainsec_slider_y;
a->push_back(scene[sc].pitch.assign(p_id++, id_s++, "pitch", "Pitch", ct_pitch_semi7bp, px,
py, sc_id, cg_GLOBAL, 0, true,
Surge::ParamConfig::kHorizontal | kSemitone | sceasy));
py += gui_hfader_dist;
a->push_back(scene[sc].portamento.assign(p_id++, id_s++, "portamento", "Portamento",
ct_portatime, px, py, sc_id, cg_GLOBAL, 0, true,
Surge::ParamConfig::kHorizontal | sceasy));
py += gui_hfader_dist;
for (int osc = 0; osc < n_oscs; osc++)
{
px = gui_col1_x;
py = gui_mainsec_y;
a->push_back(scene[sc].osc[osc].type.assign(p_id++, id_s++, "type", "Type", ct_osctype,
px + 3, py + 1, sc_id, cg_OSC, osc, false));
a->push_back(scene[sc].osc[osc].octave.assign(p_id++, id_s++, "octave", "Octave",
ct_pitch_octave, px - 3, py + 1, sc_id,
cg_OSC, osc, false, Surge::ParamConfig::kHorizontal | kNoPopup));
py = gui_mainsec_slider_y;
a->push_back(scene[sc].osc[osc].pitch.assign(p_id++, id_s++, "pitch", "Pitch",
ct_pitch_semi7bp, px, py, sc_id, cg_OSC, osc,
true, Surge::ParamConfig::kHorizontal | kSemitone | sceasy));
py += gui_hfader_dist;
for (int i = 0; i < n_osc_params; i++)
{
char label[16];
sprintf(label, "param%i", i);
a->push_back(scene[sc].osc[osc].p[i].assign(p_id++, id_s++, label, "-", ct_none, px, py,
sc_id, cg_OSC, osc, true,
Surge::ParamConfig::kHorizontal | ((i < 6) ? sceasy : 0)));
py += gui_hfader_dist;
}
py = gui_mainsec_y - 7;
a->push_back(scene[sc].osc[osc].keytrack.assign(p_id++, id_s++, "keytrack", "Keytrack",
ct_bool_keytrack, px + 2, py, sc_id,
cg_OSC, osc, false, Surge::ParamConfig::kHorizontal));
a->push_back(scene[sc].osc[osc].retrigger.assign(p_id++, id_s++, "retrigger", "Retrigger",
ct_bool_retrigger, px + 50, py, sc_id,
cg_OSC, osc, false, Surge::ParamConfig::kHorizontal));
// a->push_back(scene[sc].osc[osc].startphase.assign(p_id++,id_s++,"startphase","start
// phase",ct_none,0,0,sc_id,2,osc,false));
/*scene[sc].osc[osc].wt.n_tables = 8;
scene[sc].osc[osc].wt.size = 64;
for(int i=0; i<scene[sc].osc[osc].wt.size; i++)
{
float x = (float)i / (float)scene[sc].osc[osc].wt.size;
for(int b=0; b<8; b++) scene[sc].osc[osc].wt.table[b][i] = sin(2.0 * (double)(b
+ 1.0) * M_PI * x);
}*/
}
a->push_back(scene[sc].polymode.assign(p_id++, id_s++, "polymode", "Polymode", ct_polymode,
gui_col2_x + 83, gui_uppersec_y + 9, sc_id, cg_GLOBAL,
0, false, Surge::ParamConfig::kVertical | kWhite | kNoPopup));
a->push_back(scene[sc].fm_switch.assign(p_id++, id_s++, "fm_switch", "FM Routing",
ct_fmconfig, gui_col3_x + 3, gui_topbar + 25, sc_id,
cg_GLOBAL, 0, false));
a->push_back(scene[sc].fm_depth.assign(p_id++, id_s++, "fm_depth", "FM Depth",
ct_decibel_fmdepth, gui_col3_x,
gui_uppersec_y + gui_hfader_dist * 4, sc_id, cg_GLOBAL,
0, true, Surge::ParamConfig::kHorizontal | kWhite | sceasy));
a->push_back(scene[sc].drift.assign(p_id++, id_s++, "drift", "Osc Drift", ct_percent,
gui_col2_x, gui_uppersec_y + gui_hfader_dist * 3, sc_id,
cg_GLOBAL, 0, true, Surge::ParamConfig::kHorizontal | kWhite));
a->push_back(scene[sc].noise_colour.assign(
p_id++, id_s++, "noisecol", "Noise Color", ct_percent_bidirectional, gui_col2_x,
gui_uppersec_y + gui_hfader_dist * 4, sc_id, cg_GLOBAL, 0, true,
Surge::ParamConfig::kHorizontal | kWhite | sceasy));
a->push_back(scene[sc].keytrack_root.assign(p_id++, id_s++, "ktrkroot", "Keytrack Root Key",
ct_midikey, 180 + 127, gui_topbar + 78 + 106 + 24,
sc_id, cg_GLOBAL, 0, false));
// ct_midikey
// drift,keytrack_root
px = gui_col5_x;
py = gui_uppersec_y;
a->push_back(scene[sc].volume.assign(p_id++, id_s++, "volume", "Volume", ct_amplitude, px, py,
sc_id, cg_GLOBAL, 0, true,
Surge::ParamConfig::kHorizontal | kWhite | sceasy));
py += gui_hfader_dist;
a->push_back(scene[sc].pan.assign(p_id++, id_s++, "pan", "Pan", ct_percent_bidirectional, px,
py, sc_id, cg_GLOBAL, 0, true,
Surge::ParamConfig::kHorizontal | kWhite | sceasy));
py += gui_hfader_dist;
a->push_back(scene[sc].width.assign(p_id++, id_s++, "pan2", "Width", ct_percent_bidirectional,
px, py, sc_id, cg_GLOBAL, 0, true,
Surge::ParamConfig::kHorizontal | kWhite | sceasy));
py += gui_hfader_dist;
a->push_back(scene[sc].send_level[0].assign(p_id++, id_s++, "send_fx_1", "FX1 Send",
ct_amplitude, px, py, sc_id, cg_GLOBAL, 0, true,
Surge::ParamConfig::kHorizontal | kWhite | sceasy));
py += gui_hfader_dist;
a->push_back(scene[sc].send_level[1].assign(p_id++, id_s++, "send_fx_2", "FX2 Send",
ct_amplitude, px, py, sc_id, cg_GLOBAL, 0, true,
Surge::ParamConfig::kHorizontal | kWhite | sceasy));
scene[sc].send_level[0].val_max.f = 1.5874f;
scene[sc].send_level[1].val_max.f = 1.5874f;
px = gui_oscmix_x;
py = gui_oscmix_y;
int mof = -36, sof = mof + 10, rof = mof + 20;
a->push_back(scene[sc].level_o1.assign(p_id++, id_s++, "level_o1", "Osc1 Level", ct_amplitude,
px, py, sc_id, cg_MIX, 0, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
a->push_back(scene[sc].mute_o1.assign(p_id++, id_s++, "mute_o1", "Osc1 Mute", ct_bool_mute,
px, py + mof, sc_id, cg_MIX, 0, false));
a->push_back(scene[sc].solo_o1.assign(p_id++, id_s++, "solo_o1", "Osc1 Solo", ct_bool_solo,
px, py + sof, sc_id, cg_MIX, 0, false, kMeta));
a->push_back(scene[sc].route_o1.assign(p_id++, id_s++, "route_o1", "Osc1 Route", ct_oscroute,
px, py + rof, sc_id, cg_MIX, 0, false));
px += gui_vfader_dist;
a->push_back(scene[sc].level_o2.assign(p_id++, id_s++, "level_o2", "Osc2 Level", ct_amplitude,
px, py, sc_id, cg_MIX, 0, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
a->push_back(scene[sc].mute_o2.assign(p_id++, id_s++, "mute_o2", "Osc2 Mute", ct_bool_mute,
px, py + mof, sc_id, cg_MIX, 0, false));
a->push_back(scene[sc].solo_o2.assign(p_id++, id_s++, "solo_o2", "Osc2 Solo", ct_bool_solo,
px, py + sof, sc_id, cg_MIX, 0, false, kMeta));
a->push_back(scene[sc].route_o2.assign(p_id++, id_s++, "route_o2", "Osc2 Route", ct_oscroute,
px, py + rof, sc_id, cg_MIX, 0, false));
px += gui_vfader_dist;
a->push_back(scene[sc].level_o3.assign(p_id++, id_s++, "level_o3", "Osc3 Level", ct_amplitude,
px, py, sc_id, cg_MIX, 0, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
a->push_back(scene[sc].mute_o3.assign(p_id++, id_s++, "mute_o3", "Osc3 Mute", ct_bool_mute,
px, py + mof, sc_id, cg_MIX, 0, false));
a->push_back(scene[sc].solo_o3.assign(p_id++, id_s++, "solo_o3", "Osc3 Solo", ct_bool_solo,
px, py + sof, sc_id, cg_MIX, 0, false, kMeta));
a->push_back(scene[sc].route_o3.assign(p_id++, id_s++, "route_o3", "Osc3 Route", ct_oscroute,
px, py + rof, sc_id, cg_MIX, 0, false));
px += gui_vfader_dist;
a->push_back(scene[sc].level_ring_12.assign(p_id++, id_s++, "level_ring12", "Ring Level 1x2",
ct_amplitude, px, py, sc_id, cg_MIX, 0, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
a->push_back(scene[sc].mute_ring_12.assign(p_id++, id_s++, "mute_ring12", "Ring Mute 1x2",
ct_bool_mute, px, py + mof, sc_id, cg_MIX, 0,
false));
a->push_back(scene[sc].solo_ring_12.assign(p_id++, id_s++, "solo_ring12", "Ring Solo 1x2",
ct_bool_solo, px, py + sof, sc_id, cg_MIX, 0,
false, kMeta));
a->push_back(scene[sc].route_ring_12.assign(p_id++, id_s++, "route_ring12", "Ring Route 1x2",
ct_oscroute, px, py + rof, sc_id, cg_MIX, 0,
false));
px += gui_vfader_dist;
a->push_back(scene[sc].level_ring_23.assign(p_id++, id_s++, "level_ring23", "Ring Level 2x3",
ct_amplitude, px, py, sc_id, cg_MIX, 0, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
a->push_back(scene[sc].mute_ring_23.assign(p_id++, id_s++, "mute_ring23", "Ring Mute 2x3",
ct_bool_mute, px, py + mof, sc_id, cg_MIX, 0,
false));
a->push_back(scene[sc].solo_ring_23.assign(p_id++, id_s++, "solo_ring23", "Ring Solo 2x3",
ct_bool_solo, px, py + sof, sc_id, cg_MIX, 0,
false, kMeta));
a->push_back(scene[sc].route_ring_23.assign(p_id++, id_s++, "route_ring23", "Ring Route 2x3",
ct_oscroute, px, py + rof, sc_id, cg_MIX, 0,
false));
px += gui_vfader_dist;
a->push_back(scene[sc].level_noise.assign(p_id++, id_s++, "level_noise", "Noise Level",
ct_amplitude, px, py, sc_id, cg_MIX, 0, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
a->push_back(scene[sc].mute_noise.assign(p_id++, id_s++, "mute_noise", "Noise Mute",
ct_bool_mute, px, py + mof, sc_id, cg_MIX, 0,
false));
a->push_back(scene[sc].solo_noise.assign(p_id++, id_s++, "solo_noise", "Noise Solo",
ct_bool_solo, px, py + sof, sc_id, cg_MIX, 0, false,
kMeta));
a->push_back(scene[sc].route_noise.assign(p_id++, id_s++, "route_noise", "Noise Route",
ct_oscroute, px, py + rof, sc_id, cg_MIX, 0,
false));
px += gui_vfader_dist;
a->push_back(scene[sc].level_pfg.assign(p_id++, id_s++, "level_pfg", "Pre-Filter Gain",
ct_decibel, px, py, sc_id, cg_MIX, 0, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
px += gui_vfader_dist;
int pbx = 164, pby = 112;
a->push_back(scene[sc].pbrange_up.assign(p_id++, id_s++, "pbrange_up",
"Pitch Bend Range (up)", ct_pbdepth, pbx + 25, pby,
sc_id, cg_GLOBAL, 0, true, kNoPopup));
a->push_back(scene[sc].pbrange_dn.assign(p_id++, id_s++, "pbrange_dn",
"Pitch Bend Range (down)", ct_pbdepth, pbx, pby,
sc_id, cg_GLOBAL, 0, true, kNoPopup));
px = gui_envsec_x + gui_vfader_dist * 19 + 10;
py = gui_envsec_y;
a->push_back(scene[sc].vca_level.assign(p_id++, id_s++, "vca_level", "Gain", ct_decibel, px,
py, sc_id, cg_GLOBAL, 0, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
px += gui_vfader_dist;
a->push_back(scene[sc].vca_velsense.assign(p_id++, id_s++, "vca_velsense", "Velocity > Gain",
ct_decibel_attenuation, px, py, sc_id, cg_GLOBAL,
0, false, Surge::ParamConfig::kVertical | kWhite));
px += gui_vfader_dist;
px = gui_col3_x + gui_sec_width + 1;
py = gui_uppersec_y + gui_hfader_dist * 4;
a->push_back(scene[sc].feedback.assign(p_id++, id_s++, "feedback", "Feedback",
ct_percent_bidirectional, px, py, sc_id, cg_GLOBAL, 0,
true, Surge::ParamConfig::kHorizontal | kWhite | sceasy));
py += gui_hfader_dist;
a->push_back(scene[sc].filterblock_configuration.assign(
p_id++, id_s++, "fb_config", "Filter Configuration", ct_fbconfig, gui_col4_x - 1,
gui_topbar + 25, sc_id, cg_GLOBAL, 0, false, Surge::ParamConfig::kHorizontal));
a->push_back(scene[sc].filter_balance.assign(
p_id++, id_s++, "f_balance", "Filter Balance", ct_percent_bidirectional, gui_col4_x,
gui_mainsec_slider_y + 11, sc_id, cg_GLOBAL, 0, true, Surge::ParamConfig::kHorizontal | sceasy));
a->push_back(scene[sc].lowcut.assign(p_id++, id_s++, "lowcut", "High Pass", ct_freq_hpf,
gui_envsec_x + gui_vfader_dist * 2 + 5, gui_envsec_y,
sc_id, cg_GLOBAL, 0, true, Surge::ParamConfig::kVertical | kWhite | sceasy));
a->push_back(scene[sc].wsunit.type.assign(p_id++, id_s++, "ws_type", "Waveshaper Type",
ct_wstype, gui_envsec_x + gui_vfader_dist * 4 - 1,
gui_envsec_y + 13, sc_id, cg_GLOBAL, 0, false,
kNoPopup));
a->push_back(scene[sc].wsunit.drive.assign(
p_id++, id_s++, "ws_drive", "Waveshaper Drive", ct_decibel_narrow,
gui_envsec_x + gui_vfader_dist * 5 + 10, gui_envsec_y, sc_id, cg_GLOBAL, 0, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
for (int f = 0; f < 2; f++)
{
px = gui_col3_x + gui_sec_width * 2 * f;
py = gui_mainsec_y;
a->push_back(scene[sc].filterunit[f].type.assign(p_id++, id_s++, "type", "Filter Type",
ct_filtertype, px - 2, py + 1, sc_id,
cg_FILTER, f, false, Surge::ParamConfig::kHorizontal));
a->push_back(scene[sc].filterunit[f].subtype.assign(
p_id++, id_s++, "subtype", "Filter Subtype", ct_filtersubtype, px - 3, py + 1, sc_id,
cg_FILTER, f, false, Surge::ParamConfig::kHorizontal));
py = gui_mainsec_slider_y;
a->push_back(scene[sc].filterunit[f].cutoff.assign(
p_id++, id_s++, "cutoff", "Cutoff", ct_freq_audible, px, py, sc_id, cg_FILTER, f, true,
Surge::ParamConfig::kHorizontal | sceasy));
if (f == 1)
a->push_back(scene[sc].f2_cutoff_is_offset.assign(
p_id++, id_s++, "f2_cf_is_offset", "Is Offset to F1", ct_bool_relative_switch, px,
py, sc_id, cg_GLOBAL, 0, false, kMeta));
py += gui_hfader_dist;
a->push_back(scene[sc].filterunit[f].resonance.assign(
p_id++, id_s++, "resonance", "Resonance", ct_percent, px, py, sc_id, cg_FILTER, f,
true, Surge::ParamConfig::kHorizontal | sceasy));
if (f == 1)
a->push_back(scene[sc].f2_link_resonance.assign(
p_id++, id_s++, "f2_link_resonance", "Link Resonance", ct_bool_link_switch, px, py,
sc_id, cg_GLOBAL, 0, false, kMeta));
// py += gui_hfader_dist2;
px = gui_envsec_x + gui_vfader_dist * (5 + f) - 10;
py = gui_envsec_y;
a->push_back(scene[sc].filterunit[f].envmod.assign(
p_id++, id_s++, "envmod", "Envmod", ct_freq_mod, px + gui_sec_width, py, sc_id,
cg_FILTER, f, true, Surge::ParamConfig::kVertical | kWhite | sceasy));
px += 3 * gui_vfader_dist - gui_sec_width;
a->push_back(scene[sc].filterunit[f].keytrack.assign(
p_id++, id_s++, "keytrack", "Keytrack", ct_percent_bidirectional, px, py, sc_id,
cg_FILTER, f, true, Surge::ParamConfig::kVertical | kWhite));
}
// scene[sc].filterunit[0].type.val.i = 1;
for (int e = 0; e < 2; e++)
{
px = gui_envsec_x + gui_sec_width + (gui_sec_width) * (1 - e);
py = gui_envsec_y;
const int so = -30;
a->push_back(scene[sc].adsr[e].a.assign(p_id++, id_s++, "attack", "Attack", ct_envtime, px,
py, sc_id, cg_ENV, e, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
a->push_back(scene[sc].adsr[e].a_s.assign(p_id++, id_s++, "attack_shape", "Attack Shape",
ct_envshape, px, py + so, sc_id, cg_ENV, e,
false, kNoPopup));
px += gui_vfader_dist;
a->push_back(scene[sc].adsr[e].d.assign(p_id++, id_s++, "decay", "Decay", ct_envtime, px,
py, sc_id, cg_ENV, e, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
a->push_back(scene[sc].adsr[e].d_s.assign(p_id++, id_s++, "decay_shape", "Decay Shape",
ct_envshape, px, py + so, sc_id, cg_ENV, e,
false, kNoPopup));
px += gui_vfader_dist;
a->push_back(scene[sc].adsr[e].s.assign(p_id++, id_s++, "sustain", "Sustain", ct_percent,
px, py, sc_id, cg_ENV, e, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
px += gui_vfader_dist;
a->push_back(scene[sc].adsr[e].r.assign(p_id++, id_s++, "release", "Release", ct_envtime,
px, py, sc_id, cg_ENV, e, true,
Surge::ParamConfig::kVertical | kWhite | sceasy));
a->push_back(scene[sc].adsr[e].r_s.assign(p_id++, id_s++, "release_shape", "Release Shape",
ct_envshape, px, py + so, sc_id, cg_ENV, e,
false, kNoPopup));
px += gui_vfader_dist;
a->push_back(scene[sc].adsr[e].mode.assign(p_id++, id_s++, "mode", "Mode", ct_envmode,
px + 13, py - 31, sc_id, cg_ENV, e, false,
kNoPopup));
}
for (int l = 0; l < n_lfos; l++)
{
px = gui_modsec_x + 229;
py = gui_modsec_y - 7;
char label[32];
sprintf(label, "lfo%i_shape", l);
a->push_back(scene[sc].lfo[l].shape.assign(p_id++, id_s++, label, "Shape", ct_lfoshape, px,
py, sc_id, cg_LFO, ms_lfo1 + l, true,
Surge::ParamConfig::kHorizontal));
px = gui_modsec_x;
py = gui_modsec_y - 10;
sprintf(label, "lfo%i_rate", l);
a->push_back(scene[sc].lfo[l].rate.assign(p_id++, id_s++, label, "Rate", ct_lforate, px,
py, sc_id, cg_LFO, ms_lfo1 + l, true,
Surge::ParamConfig::kHorizontal | sceasy));
py += gui_hfader_dist;
sprintf(label, "lfo%i_phase", l);
a->push_back(scene[sc].lfo[l].start_phase.assign(p_id++, id_s++, label, "Phase / Shuffle",
ct_percent, px, py, sc_id, cg_LFO,
ms_lfo1 + l, true, Surge::ParamConfig::kHorizontal));
py += gui_hfader_dist;
sprintf(label, "lfo%i_magnitude", l);
a->push_back(scene[sc].lfo[l].magnitude.assign(p_id++, id_s++, label, "Magnitude",
ct_percent, px, py, sc_id, cg_LFO,
ms_lfo1 + l, true, Surge::ParamConfig::kHorizontal | sceasy));
py += gui_hfader_dist;
sprintf(label, "lfo%i_deform", l);
a->push_back(scene[sc].lfo[l].deform.assign(p_id++, id_s++, label, "Deform",
ct_percent_bidirectional, px, py, sc_id,
cg_LFO, ms_lfo1 + l, true, Surge::ParamConfig::kHorizontal));
px += gui_sec_width;
py = gui_modsec_y;
sprintf(label, "lfo%i_trigmode", l);
a->push_back(scene[sc].lfo[l].trigmode.assign(p_id++, id_s++, label, "Trigger Mode",
ct_lfotrigmode, px + 5, py - 4, sc_id,
cg_LFO, ms_lfo1 + l, false, kNoPopup));
py += 44;
sprintf(label, "lfo%i_unipolar", l);
a->push_back(scene[sc].lfo[l].unipolar.assign(p_id++, id_s++, label, "Unipolar",
ct_bool_unipolar, px + 5, py - 4, sc_id,
cg_LFO, ms_lfo1 + l, false));
px += 3 * gui_sec_width + 8;
py = gui_modsec_y + 5;
sprintf(label, "lfo%i_delay", l);
a->push_back(scene[sc].lfo[l].delay.assign(p_id++, id_s++, label, "Delay", ct_envtime, px,
py, sc_id, cg_LFO, ms_lfo1 + l, true,
Surge::ParamConfig::kVertical | kMini));
px += gui_vfader_dist;
sprintf(label, "lfo%i_attack", l);
a->push_back(scene[sc].lfo[l].attack.assign(p_id++, id_s++, label, "Attack", ct_envtime,
px, py, sc_id, cg_LFO, ms_lfo1 + l, true,
Surge::ParamConfig::kVertical | kMini));
px += gui_vfader_dist;
sprintf(label, "lfo%i_hold", l);
a->push_back(scene[sc].lfo[l].hold.assign(p_id++, id_s++, label, "Hold", ct_envtime, px,
py, sc_id, cg_LFO, ms_lfo1 + l, true,
Surge::ParamConfig::kVertical | kMini));
px += gui_vfader_dist;
sprintf(label, "lfo%i_decay", l);
a->push_back(scene[sc].lfo[l].decay.assign(p_id++, id_s++, label, "Decay", ct_envtime, px,
py, sc_id, cg_LFO, ms_lfo1 + l, true,
Surge::ParamConfig::kVertical | kMini));
px += gui_vfader_dist;
sprintf(label, "lfo%i_sustain", l);
a->push_back(scene[sc].lfo[l].sustain.assign(p_id++, id_s++, label, "Sustain", ct_percent,
px, py, sc_id, cg_LFO, ms_lfo1 + l, true,
Surge::ParamConfig::kVertical | kMini));
px += gui_vfader_dist;
sprintf(label, "lfo%i_release", l);
a->push_back(scene[sc].lfo[l].release.assign(p_id++, id_s++, label, "Release",
ct_envtime_lfodecay, px, py, sc_id, cg_LFO,
ms_lfo1 + l, true, Surge::ParamConfig::kVertical | kMini));
px += gui_vfader_dist;
}
}
param_ptr.push_back(character.assign(p_id++, 0, "character", "Character", ct_character, 607,
gui_mid_topbar_y + 24, 0, cg_GLOBAL, 0, false, kNoPopup));
scene_size = scene_start[1] - scene_start[0];
assert(scene_size == n_scene_params);
assert(globparams == n_global_params);
init_default_values();
update_controls(true);
// Build indexed list for the non-expert parameters
for (unsigned int i = 0; i < param_ptr.size(); i++)
{
if (param_ptr[i]->ctrlstyle & kEasy)
easy_params_id.push_back(i);
}
}
void SurgePatch::init_default_values()
{
// reset all parameters to their default value (could be zero, then zeroes never would have to be
// saved in xml) will make it all more predictable
int n = param_ptr.size();
for (int i = 0; i < n; i++)
{
if ((i != volume.id) && (i != fx_bypass.id) && (i != polylimit.id))
{
param_ptr[i]->val.i = param_ptr[i]->val_default.i;
param_ptr[i]->clear_flags();
}
}
character.val.i = 1;
for (int sc = 0; sc < 2; sc++)
{
for (auto& osc : scene[sc].osc)
{
osc.type.val.i = 0;
osc.queue_xmldata = 0;
osc.queue_type = -1;
osc.keytrack.val.b = true;
osc.retrigger.val.b = false;
osc.wt.queue_id = 0;
osc.wt.queue_filename[0] = 0;
}
scene[sc].fm_depth.val.f = -24.f;
scene[sc].portamento.val.f = scene[sc].portamento.val_min.f;
scene[sc].keytrack_root.val.i = 60;
scene[sc].send_level[0].val.f = scene[sc].send_level[0].val_min.f;
scene[sc].send_level[1].val.f = scene[sc].send_level[1].val_min.f;
scene[sc].send_level[0].per_voice_processing = false;
scene[sc].send_level[1].per_voice_processing = false;
scene[sc].volume.val.f = 0.890899f;
scene[sc].width.val.f = 1.f; // width
scene[sc].mute_o2.val.b = true;
scene[sc].mute_o3.val.b = true;
scene[sc].mute_noise.val.b = true;
scene[sc].mute_ring_12.val.b = true;
scene[sc].mute_ring_23.val.b = true;
scene[sc].route_o1.val.i = 1;
scene[sc].route_o2.val.i = 1;
scene[sc].route_o3.val.i = 1;
scene[sc].route_ring_12.val.i = 1;
scene[sc].route_ring_23.val.i = 1;
scene[sc].route_noise.val.i = 1;
scene[sc].pbrange_up.val.i = 2.f;
scene[sc].pbrange_dn.val.i = 2.f;
scene[sc].lowcut.val.f = scene[sc].lowcut.val_min.f;
scene[sc].lowcut.per_voice_processing = false;
scene[sc].adsr[0].a.val.f = scene[sc].adsr[0].a.val_min.f;
scene[sc].adsr[0].a.val_default.f = scene[sc].adsr[0].a.val_min.f;
scene[sc].adsr[0].d.val.f = -2;
scene[sc].adsr[0].d.val_default.f = -2;
scene[sc].adsr[0].r.val.f = -5;
scene[sc].adsr[0].r.val_default.f = -5;
scene[sc].adsr[0].s.val.f = 1;
scene[sc].adsr[0].s.val_default.f = 1;
scene[sc].adsr[0].a_s.val.i = 1;
scene[sc].adsr[0].d_s.val.i = 1;
scene[sc].adsr[0].r_s.val.i = 2;
scene[sc].adsr[1].a.val.f = scene[sc].adsr[1].a.val_min.f;
scene[sc].adsr[1].a.val_default.f = scene[sc].adsr[1].a.val_min.f;
scene[sc].adsr[1].d.val.f = -2;
scene[sc].adsr[1].d.val_default.f = -2;
scene[sc].adsr[1].s.val.f = 0;
scene[sc].adsr[1].s.val_default.f = 0;
scene[sc].adsr[1].r.val.f = -2;
scene[sc].adsr[1].r.val_default.f = -2;
scene[sc].adsr[1].a_s.val.i = 1;
scene[sc].adsr[1].d_s.val.i = 1;
scene[sc].adsr[1].r_s.val.i = 1;
for (int l = 0; l < n_lfos; l++)
{
scene[sc].lfo[l].magnitude.val.f = 1.f;
scene[sc].lfo[l].magnitude.val_default.f = 1.f;
scene[sc].lfo[l].trigmode.val.i = 1;
scene[sc].lfo[l].delay.val.f = scene[sc].lfo[l].delay.val_min.f;
scene[sc].lfo[l].delay.val_default.f = scene[sc].lfo[l].delay.val_min.f;
scene[sc].lfo[l].attack.val.f = scene[sc].lfo[l].attack.val_min.f;
scene[sc].lfo[l].attack.val_default.f = scene[sc].lfo[l].attack.val_min.f;
scene[sc].lfo[l].hold.val.f = scene[sc].lfo[l].hold.val_min.f;
scene[sc].lfo[l].decay.val.f = 0.f;
scene[sc].lfo[l].sustain.val.f = scene[sc].lfo[l].sustain.val_max.f;
scene[sc].lfo[l].sustain.val_default.f = scene[sc].lfo[l].sustain.val_max.f;
scene[sc].lfo[l].release.val.f = scene[sc].lfo[l].release.val_max.f;
scene[sc].lfo[l].release.val_default.f = scene[sc].lfo[l].release.val_max.f;
for (int i = 0; i < n_stepseqsteps; i++)
{
stepsequences[sc][l].steps[i] = 0.f;
}
stepsequences[sc][l].trigmask = 0;
stepsequences[sc][l].loop_start = 0;
stepsequences[sc][l].loop_end = 15;
stepsequences[sc][l].shuffle = 0.f;
}
}
for (int i = 0; i < n_customcontrollers; i++)
{
strcpy(CustomControllerLabel[i], "-");
}
}
SurgePatch::~SurgePatch()
{
free(patchptr);
}
void SurgePatch::copy_scenedata(pdata* d, int scene)
{
int s = scene_start[scene];
for (int i = 0; i < n_scene_params; i++)
{
// if (param_ptr[i+s]->valtype == vt_float)
// d[i].f = param_ptr[i+s]->val.f;
d[i].i = param_ptr[i + s]->val.i;
}
/*for(int i=0; i<(n_scene_params & 0xfff8); i+=8)
{
d[i].i = param_ptr[i+s]->val.i;
d[i+1].i = param_ptr[i+s+1]->val.i;
d[i+2].i = param_ptr[i+s+2]->val.i;
d[i+3].i = param_ptr[i+s+3]->val.i;
d[i+4].i = param_ptr[i+s+4]->val.i;
d[i+5].i = param_ptr[i+s+5]->val.i;
d[i+6].i = param_ptr[i+s+6]->val.i;
d[i+7].i = param_ptr[i+s+7]->val.i;
}
for(int i=(n_scene_params & 0xfff8); i<n_scene_params; i++)
{
d[i].i = param_ptr[i+s]->val.i;
}*/
}
void SurgePatch::copy_globaldata(pdata* d)
{
for (int i = 0; i < n_global_params; i++)
{
// if (param_ptr[i]->valtype == vt_float)
d[i].i = param_ptr[i]->val.i; // int is safer (no exceptions or anything)
}
}
// pdata scenedata[2][n_scene_params];
void SurgePatch::update_controls(bool init,
void* init_osc) // init_osc is the pointer to the data structure of
// a particular osc to be reinitialized
{
for (auto& sc : scene)
{
for (int osc = 0; osc < n_oscs; osc++)
{
for (int i = 0; i < n_osc_params; i++)
sc.osc[osc].p[i].set_type(ct_none);
Oscillator* t_osc = spawn_osc(sc.osc[osc].type.val.i, nullptr, &sc.osc[osc], nullptr);
if (t_osc)
{
t_osc->init_ctrltypes();
if (init || (init_osc == &sc.osc[osc]))
t_osc->init_default_values();
delete t_osc;
}
}
}
}
void SurgePatch::do_morph()
{
int s = scene_start[0];
int n = scene_start[1] - scene_start[0];
for (int i = 0; i < n; i++)
{
// copy_ptr[i]->morph(copy_ptr[i+n],scenemorph.val.f);
scenedata[0][i] = param_ptr[s + i]->morph(param_ptr[s + i + n], scenemorph.val.f);
}
}
#pragma pack(push, 1)
struct patch_header
{
char tag[4];
unsigned int xmlsize, wtsize[2][3];
};
#pragma pack(pop)
void SurgePatch::load_patch(const void* data, int datasize, bool preset)
{
if (datasize <= 4)
return;
assert(datasize);
assert(data);
void* end = (char*)data + datasize;
patch_header* ph = (patch_header*)data;
ph->xmlsize = vt_read_int32LE(ph->xmlsize);
if (!memcmp(ph->tag, "sub3", 4))
{
char* dr = (char*)data + sizeof(patch_header);
load_xml(dr, ph->xmlsize, preset);
dr += ph->xmlsize;
for (int sc = 0; sc < 2; sc++)
{
for (int osc = 0; osc < n_oscs; osc++)
{
ph->wtsize[sc][osc] = vt_read_int32LE(ph->wtsize[sc][osc]);
if (ph->wtsize[sc][osc])
{
wt_header* wth = (wt_header*)dr;
if (wth > end)
return;
scene[sc].osc[osc].wt.queue_id = -1;
scene[sc].osc[osc].wt.queue_filename[0] = 0;
scene[sc].osc[osc].wt.current_id = -1;
void* d = (void*)((char*)dr + sizeof(wt_header));
storage->CS_WaveTableData.enter();
scene[sc].osc[osc].wt.BuildWT(d, *wth, false);
storage->CS_WaveTableData.leave();
dr += ph->wtsize[sc][osc];
}
}
}
}
else
{
load_xml(data, datasize, preset);
}
}
unsigned int SurgePatch::save_patch(void** data)
{
size_t psize = 0;
// void **xmldata = new void*();
void* xmldata = 0;
patch_header header;
memcpy(header.tag, "sub3", 4);
size_t xmlsize = save_xml(&xmldata);
header.xmlsize = vt_write_int32LE(xmlsize);
wt_header wth[2][n_oscs];
for (int sc = 0; sc < 2; sc++)
{
for (int osc = 0; osc < n_oscs; osc++)
{
if (uses_wavetabledata(scene[sc].osc[osc].type.val.i))
{
memset(wth[sc][osc].tag, 0, 4);
wth[sc][osc].n_samples = scene[sc].osc[osc].wt.size;
wth[sc][osc].n_tables = scene[sc].osc[osc].wt.n_tables;
wth[sc][osc].flags = scene[sc].osc[osc].wt.flags | wtf_int16;
unsigned int wtsize =
wth[sc][osc].n_samples * scene[sc].osc[osc].wt.n_tables * sizeof(short) +
sizeof(wt_header);
header.wtsize[sc][osc] = vt_write_int32LE(wtsize);
psize += wtsize;
}
else
header.wtsize[sc][osc] = 0;
}
}
psize += xmlsize + sizeof(patch_header);
if (patchptr)
free(patchptr);
patchptr = malloc(psize);
char* dw = (char*)patchptr;
*data = patchptr;
memcpy(dw, &header, sizeof(patch_header));
dw += sizeof(patch_header);
memcpy(dw, xmldata, xmlsize);
dw += xmlsize;
free(xmldata);
for (int sc = 0; sc < 2; sc++)
{
for (int osc = 0; osc < n_oscs; osc++)
{
if (header.wtsize[sc][osc])
{
size_t wtsize = vt_read_int32LE(header.wtsize[sc][osc]);
int n_tables = wth[sc][osc].n_tables;
int n_samples = wth[sc][osc].n_samples;
// do all endian swapping for the wavetables in one place (for ppc)
wth[sc][osc].n_samples = vt_write_int32LE(wth[sc][osc].n_samples);
wth[sc][osc].n_tables = vt_write_int16LE(wth[sc][osc].n_tables);
wth[sc][osc].flags = vt_write_int16LE(wth[sc][osc].flags | wtf_int16);
memcpy(dw, &wth[sc][osc], sizeof(wt_header));
short* fp = (short*)(char*)(dw + sizeof(wt_header));
for (int j = 0; j < n_tables; j++)
{
vt_copyblock_W_LE(&fp[j * n_samples],
&scene[sc].osc[osc].wt.TableI16WeakPointers[0][j][FIRoffsetI16],
n_samples);
}
dw += wtsize;
}
}
}
return psize;
}
float convert_v11_reso_to_v12_2P(float reso)
{
float Qinv =
(1.0f - 0.99f * limit_range((float)(1.f - (1.f - reso) * (1.f - reso)), 0.0f, 1.0f));
// return 1.0f - sqrt(1.0f - Qinv / 1.05f);
return 1.f - sqrt(1.f - ((1.0f - Qinv) / 1.05f));
}
float convert_v11_reso_to_v12_4P(float reso)
{
return reso * (0.99f / 1.05f);
}
void SurgePatch::load_xml(const void* data, int datasize, bool is_preset)
{
TiXmlDocument doc;
int j;
double d;
if (datasize)
{
assert(datasize < (1 << 22)); // something is weird if the patch is this big
char* temp = (char*)malloc(datasize + 1);
memcpy(temp, data, datasize);
*(temp + datasize) = 0;
doc.Parse(temp, nullptr, TIXML_ENCODING_LEGACY);
free(temp);
}
// clear old routings
scene[0].modulation_scene.clear();
scene[0].modulation_voice.clear();
scene[1].modulation_scene.clear();
scene[1].modulation_voice.clear();
modulation_global.clear();
for (auto& i : fx)
i.type.val.i = fxt_off;
TiXmlElement* patch = TINYXML_SAFE_TO_ELEMENT(doc.FirstChild("patch"));
if (!patch)
return;
int revision = 0;
patch->QueryIntAttribute("revision", &revision);
TiXmlElement* meta = TINYXML_SAFE_TO_ELEMENT(patch->FirstChild("meta"));
if (meta)
{
const char* s;
if (!is_preset)
{
s = meta->Attribute("name");
if (s)
name = s;
s = meta->Attribute("category");
if (s)
category = s;
}
s = meta->Attribute("comment");
if (s)
comment = s;
s = meta->Attribute("author");
if (s)
author = s;
}
TiXmlElement* parameters = TINYXML_SAFE_TO_ELEMENT(patch->FirstChild("parameters"));
assert(parameters);
int n = param_ptr.size();
// delete volume & fx_bypass if it's a preset. Those settings should stick
if (is_preset)
{
TiXmlElement* tp = TINYXML_SAFE_TO_ELEMENT(parameters->FirstChild("volume"));
if (tp)
parameters->RemoveChild(tp);
tp = TINYXML_SAFE_TO_ELEMENT(parameters->FirstChild("fx_bypass"));
if (tp)
parameters->RemoveChild(tp);
tp = TINYXML_SAFE_TO_ELEMENT(parameters->FirstChild("polylimit"));
if (tp)
parameters->RemoveChild(tp);
}
TiXmlElement* p;
for (int i = 0; i < n; i++)
{
if (!i)
p = TINYXML_SAFE_TO_ELEMENT(parameters->FirstChild(param_ptr[i]->get_storage_name()));
else
{
if (p)
p = TINYXML_SAFE_TO_ELEMENT(p->NextSibling(param_ptr[i]->get_storage_name()));
if (!p)
p = TINYXML_SAFE_TO_ELEMENT(parameters->FirstChild(param_ptr[i]->get_storage_name()));
}
if (p)
{
int type;
if (!(p->QueryIntAttribute("type", &type) == TIXML_SUCCESS))
type = param_ptr[i]->valtype;
if (type == (valtypes)vt_float)
{
if (p->QueryDoubleAttribute("value", &d) == TIXML_SUCCESS)
param_ptr[i]->set_storage_value((float)d);
else
param_ptr[i]->val.f = param_ptr[i]->val_default.f;
}
else
{
if (p->QueryIntAttribute("value", &j) == TIXML_SUCCESS)
param_ptr[i]->set_storage_value(j);
else
param_ptr[i]->val.i = param_ptr[i]->val_default.i;
}
if ((p->QueryIntAttribute("temposync", &j) == TIXML_SUCCESS) && (j == 1))
param_ptr[i]->temposync = true;
else
param_ptr[i]->temposync = false;
if ((p->QueryIntAttribute("extend_range", &j) == TIXML_SUCCESS) && (j == 1))
param_ptr[i]->extend_range = true;
else
param_ptr[i]->extend_range = false;
if ((p->QueryIntAttribute("absolute", &j) == TIXML_SUCCESS) && (j == 1))
param_ptr[i]->absolute = true;
else
param_ptr[i]->absolute = false;
int sceneId = param_ptr[i]->scene;
int paramIdInScene = param_ptr[i]->param_id_in_scene;
TiXmlElement* mr = TINYXML_SAFE_TO_ELEMENT(p->FirstChild("modrouting"));
while (mr)
{
int modsource;
double depth;
if ((mr->QueryIntAttribute("source", &modsource) == TIXML_SUCCESS) &&
(mr->QueryDoubleAttribute("depth", &depth) == TIXML_SUCCESS))
{
if (revision < 9)
{
if (modsource > ms_ctrl7)
modsource++;