-
Notifications
You must be signed in to change notification settings - Fork 0
/
FX Devices Band Split
12981 lines (9671 loc) · 720 KB
/
FX Devices Band Split
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
--------------------------== declare Initial Variables & Functions ------------------------
VersionNumber = 'Dec 23 2022 - bug fix 3 '
FX_Add_Del_WaitTime=2
r=reaper
function msg(A)
r.ShowConsoleMsg(A)
end
dofile(reaper.GetResourcePath() .. '/Scripts/ReaTeam Extensions/API/imgui.lua')
('0.6')
UserOS = r.GetOS()
if UserOS == "OSX32" or UserOS == "OSX64" or UserOS == "macOS-arm64" then
Invisi_Cursor = reaper.JS_Mouse_LoadCursorFromFile(r.GetResourcePath()..'/Cursors/Empty Cursor.cur')
end
mx, my = reaper.GetMousePosition()
window = reaper.JS_Window_FromPoint(mx, my)
release_time = reaper.time_precise() + 3.0 -- hide/freeze mouse for 3 secs.
function Loop()
if reaper.time_precise() < release_time then
reaper.JS_Mouse_SetPosition(mx, my)
reaper.JS_Mouse_SetCursor(reaper.JS_Mouse_LoadCursor(Invisi_Cursor))
reaper.defer(Loop)
else
reaper.JS_WindowMessage_Release(window, "WM_SETCURSOR")
end
end
reaper.JS_WindowMessage_Intercept(window, "WM_SETCURSOR", false)
release_time = reaper.time_precise() + 3.0
--[[ Loop() ]]
function MouseCursorBusy(enable, title)
mx, my = reaper.GetMousePosition()
local hwnd = reaper.JS_Window_FindTop(title, true)
-- local hwnd = reaper.JS_Window_FromPoint(mx, my)
if enable then -- set cursor to hourglass
reaper.JS_Mouse_SetCursor(Invisi_Cursor)
-- block app from changing mouse cursor
reaper.JS_WindowMessage_Intercept(hwnd, "WM_SETCURSOR", false)
else -- set cursor to arrow
reaper.JS_Mouse_SetCursor(reaper.JS_Mouse_LoadCursor(32512))
-- allow app to change mouse cursor
end
end
VP={}
demo={}
app={}
enum_cache={}
cache={}
Draw= { Rect={} ;DrawMode = {} ; ItemInst={} ; L={};R={};Y={}; T={};B={};FxGUID={}; Time = 0; Df_EdgeRound={}}
AddFX={Pos={},Name={},GUID={}}
DelFX={Pos={},Name={}}
MovFX={ToPos={};FromPos={};Lbl={};Copy={}}
ClrPallet={}
Glob={};
Sel_Cross={}
DraggingFXs = { } ; DraggingFXs_Idx = {}
function ConcatPath(...)
-- Get system dependent path separator
local sep = package.config:sub(1, 1)
return table.concat({...}, sep)
end
--[[ local dir_path = ConcatPath(reaper.GetResourcePath(), 'Scripts', 'FX Devices', 'FX Layouts')
-- Create directory for file if it doesn't exist
reaper.RecursiveCreateDirectory(dir_path, 0)
]]
----------- Custom Colors-------------------
CustomColors = {'FX_Devices_Bg','FX_Layer_Container_BG','Space_Between_FXs', 'Morph_A', 'Morph_B','Layer_Solo','Layer_Mute'}
CustomColorsDefault = {FX_Devices_Bg=0x151515ff; FX_Layer_Container_BG=0x262626ff; Space_Between_FXs=0x131313ff ; Morph_A=0x22222266; Morph_B=0x78787877; Layer_Solo= 0xDADF3775; Layer_Mute=0xBE01015C}
----------Parameters --------------------
Prm={
McroModAmt={};McroModAmt_Norm={}; Pos_L={};Pos_T={};Pos_R={};Pos_B={}; ModAngle ={};
SldrGrabXPos={};Val={};NameS={};FXGUID={};InstAdded={};Init_Val={};Num={};TrkID={};Deletable={};Name={}
}
-----------------------------------------
-----Param Modulations
-----------------------------------------
PM = {Ins={} ; FXGUID={} ; Corres_Glob_ID={}; HasMod={}; Final_V = {}; DIY_TrkID={}}
waitForGmem = 0
-----------------------------------------
-----FX layering
-----------------------------------------
Lyr={
Selected={}; title={}; ProgBarClick ={}; Title = {} ; ProgBarVal={};
SpltrID={};Count={};Solo={};Mute={};Rename={};FX_Ins={};ProgBarDrag={};
EditingTitle={};LastFXPos={};FrstFXPos={};SplitrAttachTo={};PrevFX={};
TitleToShow={};
}
Spltr={}
LE={GridSize=10; Sel_Items={};ChangeR_Bound={}}
----Preset Morph--------------
PresetMorph={timer=0}
--- FX Chain -----------------------------
FXchain={FxGUID ={};wait=0;}
----track--------------------------------
Trk={GUID={};Prm={FXGUID={};Inst={};AssignWhich={};V={};O_V={};Num={};WhichMcros={}};FxGUID={};PreFX={}}
------------------Divider---------------
Dvdr={Width={};Clr={};Spc_Hover={};RestoreNormWidthWait=0;RestoreNormWidthWait={}; JustDrop={};}
-----------------FX State-----------------
FX={Enable={};InLyr={};Width={};Collapse={};LyrNum={};Win={};Win_Name={};Def_Type={} ; Win_Name_S = {};TitleWidth={};Sldr_W={};WidthCollapse={}; Round={};GrbRound={}; BgClr={}; Def_Sldr_W={};
Prm={V_Round={};V_FontSize = {};ShowCondition={}; ConditionPrm={}; ConditionPrm_V={}; Switch_W = {}; Combo_W={}; Options={};BgClrHvr={};BgClrAct={};Lbl_Clr={};V_Clr={};DragDir={}; Lbl_Pos={}; V_Pos={}; Style={};GrbClr = {}; BgClr={}; Count={}; Name={};Num={};V={};InitV={};AssignWhichParam={};ToTrkPrm={}; Lbl={}; PosX = {}; PosY={};VertSldr={};Type={};CustomLbl={};FontSize={};Sldr_H={}}
}
Knob_DefaultFontSize=10
Df={ KnobRadius=18; KnobSize= 15*3; Sldr_W=160 ; Dvdr_Width = 15 ; Dvdr_Hvr_W = 0 }
--------Pro C ------------------------
ProC={Width=280; Pt={R={m={};M={}};L={m={};M={}}}}
-----------------------------------------
-----Pro Q 3
-----------------------------------------
ProQ3 = {LT_EQBand={};GainDrag = {};Band_UseState={};DspRange={};SpectrumExist={};}
ProQ3.Width = 340
ProQ3.SpecWait=0
FreqValueDrag={}
fftsize = 4096
xscale=300/(fftsize-4)
wsc=ProQ3.Width/math.log(900) --- 340 = width of pro q window
SpectrumX = 0
SpectrumY = 0
OUTPUT=0
NodeDrag={}
XposNode = {}
ONE_OVER_SAMPLE_RATE = 1 / (30000 * 2)
Euler = 2.71828182845904523
Hz = 6
A = 2
Q = 0.5
MAX_FREQ = 30000
max_freq = 30000
min_freq = 10;
MIN_FREQ = 10;
FREQ_LOG_MAX = math.log(MAX_FREQ / MIN_FREQ);
MAX_Q = 40;
MIN_Q = 0.15;
freq_log_max = math.log(max_freq / min_freq);
NodeFreq = {}
function determineBandColor(Band) -- for pro q 3
if Band == 1 or Band == 9 or Band == 17 then Clr_HalfAlpha = 0x69B45D55
elseif Band == 2 or Band == 10 or Band == 18 then Clr_HalfAlpha = 0x2D91E355
elseif Band == 3 or Band == 11 or Band == 19 then Clr_HalfAlpha = 0xC530E555
elseif Band == 4 or Band == 12 or Band == 20 then Clr_HalfAlpha = 0xF51B1D55
elseif Band == 5 or Band == 13 or Band == 21 then Clr_HalfAlpha = 0x571EF555
elseif Band == 6 or Band == 14 or Band == 22 then Clr_HalfAlpha = 0xC1FF1A55
elseif Band == 7 or Band == 15 or Band == 23 then Clr_HalfAlpha = 0x30C2FF55
elseif Band == 8 or Band == 16 or Band == 24 then Clr_HalfAlpha = 0x00e49655
end
if Band == 1 or Band == 9 or Band == 17 then Clr_FullAlpha = 0x69B45Dff
elseif Band == 2 or Band == 10 or Band == 18 then Clr_FullAlpha = 0x2D91E3ff
elseif Band == 3 or Band == 11 or Band == 19 then Clr_FullAlpha = 0xC530E5ff
elseif Band == 4 or Band == 12 or Band == 20 then Clr_FullAlpha = 0xF51B1Dff
elseif Band == 5 or Band == 13 or Band == 21 then Clr_FullAlpha = 0x571EF5ff
elseif Band == 6 or Band == 14 or Band == 22 then Clr_FullAlpha = 0xC1FF1Aff
elseif Band == 7 or Band == 15 or Band == 23 then Clr_FullAlpha = 0x30C2FFff
elseif Band == 8 or Band == 16 or Band == 24 then Clr_FullAlpha = 0x00e496ff
end
if Band == 1 or Band == 9 or Band == 17 then Clr_Brighter = 0x96CA8Dff
elseif Band == 2 or Band == 10 or Band == 18 then Clr_Brighter = 0x6CB2EBff
elseif Band == 3 or Band == 11 or Band == 19 then Clr_Brighter = 0xC530E5ff
elseif Band == 4 or Band == 12 or Band == 20 then Clr_Brighter = 0xF51B1Dff
elseif Band == 5 or Band == 13 or Band == 21 then Clr_Brighter = 0x865affff
elseif Band == 6 or Band == 14 or Band == 22 then Clr_Brighter = 0xccef6eff
elseif Band == 7 or Band == 15 or Band == 23 then Clr_Brighter = 0x30C2FFff
elseif Band == 8 or Band == 16 or Band == 24 then Clr_Brighter = 0x00e496ff
end
return Clr_HalfAlpha, Clr_FullAlpha,Clr_Brighter
end
function explode_rgba(rgba)
return
((rgba >> 24) & 0xFF) / 255,
((rgba >> 16) & 0xFF) / 255,
((rgba >> 8 ) & 0xFF) / 255,
(rgba & 0xFF) / 255
end
function _svf_bp(freq, q)
g = math.tan(math.pi * freq/SAMPLE_RATE);
k = 1.0 / q;
a1 = 1.0 / (1.0 + g * (g + k));
a2 = g * a1;
a3 = g * a2;
m0 = 0;
m1 = 1/q;
m2 = 0;
svf_set_coeffs(g, k, a1, a2, a3, m0, m1, m2);
end
function _svf_bs(freq, q)
g = math.tan(math.pi * freq/SAMPLE_RATE);
k = 1.0 / q;
a1 = 1.0 / (1.0 + g * (g + k));
a2 = g * a1;
a3 = g * a2;
m0 = 1;
m1 = -k;
m2 = 0;
svf_set_coeffs(g, k, a1, a2, a3, m0, m1, m2);
end
function svf_bs(freq, q)
nlp = 1;
onepole = 0;
_svf_bs(freq, q);
end
function svf_bp(freq, q)
nlp = 1;
onepole = 0;
_svf_bp(freq, q);
end
function per_to_q(x, range)
Q_LOG_MAX = math.log(MAX_Q / MIN_Q,5);
return MIN_Q * (Euler ^(Q_LOG_MAX * x / range))
end
function q_to_per(q, range)
return range * math.log(q / MIN_Q) / Q_LOG_MAX;
end
function _zdf_eq(freq, q, gain)
A = gain; --10.0 ^ (gain / 20.0);
g = math.tan(math.pi * freq/SAMPLE_RATE);
k = 1.0 / (q * A);
a1 = 1.0 / (1.0 + g * (g + k));
a2 = g * a1;
a3 = g * a2;
m0 = 1;
m1 = k*(A*A-1);
m2 = 0;
rbj_eq(freq, q, gain);
return zdf_set_coeffs(a1, a2, a3, m0, m1, m2);
end
function zdf_eq(freq, q, gain)
--instance(nlp, onepole)
nlp = 1;
onepole = 0;
this._zdf_eq(freq, q, gain);
end
function rbj_eq(freq, q, gain)
--instance(a1, a2, b0, b1, b2)
w0 = 2*math.pi * math.min(freq / SAMPLE_RATE, 0.49);
alpha = math.sin(w0) / (2*q);
a = gain; --math.sqrt(gain);
b0 = 1 + alpha * a;
b1 = a1
a1 = -2 * math.cos(w0);
b2 = 1 - alpha * a;
a0 = 1 + alpha / a;
a2 = 1 - alpha / a;
return rbj_scale(a0)
end
function db_to_y(db)
DB_EQ_RANGE = 60
m = 1.0 - (((db / DB_EQ_RANGE) / 2) + 0.5);
return - (m * 200 - 100)
--return TOP_MARGIN+(m * (gfx_h - (gfx_texth*2) - BOTTOM_MARGIN - (RAISED_BOTTOM * ENABLE_RAISED_BOTTOM)));
end
function freq_to_x(freq)
ProQ3.Width = 340
return 0 + (340 * math.log(freq / 10) / 30000 );
end
function spectrum1_to_y(zo)
gfx_h = 190
return 0 + (1.0 - zo) * gfx_h ;
end
function _svf_ls(freq, q, gain)
A = gain; --10 ^ (gain / 40.0);
g = math.tan(math.pi * freq/SAMPLE_RATE) / math.sqrt(A);
k = 1.0 / q;
a1 = 1.0 / (1.0 + g * (g + k));
a2 = g * a1;
a3 = g * a2;
m0 = 1;
m1 = k*(A - 1);
m2 = (A * A - 1);
svf_set_coeffs(g, k, a1, a2, a3, m0, m1, m2);
end
function svf_ls(freq, q, gain)
nlp = 1;
onepole = 0;
_svf_ls(freq, q, gain);
end
function _svf_hs(freq, q, gain)
A = gain; --10 ^ (gain / 40.0);
g = math.tan(math.pi * freq/SAMPLE_RATE) * math.sqrt(A);
k = 1.0 / q;
a1 = 1.0 / (1.0 + g * (g + k));
a2 = g * a1;
a3 = g * a2;
m0 = A * A;
m1 = k * (1 - A) * A;
m2 = (1 - A * A);
svf_set_coeffs(g, k, a1, a2, a3, m0, m1, m2);
end
function svf_st(freq, q, gain)
nlp = 3;
onepole = 0;
gain2 = 10^((-gain) / 40);
gainn = 10^(gain / 40);
_svf_hs(freq, q, gainn);
--_svf_ls(freq, q, gain2)
A = gain2 ; --10 ^ (gain / 40.0);
g = math.tan(math.pi * freq/SAMPLE_RATE) / math.sqrt(A);
k = 1.0 / q;
a1 = 1.0 / (1.0 + g * (g + k));
a2 = g * a1;
a3 = a3+ g * a2;
m0 = m0 ;
m1 = m1+ k*(A - 1) ;
m2 = m2+ (A * A - 1);
end
function svf_hs(freq, q, gain)
nlp = 1;
onepole = 0;
_svf_hs(freq, q, gain);
end
function rbj_ls(freq, q, gain)
w0 = 2*math.pi * math.min(freq / SAMPLE_RATE, 0.49);
cos_w0 = math.cos(w0);
a = gain; --sqrt(gain);
tmp0 = 2 * math.sqrt(a) * math.sin(w0) / (2 * q);
tmp1 = (a + 1) - (a - 1) * cos_w0;
tmp2 = (a + 1) + (a - 1) * cos_w0;
b0 = a * (tmp1 + tmp0);
b1 = 2 * a * ((a - 1) - (a + 1) * cos_w0);
b2 = a * (tmp1 - tmp0);
a0 = tmp2 + tmp0;
a1 = -2 * ((a - 1) + (a + 1) * cos_w0);
a2 = tmp2 - tmp0;
return rbj_scale(a0);
end
function rbj_hs(freq, q, gain)
w0 = 2*math.pi * math.min(freq / SAMPLE_RATE, 0.49);
cos_w0 = math.cos(w0);
a = gain; --sqrt(gain);
tmp0 = 2 * math.sqrt(a) * math.sin(w0) / (2 * q);
tmp1 = (a + 1) - (a - 1) * cos_w0;
tmp2 = (a + 1) + (a - 1) * cos_w0;
b0 = a * (tmp2 + tmp0);
b1 = -2 * a * ((a - 1) + (a + 1) * cos_w0);
b2 = a * (tmp2 - tmp0);
a0 = tmp1 + tmp0;
a1 = 2 * ((a - 1) - (a + 1) * cos_w0);
a2 = tmp1 - tmp0;
return rbj_scale(a0);
end
function rbj_hp(freq, q)
w0 = 2*math.pi * math.min(freq / SAMPLE_RATE, 0.49);
cos_w0 = math.cos(w0);
alpha = math.sin(w0) / (2*q);
b1 = -1 - math.cos_w0;
b0 = b2
b2 = -0.5 * b1;
a0 = 1 + alpha;
a1 = -2 * math.cos_w0;
a2 = 1 - alpha;
return rbj_scale(a0);
end
function rbj_scale(a0)
local scale = 1/a0;
a1 = a1 * scale;
a2 = a2 * scale;
b0 = b0 * scale;
b1 = b1 * scale;
b2 = b2 * scale;
return a0
end
SAMPLE_RATE = 60000
function freq_to_scx(freq)
MAX_FREQ = 30000
MIN_FREQ = 10;
FREQ_LOG_MAX = math.log(MAX_FREQ / MIN_FREQ);
Witdth = 340
return ProQ3.Width * math.log(freq / MIN_FREQ) / FREQ_LOG_MAX;
end
function rbj_hp(freq, q)
w0 = 2* math.pi * math.min(freq / 60000, 0.49); --60000 is supposed to be sample rate
cos_w0 = math.cos(w0);
alpha = math.sin(w0) / (2*q);
b1 = -1 - cos_w0;
b0 = -0.5 * b1;
b2 = -0.5 * b1;
a0 = 1 + alpha;
a1 = -2 * cos_w0;
a2 = 1 - alpha;
return rbj_scale(a0)
end
function rbj_lp(freq, q)
w0 = 2* math.pi * math.min(freq / 60000, 0.49);
cos_w0 = math.cos(w0);
alpha = math.sin(w0) / (2*q);
b1 = 1 - cos_w0;
b0 = 0.5 * b1;
b2 = 0.5 * b1;
a0 = 1 + alpha;
a1 = -2 * cos_w0;
a2 = 1 - alpha;
return rbj_scale(a0);
end
function svf_onepole(mode, cutoff)
passtype = mode;
if passtype == 0 then
-- Low pass
W = math.tan(math.pi * cutoff / SAMPLE_RATE);
N = 1/(1+W);
B0 = W * N;
B1 = B0;
A1 = N * (W-1);
return A1
else
-- High pass
W = math.tan(math.pi * cutoff / SAMPLE_RATE);
N = 1/(1+W);
B0 = N;
B1 = -B0;
A1 = N * (W-1);
return A1
end
end
function svf_single_hp(freq, q)
g = math.tan(math.pi * freq/SAMPLE_RATE);
k = 1.0 / q;
a1 = 1.0 / (1.0 + g * (g + k));
a2 = g * a1;
a3 = g * a2;
m0 = 1.0;
m1 = -k;
m2 = -1.0;
--rbj_hp(freq, q);
svf_set_coeffs(g, k, a1, a2, a3, m0, m1, m2);
--svf_set_coeffs(g, k, a1, a2, a3, m0, m1, m2);
cutoff = freq;
op0 = svf_onepole(1, cutoff);
op1 = svf_onepole(1, cutoff);
return op0,op1
end
function zdf_single_lp(freq, q)
g = math.tan(math.pi * freq/SAMPLE_RATE);
k = 1.0 / q;
a1 = 1.0 / (1.0 + g * (g + k));
a2 = g * a1;
a3 = g * a2;
m0 = 0;
m1 = 0;
m2 = 1;
--rbj_lp(freq, q);
svf_set_coeffs(g, k, a1, a2, a3, m0, m1, m2);
--a1,a2,a3,m0,m1,m2 = zdf_set_coeffs(a1, a2, a3, m0, m1, m2);
cutoff = freq;
op0 = svf_onepole(0, cutoff)
op1 = svf_onepole(0, cutoff)
return op0, op1
end
function magnitude_to_01(m, freq)
ceiling = 0;
noise_floor = -90;
db = 10 * math.log10(m);
-- Tilt around 1kHz
if tilt ~= 0.0 then db = db+ tilt * ((math.log(freq) / math.log(2)) - (math.log(1024) / math.log(2))) end
return 1.0 - ((db - ceiling) / (noise_floor - ceiling));
end
function db_to_gain(db)
return 10^(db / 21); -- 21 is 40 in original script
end
function db_to_gain30(db)
return 10^(db / 21); -- 21 is 40 in original script
end
function zdf_lp(freq, q, slope)
--instance(nlp, cas1, cas2, cas3, cas4, cas5, cas6, cas7, cas8, cas9, onepole)
nlp = slope;
if slope == 0 then onepole = 1 else onepole = 0 end
cas0 = zdf_single_lp(freq, q);
cas1 = zdf_single_lp(freq, q);
cas2 = zdf_single_lp(freq, q);
cas3 = zdf_single_lp(freq, q);
cas4 = zdf_single_lp(freq, q);
cas5 = zdf_single_lp(freq, q);
cas6 = zdf_single_lp(freq, q);
cas7 = zdf_single_lp(freq, q);
cas8 = zdf_single_lp(freq, q);
cas9 = zdf_single_lp(freq, q);
return cas0,cas1,cas2,cas3,cas4,cas5,cas6,cas7,cas8,cas9
end
function svf_hp(freq, q, slope)
nlp = slope;
if slope == 0 then onepole = 1 else onepole = 0 end
cas0 = svf_single_hp(freq, q);
cas1 = svf_single_hp(freq, q);
cas2 = svf_single_hp(freq, q);
cas3 = svf_single_hp(freq, q);
cas4 = svf_single_hp(freq, q);
cas5 = svf_single_hp(freq, q);
cas6 = svf_single_hp(freq, q);
cas7 = svf_single_hp(freq, q);
cas8 = svf_single_hp(freq, q);
cas9 = svf_single_hp(freq, q);
return cas0,cas1,cas2,cas3,cas4,cas5,cas6,cas7,cas8,cas9
end
function svf_set_coeffs(tg, tk, ta1, ta2, ta3, tm0, tm1, tm2)
--instance(g, k, a1, a2, a3, m0, m1, m2, t_g, t_k, t_a1, t_a2, t_a3, t_m0, t_m1, t_m2, s_g, s_k, s_a1, s_a2, s_a3, s_m0, s_m1, s_m2, iter_t)
iter_t = 0.0;
-- Start coefficients
s_g = g;
s_k = k;
s_a1 = a1;
s_a2 = a2;
s_a3 = a3;
s_m0 = m0;
s_m1 = m1;
s_m2 = m2;
-- Target coefficients
t_g = tg;
t_k = tk;
t_a1 = ta1;
t_a2 = ta2;
t_a3 = ta3;
t_m0 = tm0;
t_m1 = tm1;
t_m2 = tm2;
end
function magnitude(freq)
-- instance(g, k, m0, m1, m2, a1, a2, a3)
--local(zr, zi, zrr, gsq, gm1, gk, twogsq, a, zsq_i, zsq_r, twoz_r, twoz_i, nr, ni, dr, di, norm, ddi, ddr, x, y, s)
-- exp(complex(0.0, -2.0 * pi) * frequency / sampleRate)
zr = 0.0;
zi = -2.0 * math.pi;
zr = zr * freq * ONE_OVER_SAMPLE_RATE;
zi = zi * freq * ONE_OVER_SAMPLE_RATE;
zr = math.exp(zr);
zrr = zr;
zr = zrr * math.cos(zi);
zi = zrr * math.sin(zi);
gsq = g * g;
gm1 = g * m1;
gk = g * k;
twogsq = gsq * 2.0;
-- z * z
a = zr * zr - zi * zi;
zsq_i = zi * zr + zr * zi;
zsq_r = a;
-- z * 2.0
twoz_r = zr * 2;
twoz_i = zi * 2;
-- Numerator complex
nr = gsq * m2 * (zsq_r + twoz_r + 1.0) - gm1 * (zsq_r - 1.0);
ni = gsq * m2 * (zsq_i + twoz_i) - gm1 * (zsq_i);
-- Denominator complex
dr = gsq + gk + zsq_r * (gsq - gk + 1.0) + zr * (twogsq - 2.0) + 1.0;
di = zsq_i * (gsq - gk + 1.0) + zi * (twogsq - 2.0);
-- Numerator / Denominator
norm = dr * dr + di * di;
a = (nr * dr + ni * di) / norm;
ddi = (ni * dr - nr * di) / norm;
ddr = a;
-- abs(m0_ + (Numerator / Denominator)
x = m0 + ddr;
y = ddi;
s = math.max(math.abs(x), math.abs(y));
x = x/ s;
y = y/ s;
-- Return magnitude
return s * math.sqrt(x * x + y * y);
end
function zdf_magnitude(freq)
--instance(rbj, nlp, onepole, cas1, cas2, cas3, cas4, cas5, cas6, cas7, cas8, cas9, cutoff, op0, op1)
--local(m)
-- Our svf magnitude maps to the same magnitude z transfer function as biquad
m = 1.0;
-- Apply two pole (12dB steps)
if nlp > 0 then m = m * magnitude(freq) end --12
if nlp > 2 then m = m * magnitude(freq) end
if nlp > 4 then m = m * magnitude(freq) end
if nlp > 6 then m = m * magnitude(freq) end
if nlp > 8 then m = m * magnitude(freq) end
if nlp > 10 then m = m * magnitude(freq ) end
if nlp > 12 then m = m * magnitude(freq ) end
if nlp > 14 then m = m * magnitude(freq ) end
if nlp > 16 then m = m * magnitude(freq ) end
if nlp > 18 then m = m * magnitude(freq ) end --120
-- Apply one pole (6dB)
if onepole == 1 then
wdcutoff = math.pi * (cutoff / SAMPLE_RATE);
coff = math.tan(wdcutoff);
wdeval = math.pi * (freq / SAMPLE_RATE);
svalue = math.tan(wdeval);
if passtype == 0 then
-- lp
m = m* 1.0 / math.sqrt(1 + ((svalue/coff)^2));
else
-- hp
m = m* 1.0 / math.sqrt(1 + ((coff/svalue)^2));
end
end
return m
end
function x_to_freq(x)
max_freq = 30000
min_freq = 10
x = min_freq * (Euler ^(freq_log_max * (x) / (340))); -- 340 is width
return math.max(math.min(x, max_freq), min_freq);
end
function freq_to_x_MyOwn(y)
Euler = 2.71828182845904523
return (340 * math.log(y/10, Euler)) / 8.00636757
end
for i=1, 340 , 1 do -- 340 is width
iToFreq = x_to_freq(i)
if iToFreq >50 and iToFreq <51 then iPos50 = i end
if iToFreq >99 and iToFreq <102 then iPos100 = i end
if iToFreq >198 and iToFreq <201 then iPos200 = i end
if iToFreq >490 and iToFreq <500 then iPos500 = i end
if iToFreq >990 and iToFreq <1020 then iPos1k = i end
if iToFreq >1980 and iToFreq <2010 then iPos2k = i end
if iToFreq >4900 and iToFreq <5050 then iPos5k = i end
if iToFreq >9990 and iToFreq <10300 then iPos10k = i end
end
function Calc_4ptBezier (x1, y1 , x2, y2, x3,y3,x4,y4,t)
X = (1 - t)^3*x1 + 3*(1 - t)^2*t*x2 + 3* (1 - t) *t^2*x3 + t^3*x4
Y = ( 1 - t)^3*y1 + 3*(1 - t)^2*t*y2 +3*(1 - t)*t^2*y3 + t^3*y4
return X, Y
end
-------------------Macros --------------------------
Mc={Val_Trk={}; V_Out={0,0,0,0,0,0,0,0,0}; Name={}}
Wet={DragLbl={};Val={};P_Num={}}
r.gmem_attach('gmemForSpectrum')
-- FXs listed here will not have a fx window in the script UI
BlackListFXs = {'Macros','JS: Macros .+', 'Frequency Spectrum Analyzer Meter', 'JS: FXD Split to 32 Channels', 'JS: FXD (Mix)RackMixer .+', 'FXD (Mix)RackMixer','JS: FXD Macros.jsfx', 'FXD Macros',
'JS: FXD ReSpectrum', 'AU: AULowpass (Apple)', 'AU: AULowpass', 'VST: FabFilter Pro C 2 ' , 'Pro-C 2', 'Pro C 2' , 'JS: FXD Split To 4 Channels.jsfx', 'JS: FXD Gain Reduction Scope.jsfx',
'JS: FXD Saike BandSplitter', 'JS: FXD Band Joiner'
}
UtilityFXs = {'Macros', 'JS: Macros /[.+', 'Frequency Spectrum Analyzer Meter', 'JS: FXD Split to 32 Channels', 'JS: FXD (Mix)RackMixer .+', 'FXD (Mix)RackMixer','JS: FXD Macros.jsfx', 'FXD Macros',
'JS: FXD ReSpectrum', 'JS: FXD Split To 4 Channels.jsfx', 'JS: FXD Gain Reduction Scope.jsfx', 'JS: FXD Band Joiner'
}
SpecialLayoutFXs = {'VST: FabFilter Pro C 2 ', 'Pro Q 3' , 'VST: FabFilter Pro Q 3 ', 'VST3: Pro Q 3 FabFilter' , 'VST3: Pro C 2 FabFilter', 'AU: Pro C 2 FabFilter' }
-------------General Functions ------------------------------
function SetMinMax(Input, Min,Max )
if Input >= Max then Input = Max
elseif Input <= Min then Input = Min
else Input = Input
end
return Input
end
function ToNum(str)
str = tonumber(str)
end
function toggle(v)
if v then v = false else v = true end
return v
end
function get_aftr_Equal(str)
if str then
local o = str:sub((str:find('=') or -2)+2)
if o == '' or o == ' ' then o = nil end
return o
end
end
function RecallInfo (Str,Id, Fx_P, Type, untilwhere)
if Str then
local Out,LineChange
local ID = Fx_P..'. '..Id..' = '
local Start, End = Str:find(ID)
if untilwhere then LineChange = Str:find(untilwhere ,Start)
else LineChange = Str:find('\n',Start)
end
if End and Str and LineChange then
if Type == 'Num' then Out = tonumber(string.sub(Str, End+1, LineChange-1))
elseif Type =='Bool' then
if string.sub(Str, End+1, LineChange-1) == 'true' then Out = true else Out = false end
else Out = string.sub(Str, End+1, LineChange-1)
end
end
if Out == '' then Out = nil end
return Out
end
end
function RecallGlobInfo(Str,ID, Type, untilwhere)
if Str then
local Out,LineChange
local Start, End = Str:find(ID)
if untilwhere then LineChange = Str:find(untilwhere ,Start)
else LineChange = Str:find('\n',Start)
end
if End and Str and LineChange then
if Type == 'Num' then Out = tonumber(string.sub(Str, End+1, LineChange-1))
elseif Type =='Bool' then
if string.sub(Str, End+1, LineChange-1) == 'true' then Out = true else Out = false end
else Out = string.sub(Str, End+1, LineChange-1)
end
end
if Out == '' then Out = nil end
return Out
end
end
function RecallIntoTable(Str,Id, Fx_P, Type)
if Str then
local _, End = Str:find(Id)
local T = {}
while End do
local NextLine = Str:find('\n', End) local EndPos
local NextSep = Str:find('|', End)
if NextSep and NextLine then
if NextSep> NextLine then End = nil
else
if Type =='Num' then table.insert(T, tonumber( Str:sub(End+1, NextSep-1)))
else table.insert(T, Str:sub(End+1, NextSep-1))
end
_, NewEnd = Str:find('|%d+=', End+1)
if NewEnd then
if NewEnd > NextLine then End = nil else End = NewEnd end
else End = nil
end
end
else End = nil
end
end
if T[1] then return T end
end
end
function get_aftr_Equal_bool(str)
if str then
local o = str:sub(str:find('=')+2)
if o == '' or o == ' ' or 0 == 'nil' then o = nil
elseif o =='true' then o = true
elseif o =='false' then o = false
else o = nil
end
return o
end
end
function get_aftr_Equal_Num(str)
if str then
if str:find('=') then
return tonumber(str:sub(str:find('=')+2))
end
else return nil
end
end
function OnlyNum(str)
return tonumber(str:gsub('[%D%.]', ''))
end
function get_lines(filename)
local lines = {}
-- io.lines returns an iterator, so we need to manually unpack it into an array
for line in io.lines(filename) do
lines[#lines+1] = line
end
return lines
end
function TableSwap(Table, Pos1, Pos2)