-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.cpp
13727 lines (11513 loc) · 485 KB
/
render.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
// Options :
#define MIDICTRL
#define OSCCTRL
/* ------------------------------------------------------------
name: "waveguide", "FaustDSP"
Code generated with Faust 2.40.7 (https://faust.grame.fr)
Compilation options: -a /usr/local/share/faust/bela.cpp -lang cpp -i -es 1 -mcd 16 -single -ftz 0
------------------------------------------------------------ */
#ifndef __mydsp_H__
#define __mydsp_H__
/************************************************************************
IMPORTANT NOTE : this file contains two clearly delimited sections :
the ARCHITECTURE section (in two parts) and the USER section. Each section
is governed by its own copyright and license. Please check individually
each section for license and copyright information.
*************************************************************************/
/******************* BEGIN bela.cpp ****************/
/************************************************************************
Bela FAUST Architecture file
Oli Larkin 2016
www.olilarkin.co.uk
Based on owl.cpp
FAUST Architecture File
Copyright (C) 2003-2019 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************
************************************************************************/
#ifndef __FaustBela_H__
#define __FaustBela_H__
#include <cstddef>
#include <string>
#include <iostream>
#include <math.h>
#include <strings.h>
#include <cstdlib>
#include <Bela.h>
#include <Utilities.h>
using namespace std;
/************************** BEGIN SimpleParser.h *********************
FAUST Architecture File
Copyright (C) 2003-2022 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
********************************************************************/
#ifndef SIMPLEPARSER_H
#define SIMPLEPARSER_H
// ---------------------------------------------------------------------
// Simple Parser
// A parser returns true if it was able to parse what it is
// supposed to parse and advance the pointer. Otherwise it returns false
// and the pointer is not advanced so that another parser can be tried.
// ---------------------------------------------------------------------
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <fstream>
#include <sstream>
#include <stdio.h> // We use the lighter fprintf code
#include <ctype.h>
#ifndef _WIN32
# pragma GCC diagnostic ignored "-Wunused-function"
#endif
struct itemInfo {
std::string type;
std::string label;
std::string url;
std::string address;
int index;
double init;
double fmin;
double fmax;
double step;
std::vector<std::pair<std::string, std::string> > meta;
itemInfo():index(0), init(0.), fmin(0.), fmax(0.), step(0.)
{}
};
// ---------------------------------------------------------------------
// Elementary parsers
// ---------------------------------------------------------------------
// Report a parsing error
static bool parseError(const char*& p, const char* errmsg)
{
fprintf(stderr, "Parse error : %s here : %s\n", errmsg, p);
return true;
}
/**
* @brief skipBlank : advance pointer p to the first non blank character
* @param p the string to parse, then the remaining string
*/
static void skipBlank(const char*& p)
{
while (isspace(*p)) { p++; }
}
// Parse character x, but don't report error if fails
static bool tryChar(const char*& p, char x)
{
skipBlank(p);
if (x == *p) {
p++;
return true;
} else {
return false;
}
}
/**
* @brief parseChar : parse a specific character x
* @param p the string to parse, then the remaining string
* @param x the character to recognize
* @return true if x was found at the begin of p
*/
static bool parseChar(const char*& p, char x)
{
skipBlank(p);
if (x == *p) {
p++;
return true;
} else {
return false;
}
}
/**
* @brief parseWord : parse a specific string w
* @param p the string to parse, then the remaining string
* @param w the string to recognize
* @return true if string w was found at the begin of p
*/
static bool parseWord(const char*& p, const char* w)
{
skipBlank(p);
const char* saved = p; // to restore position if we fail
while ((*w == *p) && (*w)) {++w; ++p;}
if (*w) {
p = saved;
return false;
} else {
return true;
}
}
/**
* @brief parseDouble : parse number [s]dddd[.dddd] or [s]d[.dddd][E|e][s][dddd] and store the result in x
* @param p the string to parse, then the remaining string
* @param x the float number found if any
* @return true if a float number was found at the begin of p
*/
static bool parseDouble(const char*& p, double& x)
{
double sign = 1.0; // sign of the number
double ipart = 0; // integral part of the number
double dpart = 0; // decimal part of the number before division
double dcoef = 1.0; // division factor for the decimal part
double expsign = 1.0; // sign of the E|e part
double expcoef = 0.0; // multiplication factor of E|e part
bool valid = false; // true if the number contains at least one digit
skipBlank(p);
const char* saved = p; // to restore position if we fail
// Sign
if (parseChar(p, '+')) {
sign = 1.0;
} else if (parseChar(p, '-')) {
sign = -1.0;
}
// Integral part
while (isdigit(*p)) {
valid = true;
ipart = ipart*10 + (*p - '0');
p++;
}
// Possible decimal part
if (parseChar(p, '.')) {
while (isdigit(*p)) {
valid = true;
dpart = dpart*10 + (*p - '0');
dcoef *= 10.0;
p++;
}
}
// Possible E|e part
if (parseChar(p, 'E') || parseChar(p, 'e')) {
if (parseChar(p, '+')) {
expsign = 1.0;
} else if (parseChar(p, '-')) {
expsign = -1.0;
}
while (isdigit(*p)) {
expcoef = expcoef*10 + (*p - '0');
p++;
}
}
if (valid) {
x = (sign*(ipart + dpart/dcoef)) * std::pow(10.0, expcoef*expsign);
} else {
p = saved;
}
return valid;
}
/**
* @brief parseString, parse an arbitrary quoted string q...q and store the result in s
* @param p the string to parse, then the remaining string
* @param quote the character used to quote the string
* @param s the (unquoted) string found if any
* @return true if a string was found at the begin of p
*/
static bool parseString(const char*& p, char quote, std::string& s)
{
std::string str;
skipBlank(p);
const char* saved = p; // to restore position if we fail
if (*p++ == quote) {
while ((*p != 0) && (*p != quote)) {
str += *p++;
}
if (*p++ == quote) {
s = str;
return true;
}
}
p = saved;
return false;
}
/**
* @brief parseSQString, parse a single quoted string '...' and store the result in s
* @param p the string to parse, then the remaining string
* @param s the (unquoted) string found if any
* @return true if a string was found at the begin of p
*/
static bool parseSQString(const char*& p, std::string& s)
{
return parseString(p, '\'', s);
}
/**
* @brief parseDQString, parse a double quoted string "..." and store the result in s
* @param p the string to parse, then the remaining string
* @param s the (unquoted) string found if any
* @return true if a string was found at the begin of p
*/
static bool parseDQString(const char*& p, std::string& s)
{
return parseString(p, '"', s);
}
// ---------------------------------------------------------------------
//
// IMPLEMENTATION
//
// ---------------------------------------------------------------------
/**
* @brief parseMenuItem, parse a menu item ...'low':440.0...
* @param p the string to parse, then the remaining string
* @param name the name found
* @param value the value found
* @return true if a nemu item was found
*/
static bool parseMenuItem(const char*& p, std::string& name, double& value)
{
const char* saved = p; // to restore position if we fail
if (parseSQString(p, name) && parseChar(p, ':') && parseDouble(p, value)) {
return true;
} else {
p = saved;
return false;
}
}
static bool parseMenuItem2(const char*& p, std::string& name)
{
const char* saved = p; // to restore position if we fail
// single quoted
if (parseSQString(p, name)) {
return true;
} else {
p = saved;
return false;
}
}
/**
* @brief parseMenuList, parse a menu list {'low' : 440.0; 'mid' : 880.0; 'hi' : 1760.0}...
* @param p the string to parse, then the remaining string
* @param names the vector of names found
* @param values the vector of values found
* @return true if a menu list was found
*/
static bool parseMenuList(const char*& p, std::vector<std::string>& names, std::vector<double>& values)
{
std::vector<std::string> tmpnames;
std::vector<double> tmpvalues;
const char* saved = p; // to restore position if we fail
if (parseChar(p, '{')) {
do {
std::string n;
double v;
if (parseMenuItem(p, n, v)) {
tmpnames.push_back(n);
tmpvalues.push_back(v);
} else {
p = saved;
return false;
}
} while (parseChar(p, ';'));
if (parseChar(p, '}')) {
// we suceeded
names = tmpnames;
values = tmpvalues;
return true;
}
}
p = saved;
return false;
}
static bool parseMenuList2(const char*& p, std::vector<std::string>& names, bool debug)
{
std::vector<std::string> tmpnames;
const char* saved = p; // to restore position if we fail
if (parseChar(p, '{')) {
do {
std::string n;
if (parseMenuItem2(p, n)) {
tmpnames.push_back(n);
} else {
goto error;
}
} while (parseChar(p, ';'));
if (parseChar(p, '}')) {
// we suceeded
names = tmpnames;
return true;
}
}
error:
if (debug) { fprintf(stderr, "parseMenuList2 : (%s) is not a valid list !\n", p); }
p = saved;
return false;
}
/// ---------------------------------------------------------------------
// Parse list of strings
/// ---------------------------------------------------------------------
static bool parseList(const char*& p, std::vector<std::string>& items)
{
const char* saved = p; // to restore position if we fail
if (parseChar(p, '[')) {
do {
std::string item;
if (!parseDQString(p, item)) {
p = saved;
return false;
}
items.push_back(item);
} while (tryChar(p, ','));
return parseChar(p, ']');
} else {
p = saved;
return false;
}
}
static bool parseMetaData(const char*& p, std::map<std::string, std::string>& metadatas)
{
const char* saved = p; // to restore position if we fail
std::string metaKey, metaValue;
if (parseChar(p, ':') && parseChar(p, '[')) {
do {
if (parseChar(p, '{') && parseDQString(p, metaKey) && parseChar(p, ':') && parseDQString(p, metaValue) && parseChar(p, '}')) {
metadatas[metaKey] = metaValue;
}
} while (tryChar(p, ','));
return parseChar(p, ']');
} else {
p = saved;
return false;
}
}
static bool parseItemMetaData(const char*& p, std::vector<std::pair<std::string, std::string> >& metadatas)
{
const char* saved = p; // to restore position if we fail
std::string metaKey, metaValue;
if (parseChar(p, ':') && parseChar(p, '[')) {
do {
if (parseChar(p, '{') && parseDQString(p, metaKey) && parseChar(p, ':') && parseDQString(p, metaValue) && parseChar(p, '}')) {
metadatas.push_back(std::make_pair(metaKey, metaValue));
}
} while (tryChar(p, ','));
return parseChar(p, ']');
} else {
p = saved;
return false;
}
}
// ---------------------------------------------------------------------
// Parse metadatas of the interface:
// "name" : "...", "inputs" : "...", "outputs" : "...", ...
// and store the result as key/value
/// ---------------------------------------------------------------------
static bool parseGlobalMetaData(const char*& p, std::string& key, std::string& value, double& dbl, std::map<std::string, std::string>& metadatas, std::vector<std::string>& items)
{
const char* saved = p; // to restore position if we fail
if (parseDQString(p, key)) {
if (key == "meta") {
return parseMetaData(p, metadatas);
} else {
return parseChar(p, ':') && (parseDQString(p, value) || parseList(p, items) || parseDouble(p, dbl));
}
} else {
p = saved;
return false;
}
}
// ---------------------------------------------------------------------
// Parse gui:
// "type" : "...", "label" : "...", "address" : "...", ...
// and store the result in uiItems Vector
/// ---------------------------------------------------------------------
static bool parseUI(const char*& p, std::vector<itemInfo>& uiItems, int& numItems)
{
const char* saved = p; // to restore position if we fail
if (parseChar(p, '{')) {
std::string label;
std::string value;
double dbl = 0;
do {
if (parseDQString(p, label)) {
if (label == "type") {
if (uiItems.size() != 0) {
numItems++;
}
if (parseChar(p, ':') && parseDQString(p, value)) {
itemInfo item;
item.type = value;
uiItems.push_back(item);
}
}
else if (label == "label") {
if (parseChar(p, ':') && parseDQString(p, value)) {
uiItems[numItems].label = value;
}
}
else if (label == "url") {
if (parseChar(p, ':') && parseDQString(p, value)) {
uiItems[numItems].url = value;
}
}
else if (label == "address") {
if (parseChar(p, ':') && parseDQString(p, value)) {
uiItems[numItems].address = value;
}
}
else if (label == "index") {
if (parseChar(p, ':') && parseDouble(p, dbl)) {
uiItems[numItems].index = int(dbl);
}
}
else if (label == "meta") {
if (!parseItemMetaData(p, uiItems[numItems].meta)) {
return false;
}
}
else if (label == "init") {
if (parseChar(p, ':') && parseDouble(p, dbl)) {
uiItems[numItems].init = dbl;
}
}
else if (label == "min") {
if (parseChar(p, ':') && parseDouble(p, dbl)) {
uiItems[numItems].fmin = dbl;
}
}
else if (label == "max") {
if (parseChar(p, ':') && parseDouble(p, dbl)) {
uiItems[numItems].fmax = dbl;
}
}
else if (label == "step") {
if (parseChar(p, ':') && parseDouble(p, dbl)) {
uiItems[numItems].step = dbl;
}
}
else if (label == "items") {
if (parseChar(p, ':') && parseChar(p, '[')) {
do {
if (!parseUI(p, uiItems, numItems)) {
p = saved;
return false;
}
} while (tryChar(p, ','));
if (parseChar(p, ']')) {
itemInfo item;
item.type = "close";
uiItems.push_back(item);
numItems++;
}
}
}
} else {
p = saved;
return false;
}
} while (tryChar(p, ','));
return parseChar(p, '}');
} else {
return true; // "items": [] is valid
}
}
// ---------------------------------------------------------------------
// Parse full JSON record describing a JSON/Faust interface :
// {"metadatas": "...", "ui": [{ "type": "...", "label": "...", "items": [...], "address": "...","init": "...", "min": "...", "max": "...","step": "..."}]}
//
// and store the result in map Metadatas and vector containing the items of the interface. Returns true if parsing was successfull.
/// ---------------------------------------------------------------------
static bool parseJson(const char*& p,
std::map<std::string, std::pair<std::string, double> >& metaDatas0,
std::map<std::string, std::string>& metaDatas1,
std::map<std::string, std::vector<std::string> >& metaDatas2,
std::vector<itemInfo>& uiItems)
{
parseChar(p, '{');
do {
std::string key;
std::string value;
double dbl = 0;
std::vector<std::string> items;
if (parseGlobalMetaData(p, key, value, dbl, metaDatas1, items)) {
if (key != "meta") {
// keep "name", "inputs", "outputs" key/value pairs
if (items.size() > 0) {
metaDatas2[key] = items;
items.clear();
} else if (value != "") {
metaDatas0[key].first = value;
} else {
metaDatas0[key].second = dbl;
}
}
} else if (key == "ui") {
int numItems = 0;
parseChar(p, '[') && parseUI(p, uiItems, numItems);
}
} while (tryChar(p, ','));
return parseChar(p, '}');
}
#endif // SIMPLEPARSER_H
/************************** END SimpleParser.h **************************/
/************************** BEGIN timed-dsp.h *****************************
FAUST Architecture File
Copyright (C) 2003-2022 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
***************************************************************************/
#ifndef __timed_dsp__
#define __timed_dsp__
#include <set>
#include <float.h>
#include <assert.h>
/************************** BEGIN dsp.h ********************************
FAUST Architecture File
Copyright (C) 2003-2022 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************/
#ifndef __dsp__
#define __dsp__
#include <string>
#include <vector>
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
struct UI;
struct Meta;
/**
* DSP memory manager.
*/
struct dsp_memory_manager {
virtual ~dsp_memory_manager() {}
/**
* Inform the Memory Manager with the number of expected memory zones.
* @param count - the number of expected memory zones
*/
virtual void begin(size_t count) {}
/**
* Give the Memory Manager information on a given memory zone.
* @param size - the size in bytes of the memory zone
* @param reads - the number of Read access to the zone used to compute one frame
* @param writes - the number of Write access to the zone used to compute one frame
*/
virtual void info(size_t size, size_t reads, size_t writes) {}
/**
* Inform the Memory Manager that all memory zones have been described,
* to possibly start a 'compute the best allocation strategy' step.
*/
virtual void end() {}
/**
* Allocate a memory zone.
* @param size - the memory zone size in bytes
*/
virtual void* allocate(size_t size) = 0;
/**
* Destroy a memory zone.
* @param ptr - the memory zone pointer to be deallocated
*/
virtual void destroy(void* ptr) = 0;
};
/**
* Signal processor definition.
*/
class dsp {
public:
dsp() {}
virtual ~dsp() {}
/* Return instance number of audio inputs */
virtual int getNumInputs() = 0;
/* Return instance number of audio outputs */
virtual int getNumOutputs() = 0;
/**
* Trigger the ui_interface parameter with instance specific calls
* to 'openTabBox', 'addButton', 'addVerticalSlider'... in order to build the UI.
*
* @param ui_interface - the user interface builder
*/
virtual void buildUserInterface(UI* ui_interface) = 0;
/* Return the sample rate currently used by the instance */
virtual int getSampleRate() = 0;
/**
* Global init, calls the following methods:
* - static class 'classInit': static tables initialization
* - 'instanceInit': constants and instance state initialization
*
* @param sample_rate - the sampling rate in Hz
*/
virtual void init(int sample_rate) = 0;
/**
* Init instance state
*
* @param sample_rate - the sampling rate in Hz
*/
virtual void instanceInit(int sample_rate) = 0;
/**
* Init instance constant state
*
* @param sample_rate - the sampling rate in Hz
*/
virtual void instanceConstants(int sample_rate) = 0;
/* Init default control parameters values */
virtual void instanceResetUserInterface() = 0;
/* Init instance state (like delay lines...) but keep the control parameter values */
virtual void instanceClear() = 0;
/**
* Return a clone of the instance.
*
* @return a copy of the instance on success, otherwise a null pointer.
*/
virtual dsp* clone() = 0;
/**
* Trigger the Meta* parameter with instance specific calls to 'declare' (key, value) metadata.
*
* @param m - the Meta* meta user
*/
virtual void metadata(Meta* m) = 0;
/**
* DSP instance computation, to be called with successive in/out audio buffers.
*
* @param count - the number of frames to compute
* @param inputs - the input audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, double or quad)
* @param outputs - the output audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, double or quad)
*
*/
virtual void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) = 0;
/**
* DSP instance computation: alternative method to be used by subclasses.
*
* @param date_usec - the timestamp in microsec given by audio driver.
* @param count - the number of frames to compute
* @param inputs - the input audio buffers as an array of non-interleaved FAUSTFLOAT samples (either float, double or quad)
* @param outputs - the output audio buffers as an array of non-interleaved FAUSTFLOAT samples (either float, double or quad)
*
*/
virtual void compute(double /*date_usec*/, int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) { compute(count, inputs, outputs); }
};
/**
* Generic DSP decorator.
*/
class decorator_dsp : public dsp {
protected:
dsp* fDSP;
public:
decorator_dsp(dsp* dsp = nullptr):fDSP(dsp) {}
virtual ~decorator_dsp() { delete fDSP; }
virtual int getNumInputs() { return fDSP->getNumInputs(); }
virtual int getNumOutputs() { return fDSP->getNumOutputs(); }
virtual void buildUserInterface(UI* ui_interface) { fDSP->buildUserInterface(ui_interface); }
virtual int getSampleRate() { return fDSP->getSampleRate(); }
virtual void init(int sample_rate) { fDSP->init(sample_rate); }
virtual void instanceInit(int sample_rate) { fDSP->instanceInit(sample_rate); }
virtual void instanceConstants(int sample_rate) { fDSP->instanceConstants(sample_rate); }
virtual void instanceResetUserInterface() { fDSP->instanceResetUserInterface(); }
virtual void instanceClear() { fDSP->instanceClear(); }
virtual decorator_dsp* clone() { return new decorator_dsp(fDSP->clone()); }
virtual void metadata(Meta* m) { fDSP->metadata(m); }
// Beware: subclasses usually have to overload the two 'compute' methods
virtual void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) { fDSP->compute(count, inputs, outputs); }
virtual void compute(double date_usec, int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) { fDSP->compute(date_usec, count, inputs, outputs); }
};
/**
* DSP factory class, used with LLVM and Interpreter backends
* to create DSP instances from a compiled DSP program.
*/
class dsp_factory {
protected:
// So that to force sub-classes to use deleteDSPFactory(dsp_factory* factory);
virtual ~dsp_factory() {}
public:
virtual std::string getName() = 0;
virtual std::string getSHAKey() = 0;
virtual std::string getDSPCode() = 0;
virtual std::string getCompileOptions() = 0;
virtual std::vector<std::string> getLibraryList() = 0;
virtual std::vector<std::string> getIncludePathnames() = 0;
virtual dsp* createDSPInstance() = 0;
virtual void setMemoryManager(dsp_memory_manager* manager) = 0;
virtual dsp_memory_manager* getMemoryManager() = 0;
};
// Denormal handling
#if defined (__SSE__)
#include <xmmintrin.h>
#endif
class ScopedNoDenormals
{
private:
intptr_t fpsr;
void setFpStatusRegister(intptr_t fpsr_aux) noexcept
{
#if defined (__arm64__) || defined (__aarch64__)
asm volatile("msr fpcr, %0" : : "ri" (fpsr_aux));
#elif defined (__SSE__)
_mm_setcsr(static_cast<uint32_t>(fpsr_aux));
#endif
}
void getFpStatusRegister() noexcept
{
#if defined (__arm64__) || defined (__aarch64__)
asm volatile("mrs %0, fpcr" : "=r" (fpsr));
#elif defined ( __SSE__)
fpsr = static_cast<intptr_t>(_mm_getcsr());
#endif
}
public:
ScopedNoDenormals() noexcept
{
#if defined (__arm64__) || defined (__aarch64__)
intptr_t mask = (1 << 24 /* FZ */);
#else
#if defined(__SSE__)
#if defined(__SSE2__)
intptr_t mask = 0x8040;
#else
intptr_t mask = 0x8000;
#endif
#else
intptr_t mask = 0x0000;
#endif
#endif
getFpStatusRegister();
setFpStatusRegister(fpsr | mask);
}
~ScopedNoDenormals() noexcept
{
setFpStatusRegister(fpsr);
}
};
#define AVOIDDENORMALS ScopedNoDenormals();
#endif
/************************** END dsp.h **************************/
/************************** BEGIN GUI.h **********************************
FAUST Architecture File
Copyright (C) 2003-2022 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
*************************************************************************/
#ifndef __GUI_H__
#define __GUI_H__
#include <list>
#include <map>
#include <vector>
#include <assert.h>
#ifdef _WIN32
# pragma warning (disable: 4100)
#else
# pragma GCC diagnostic ignored "-Wunused-parameter"
#endif