-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
XAir_fxparse.c
562 lines (498 loc) · 17.3 KB
/
XAir_fxparse.c
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
//
// fxparse.c
//
// Created on: 25 oct. 2014
// Author: Patrick-Gilles Maillot
//
// This/These functions deal only with Effects, parsing scene data to float/int data sent to X32;
// They are called in/from X32SetScene()
// They are common to fparse1.c and fparse5.c
//
//
// change Log: July 14, 2016 - line 203, test should be done against PQ5S, not PQ5
//
#include <stdio.h>
#include <string.h>
#include <math.h>
extern int Xsprint(char *bd, int index, char format, void *bs);
extern float Xr_float();
extern FILE* Xin;
// pointers to known Effect names for effects 5-8
extern char* l_fmode[];
extern int ll_fmode;
extern char* l_fwave[];
extern int ll_fwave;
extern char* l_srange[];
extern int ll_srange;
extern char* l_plfreq[];
extern int ll_plfreq;
extern char* l_phfreq[];
extern int ll_phfreq;
extern char* l_pasel[];
extern int ll_pasel;
extern char* l_qllfreq[];
extern int ll_qllfreq;
extern char* l_qmlfreq[];
extern int ll_qmlfreq;
extern char* l_qhlfreq[];
extern int ll_qhlfreq;
extern char* l_rulc[];
extern int ll_rulc;
//
// Macros
//
// log2float: The principle is to convert to y [0, 1] a data comprised between
// xmin and xmax in the log domain. We apply an afine conversion to get the value:
// y = (log(x) - log(xmin)) / (log(xmax) - log(xmin)), all log are base 10.
// -1- logs can simplify to ln (neper base) easily (log10(x) = ln(x)/ln(10))
// -2- ln(a) - ln(b) = ln(a/b)
// The applied formula becomes
// y = ln(x / xmin) / ln (xmax / xmin)
// in the macro: x is the returned value of Xr_float(), a = xmin, and b = ln (xmax / xmin)
#define log2float(a,b) do { \
fval = log(Xr_float() / a) / b; \
k = Xsprint(buf, k, 'f', &fval); \
} while (0)
// afine2float: The principle is to convert to y [0, 1] a data comprised between
// xmin and xmax in the linear domain. We apply an afine conversion to get the value:
// y = (x - xmin) / (xmax - xmin)
// in the macro: x is the returned value of Xr_float(), a = xmin, and b = (xmax - xmin)
#define afine2float(a,b) do { \
fval = ((Xr_float() - a) / b); \
k = Xsprint(buf, k, 'f', &fval); \
} while (0)
// ratio2float: The principle is to convert to y [0, 1] a data comprised between
// xmin and xmax in the linear domain with a special case of xmin = 0. We apply a
// simple conversion to get the value:
// y = x / xmax
// in the macro: x is the retuned value of Xr_float(), a = xmax
#define ratio2float(a) do { \
fval = (Xr_float() / a); \
k = Xsprint(buf, k, 'f', &fval); \
} while (0)
// toggle2int: The principle is to convert to y [0 or 1]integer a string data
// that can take two values. We only test the value corresponding to result = 0.
// All other string values will convert to result = 1.
// in the macro: a points to the character string corresponding to result = 0.
#define toggle2int(a) do { \
ival = fscanf(Xin, "%s", llread); \
if (strcmp(llread, a) == 0) ival = 0; \
else ival = 1; \
k = Xsprint(buf, k, 'i', &ival); \
} while (0)
// list2int: The principle is to convert to y [0 to n]integer a string data
// that can take multiple values. We test values until we get a corresponding result.
// in the macro: l_list points to an array of character strings corresponding valid
// values and l_len is the array size. If the data is not found, the macro returns
// value of 0.
#define list2int(l_list, l_len) do { \
ival = fscanf(Xin, "%s", llread); \
ival = 0; \
for (mi = 0; mi < l_len; mi++) { \
if (strcmp(llread, l_list[mi]) == 0) { \
ival = mi; \
break; \
} \
} \
k = Xsprint(buf, k, 'i', &ival); \
} while (0)
int XGEQ2_TEQ2(char* buf, int k) {
int i;
float fval;
k = Xsprint(buf, k, 's', ",ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
for (i = 0; i < 64; i++) afine2float(-15.,30.); // EQ values [-15, 15]
return (k);
}
int XGEQ_TEQ(char* buf, int k) {
int i;
float fval;
k = Xsprint(buf, k, 's', ",ffffffffffffffffffffffffffffffff");
for (i = 0; i < 32; i++) afine2float(-15.,30.); // EQ values [-15, 15]
return (k);
}
int XDES_DES2(char* buf, int k, int ifx, int DES2, int DES) {
float fval;
int ival;
char llread[16];
k = Xsprint(buf, k, 's', ",ffffii");
ratio2float(50.); // lo band [0, 50]
ratio2float(50.); // hi band [0, 50]
ratio2float(50.); // lo band [0, 50]
ratio2float(50.); // hi band [0, 50]
toggle2int("FEM"); // voice [FEM / MALE]
if (ifx == DES2) toggle2int("FEM"); // voice [FEM / MALE]
else if (ifx == DES) {
// toggle2int("ST"); // voice [ST / M/S]
// Start of Special Handling for DES Bug.
// XAir Edit saves FEM/MALE instead of "ST/MS"
ival = fscanf(Xin, "%s", llread);
ival = 0; // Failsafe
if ((strcmp(llread, "FEM") == 0) || (strcmp(llread, "ST") == 0)) ival = 0;
if ((strcmp(llread, "MALE") == 0) || (strcmp(llread, "MS") == 0)) ival = 1;
k = Xsprint(buf, k, 'i', &ival);
}
return (k);
}
int XPIA_PIA2(char* buf, int k, int ifx, int P1A2, int P1A) {
float fval;
int mi, ival;
char llread[16];
if (ifx == P1A) k = Xsprint(buf, k, 's', ",iffifffifii");
else if (ifx == P1A2) k = Xsprint(buf, k, 's', ",iffifffifiiiffifffifii");
toggle2int("OFF"); // active [OFF / ON]
afine2float(-12., 24.); // gain [-12, 12]
ratio2float(10.); // lo boost [0, 10]
list2int(l_plfreq, ll_plfreq); // lo freq [0, 30, 60, 100]
ratio2float(10.); // lo attenuation [0, 10]
ratio2float(10.); // hi width [0, 10]
ratio2float(10.); // hi boost [0, 10]
list2int(l_phfreq, ll_phfreq); // lo freq [3K, 4K, 5K, 8K, 10K, 12K, 16K]
ratio2float(10.); // hi attenuation [0, 10]
list2int(l_pasel, ll_pasel); // lo freq [5K, 10K, 20K]
toggle2int("OFF"); // transformer [OFF / ON]
if (ifx == P1A2) {
toggle2int("OFF"); // active [OFF / ON]
afine2float(-12., 24.); // gain [-12, 12]
ratio2float(10.); // lo boost [0, 10]
list2int(l_plfreq, ll_plfreq); // lo freq [0, 30, 60, 100]
ratio2float(10.); // lo attenuation [0, 10]
ratio2float(10.); // hi width [0, 10]
ratio2float(10.); // hi boost [0, 10]
list2int(l_phfreq, ll_phfreq); // lo freq [3K, 4K, 5K, 8K, 10K, 12K, 16K]
ratio2float(10.); // hi attenuation [0, 10]
list2int(l_pasel, ll_pasel); // lo freq [5K, 10K, 20K]
toggle2int("OFF"); // transformer [OFF / ON]
}
return (k);
}
int XPQ5_PQ5S(char* buf, int k, int ifx, int PQ5S, int PQ5) {
float fval;
int mi, ival;
char llread[16];
if (ifx == PQ5) k = Xsprint(buf, k, 's', ",ififififi");
else if (ifx == PQ5S) k = Xsprint(buf, k, 's', ",ififififiififififi");
toggle2int("OFF"); // active [OFF / ON]
afine2float(-12., 24.); // gain [-12, 12]
list2int(l_qllfreq, ll_qllfreq); // lo freq [200, 300, 500, 700, 1000]
ratio2float(10.); // lo boost [0, 10]
list2int(l_qmlfreq, ll_qmlfreq); // mid freq [200, 300, 500, 700, 1k, 1k5, 2k, 3k, 4k, 5k, 7k]
ratio2float(10.); // mid boost [0, 10]
list2int(l_qhlfreq, ll_qhlfreq); // hi freq [1k5, 2k, 3k, 4k, 5k]
ratio2float(10.); // hi boost [0, 10]
toggle2int("OFF"); // transformer [OFF / ON]
if (ifx == PQ5S) {
toggle2int("OFF"); // active [OFF / ON]
afine2float(-12., 24.); // gain [-12, 12]
list2int(l_qllfreq, ll_qllfreq); // lo freq [200, 300, 500, 700, 1000]
ratio2float(10.); // lo boost [0, 10]
list2int(l_qmlfreq, ll_qmlfreq); // mid freq [200, 300, 500, 700, 1k, 1k5, 2k, 3k, 4k, 5k, 7k]
ratio2float(10.); // mid boost [0, 10]
list2int(l_qhlfreq, ll_qhlfreq); // hi freq [1k5, 2k, 3k, 4k, 5k]
ratio2float(10.); // hi boost [0, 10]
toggle2int("OFF"); // transformer [OFF / ON]
}
return (k);
}
int XWAVD(char* buf, int k) {
float fval;
k = Xsprint(buf, k, 's', ",ffffff");
afine2float(-100., 200.); // attack A [-100, 100]
afine2float(-100., 200.); // sustain A [-100, 100]
afine2float(-24., 48.); // gain A [-24, 24]]
afine2float(-100., 200.); // attack B [-100, 100]
afine2float(-100., 200.); // sustain B [-100, 100]
afine2float(-24., 48.); // gain B [-24, 24]]
return (k);
}
int XLIM(char* buf, int k) {
float fval;
int ival;
char llread[16];
k = Xsprint(buf, k, 's', ",ffffffii");
ratio2float(18.); // input gain [0, 18]
afine2float(-18., 18.); // out gain [-18, 0]
ratio2float(100.); // squeeze [0, 100]
ratio2float(10.); // knee [0, 10]
log2float(0.05, 2.995732274); // attack[0.05, 1]
log2float(20., 4.605170186); // release[20, 2000]
toggle2int("OFF"); // stereo link [OFF / ON]
toggle2int("OFF"); // auto gain [OFF / ON]
return (k);
}
int XFAC_FAC1M_FAC2(char* buf, int k, int ifx, int FAC2, int FAC1M, int FAC) {
float fval;
int ival, i, j;
char llread[16];
j = 1;
if (ifx == FAC) {
k = Xsprint(buf, k, 's', ",iffffff");
}
else if (ifx == FAC1M || ifx == FAC2) {
k = Xsprint(buf, k, 's', ",iffffffiffffff");
j = 2;
}
for (i = 0; i < j; i++) {
toggle2int("OFF"); // active [OFF / ON]
afine2float(-20., 20.); // input gain [-20, 0]
ratio2float(10.); // threshold [0, 10]
ratio2float(6.); // time [0, 6]
ratio2float(100.); // bias [0, 100]
afine2float(-18., 24.); // gain [-18, 6]
afine2float(-100., 200.); // balance [-100, 100]
}
return(k);
}
int XLEC_LEC2(char* buf, int k, int ifx, int LEC2, int LEC) {
float fval;
int ival, i, j;
char llread[16];
j = 1;
if (ifx == LEC){
k = Xsprint(buf, k, 's', ",iffif");
} else if (ifx == LEC2) {
k = Xsprint(buf, k, 's', ",iffififfif");
j = 2;
}
for (i = 0; i < j; i++) {
toggle2int("OFF"); // active [OFF / ON]
ratio2float(100.); // gain [0, 100]
ratio2float(100.); // peak [0, 100]
toggle2int("COMP"); // mode [COMP, LIM]
afine2float(-18., 24.); // gain [-18, 6]
}
return (k);
}
int XULC_ULC2(char* buf, int k, int ifx, int ULC2, int ULC) {
float fval;
int ival, mi, i, j;
char llread[16];
j = 1;
if (ifx == ULC){
k = Xsprint(buf, k, 's', ",iffffi");
} else if (ifx == ULC2) {
k = Xsprint(buf, k, 's', ",iffffiiffffi");
j = 2;
}
for (i = 0; i < j; i++) {
toggle2int("OFF"); // active [OFF / ON]
afine2float(-48., 48.); // input gain [-48, 0]
afine2float(-48., 48.); // out gain [-48, 0]
afine2float(1., 6.); // attack [1, 7]
afine2float(1., 6.); // release [1, 7]
list2int(l_rulc, ll_rulc); // ratio [4, 8, 12, 20, ALL]
}
return (k);
}
int XENH_ENH2(char* buf, int k, int ifx, int ENH2, int ENH) {
float fval;
int ival, i, j;
char llread[16];
j = 1;
if (ifx == ENH){
k = Xsprint(buf, k, 's', ",ffffffffi");
} else if (ifx == ENH2) {
k = Xsprint(buf, k, 's', ",ffffffffiffffffffi");
j = 2;
}
for (i = 0; i < j; i++) {
afine2float(-12., 24.); // out gain [-12, 12]
ratio2float(100.); // spead [0, 100]
ratio2float(100.); // bass gain [0, 100]
afine2float(1., 49.); // bass freq [1, 50]
ratio2float(100.); // mid gain [0, 100]
afine2float(1., 49.); // mid q [1, 50]
ratio2float(100.); // hi gain [0, 100]
afine2float(1., 49.); // hi freq [1, 50]
toggle2int("OFF"); // solo [OFF / ON]
}
return (k);
}
int XEXC_EXC2(char* buf, int k, int ifx, int EXC2, int EXC) {
float fval;
int ival, i, j;
char llread[16];
j = 1;
if (ifx == EXC){
k = Xsprint(buf, k, 's', ",ffffffi");
} else if (ifx == EXC2) {
k = Xsprint(buf, k, 's', ",ffffffiffffffi");
j = 2;
}
for (i = 0; i < j; i++) {
log2float(1000., 2.302585093); // tune [1k, 10k]
ratio2float(100.); // peak [0, 100]
ratio2float(100.); // zero fill [0, 100]
afine2float(-50., 100); // timbre [-50, 50]
ratio2float(100.); // harmonics [0, 100]
ratio2float(100.); // mix [0, 100]
toggle2int("OFF"); // solo [OFF / ON]
}
return (k);
}
int XIMG(char* buf, int k) {
float fval;
k = Xsprint(buf, k, 's', ",fffffff");
afine2float(-100., 200.); // balance [-100, 100]
afine2float(-100., 200.); // mono pan [-100, 100]
afine2float(-100., 200.); // stereo pan [-100, 100]
ratio2float(12.); // shv gain [0, 12]
log2float(100., 2.302585093); // shv freq [100, 1000]
log2float(1., 2.302585093); // shv q [1, 10]
afine2float(-12., 24.); // out gain [-12, 12]
return (k);
}
int XEDI(char* buf, int k) {
float fval;
int ival;
char llread[16];
k = Xsprint(buf, k, 's', ",iiifffff");
toggle2int("OFF"); // active [OFF / ON]
toggle2int("ST"); // stereo input [ST / M/S]
toggle2int("ST"); // stereo output [ST / M/S]
afine2float(-50., 100); // st spread [-50, 50]
afine2float(-50., 100); // lmf spread [-50, 50]
afine2float(-50., 100); // balance [-50, 50]
afine2float(-50., 100); // center distance [-50, 50]
afine2float(-12., 24.); // out gain [-12, 12]
return (k);
}
int XSON(char* buf, int k) {
float fval;
int ival;
char llread[16];
k = Xsprint(buf, k, 's', ",ifffifff");
toggle2int("OFF"); // active [OFF / ON]
ratio2float(10.); // lo contour [0, 10]
ratio2float(10.); // process [0, 10]
afine2float(-12., 24.); // out gain [-12, 12]
toggle2int("OFF"); // active [OFF / ON]
ratio2float(10.); // lo contour [0, 10]
ratio2float(10.); // process [0, 10]
afine2float(-12., 24.); // out gain [-12, 12]
return (k);
}
int XAMP_AMP2(char* buf, int k, int ifx, int AMP2, int AMP) {
float fval;
int ival, i, j;
char llread[16];
j = 1;
if (ifx == AMP){
k = Xsprint(buf, k, 's', ",ffffffffi");
} else if (ifx == AMP2) {
k = Xsprint(buf, k, 's', ",ffffffffiffffffffi");
j = 2;
}
for (i = 0; i < j; i++) {
ratio2float(10.); // preamp [0, 10]
ratio2float(10.); // buzz [0, 10]
ratio2float(10.); // punch [0, 10]
ratio2float(10.); // crunch [0, 10]
ratio2float(10.); // drive [0, 10]
ratio2float(10.); // low [0, 10]
ratio2float(10.); // high [0, 10]
ratio2float(10.); // level [0, 10]
toggle2int("OFF"); // cabinet [OFF / ON]
}
return (k);
}
int XDRV_DRV2(char* buf, int k, int ifx, int DRV2, int DRV) {
float fval;
int i, j;
j = 1;
if (ifx == DRV){
k = Xsprint(buf, k, 's', ",ffffffffff");
} else if (ifx == DRV2) {
k = Xsprint(buf, k, 's', ",ffffffffffffffffffff");
j = 2;
}
for (i = 0; i < j; i++) {
ratio2float(100.); // drive [0, 100]
ratio2float(50.); // even ear [0, 50]
ratio2float(50.); // odd ear [0, 50]
afine2float(-12, 24.); // gain [-12, 12]
log2float(20., 2.302585093); // lo cut [20, 200]
log2float(4000., 1.609437912); // hi cut [4k, 20k]
afine2float(-12, 24.); // lo gain [-12, 12]
log2float(50., 2.079441542); // lo freq [50, 400]
afine2float(-12, 24.); // hi gain [-12, 12]
log2float(1000., 2.302585093); // hi freq [1k, 10k]
}
return (k);
}
int XPHAS(char* buf, int k) {
float fval;
k = Xsprint(buf, k, 's', ",ffffffffffff");
log2float(0.05, 4.605170186); // speed HZ [0.05, 5]
ratio2float(100.); // depth [0, 100]
ratio2float(80.); // resonance [0, 80]
ratio2float(50.); // base [0, 50]
afine2float(2., 10.); // stages [2, 12]
ratio2float(100.); // mix [0, 100]
afine2float(-50.,100.); // wave [-50, 50]
ratio2float(180.); // phase [0, 180]
afine2float(-100.,200.); // env. modulation [-100, 100]
log2float(10., 4.605170186); // attack [10, 1000]
log2float(1., 7.60090246); // hold [1, 2000]
log2float(10., 4.605170186); // release [10, 1000]
return (k);
}
int XFILT(char* buf, int k) {
float fval;
int ival, mi;
char llread[16];
k = Xsprint(buf, k, 's', ",ffffififffffii");
log2float(0.05, 5.991464547); // speed HZ [0.05, 20]
ratio2float(100.); // depth [0, 100]
ratio2float(100.); // resonance [0, 100]
log2float(20., 6.620073207); // base [20 , 15000]
list2int(l_fmode, ll_fmode); // mode [LP, HP, BP, NO]
ratio2float(100.); // mix [0, 100]
list2int(l_fwave, ll_fwave); // wave [TRI, SIN, SAW, SAW-, RMP, SQU. RND]
ratio2float(180.); // phase [0, 180]
afine2float(-100.,200.); // env. modulation [-100, 100]
log2float(10., 3.218875825); // attack [10, 250]
log2float(10., 3.912023005); // Release [10, 500]
ratio2float(100.); // drive [0, 100]
// toggle2int("2POL"); // 4 pole [off/on]
// Special Handling for FILT Bug.
// XAir Edit saves 2POL/4POL but /node returns OFF/ON.
ival = fscanf(Xin, "%s", llread);
ival = 0; // Failsafe
if ((strcmp(llread, "2POL") == 0) || (strcmp(llread, "OFF") == 0)) ival = 0;
if ((strcmp(llread, "4POL") == 0) || (strcmp(llread, "ON") == 0)) ival = 1;
k = Xsprint(buf, k, 'i', &ival);
// End of Special Handling
toggle2int("OFF"); // sidechain [off/on]
return (k);
}
int XPAN(char* buf, int k) {
float fval;
k = Xsprint(buf, k, 's', ",fffffffff");
log2float(0.05, 4.605170186); // speed HZ [0.05, 5]
ratio2float(180.); // phase [0, 180]
afine2float(-50.,100.); // wave [-50, 50]
ratio2float(100.); // depth [0, 100]
ratio2float(100.); // env speed [0, 100]
ratio2float(100.); // env depth [0, 100]
log2float(10., 4.605170186); // attack [10, 1000]
log2float(1., 7.60090246); // hold [1, 2000]
log2float(10., 4.605170186); // release [10, 1000]
return (k);
}
int XSUB(char* buf, int k) {
float fval;
int ival, mi;
char llread[16];
k = Xsprint(buf, k, 's', ",iifffiifff");
toggle2int("OFF"); // active [off/on]
list2int(l_srange, ll_srange); // range [LO, MID, HI]
ratio2float(100.); // dry [0, 100]
ratio2float(100.); // octave -1 [0, 100]
ratio2float(100.); // octave -2 [0, 100]
toggle2int("OFF"); // active [off/on]
list2int(l_srange, ll_srange); // range [LO, MID, HI]
ratio2float(100.); // dry [0, 100]
ratio2float(100.); // octave -1 [0, 100]
ratio2float(100.); // octave -2 [0, 100]
return (k);
}