File: DspFaust.h

package info (click to toggle)
faust 2.30.5~ds0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 279,348 kB
  • sloc: cpp: 239,368; javascript: 32,310; ansic: 17,442; sh: 11,925; java: 5,903; objc: 3,879; makefile: 3,030; cs: 1,139; python: 987; ruby: 951; xml: 693; yacc: 537; lex: 239; lisp: 201; awk: 110
file content (514 lines) | stat: -rw-r--r-- 20,177 bytes parent folder | download
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
/************************************************************************
 ************************************************************************
 FAUST API Architecture File
 Copyright (C) 2016 GRAME, Romain Michon, CCRMA - Stanford University
 Copyright (C) 2014-2016 GRAME, Centre National de Creation Musicale
 ---------------------------------------------------------------------

 This is sample code. This file is provided as an example of minimal
 FAUST architecture file. Redistribution and use in source and binary
 forms, with or without modification, in part or in full are permitted.
 In particular you can create a derived work of this FAUST architecture
 and distribute that work under terms of your choice.

 This sample code 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.
 ************************************************************************
 ************************************************************************/

#ifndef __faust_api__
#define __faust_api__

#include <cstdint>

//===============API Reference==============
//==========================================

class FaustPolyEngine;
class MidiUI;
class OSCUI;
class JuceOSCUI;
class SoundUI;
class audio;
class dsp;
class UI;
class dsp_factory;

class DspFaust
{

    private:

        FaustPolyEngine* fPolyEngine;

    #if OSCCTRL
    #if JUCE_DRIVER
        JuceOSCUI* fOSCInterface;
    #else
        OSCUI* fOSCInterface;
    #endif
    #endif

    #if MIDICTRL
        MidiUI* fMidiInterface;
    #endif

    #if SOUNDFILE
        SoundUI* fSoundInterface;
    #endif

    #if DYNAMIC_DSP
        dsp_factory* fFactory;
    #endif

        void init(dsp* mono_dsp, audio* driver);
        audio* createDriver(int sample_rate, int buffer_size, bool auto_connect = true);

    public:

        //--------------`DspFaust()`----------------
        // Default constructor, to be used wih audio drivers
        /// that impose their sample rate and buffer size
        // (like JACK and JUCE)
        //
        // #### Arguments
        //
        // * `auto_connect`: whether to automatically connect audio outpus to the hardware (usable with JACK)
        //----
        DspFaust(bool auto_connect = true);

        //--------------`DspFaust(int SR, int BS)`----------------
        // Constructor.
        //
        // #### Arguments
        //
        // * `SR`: sampling rate
        // * `BS`: buffer size
        // * `auto_connect`: whether to automatically connect audio outputs to the hardware (usable with JACK)
        //--------------------------------------------------------
        DspFaust(int, int, bool auto_connect = true);

        //--------------`DspFaust(const string& dsp_content, int SR, int BS)`----------------
        // Constructor.
        //
        // #### Arguments
        //
        // * `dsp_content`: the DSP as a file or string
        // * `SR`: sampling rate
        // * `BS`: buffer size
        // * `auto_connect`: whether to automatically connect audio outputs to the hardware (usable with JACK)
        //--------------------------------------------------------
    #if DYNAMIC_DSP
        DspFaust(const std::string&, int, int, bool auto_connect = true);
    #endif

        // No virtual destructor since DspFaust does not have any virtual methods and is not supposed to be subclassed
        ~DspFaust();

        //---------------------`bool start()`---------------------
        // Start the audio processing.
        //
        // Returns `true` if successful and `false` if not.
        //--------------------------------------------------------
        bool start();

        //-----------------`void stop()`--------------------------
        // Stop the audio processing.
        //--------------------------------------------------------
        void stop();

        //---------------------`bool isRunning()`-----------------
        // Returns `true` if audio is running.
        //--------------------------------------------------------
        bool isRunning();

        //--------`long keyOn(int pitch, int velocity)`-----------
        // Instantiate a new polyphonic voice. This method can
        // only be used if the `[style:poly]` metadata is used in
        // the Faust code or if the `-polyvoices` flag has been
        // provided before compilation.
        //
        // `keyOn` will return 0 if the Faust object is not
        // polyphonic or the address to the allocated voice as
        // a `uintptr_t` otherwise. This value can be used later with
        // [`setVoiceParamValue`](#setvoiceparamvalue) or
        // [`getVoiceParamValue`](#getvoiceparamvalue) to access
        // the parameters of a specific voice.
        //
        // #### Arguments
        //
        // * `pitch`: MIDI note number (0-127)
        // * `velocity`: MIDI velocity (0-127)
        //--------------------------------------------------------
        uintptr_t keyOn(int, int);

        //----------------`int keyOff(int pitch)`-----------------
        // De-instantiate a polyphonic voice. This method can
        // only be used if the `[style:poly]` metadata is used in
        // the Faust code or if the `-nvoices` flag has been
        // provided before compilation.
        //
        // `keyOff` will return 0 if the object is not polyphonic
        // and 1 otherwise.
        //
        // #### Arguments
        //
        // * `pitch`: MIDI note number (0-127), should be the same
        // as the one used for `keyOn`
        //--------------------------------------------------------
        int keyOff(int);

        //-------------------`uintptr_t newVoice()`--------------------
        // Instantiate a new polyphonic voice. This method can
        // only be used if the `[style:poly]` metadata is used in
        // the Faust code or if `-nvoices` flag has been
        // provided before compilation.
        //
        // `newVoice` will return 0 if the Faust object is not
        // polyphonic or the address to the allocated voice as
        // a `uintptr_t` otherwise. This value can be used later with
        // `setVoiceParamValue`, `getVoiceParamValue` or
        // `deleteVoice` to access the parameters of a specific
        // voice.
        //--------------------------------------------------------
        uintptr_t newVoice();

        //---------`int deleteVoice(uintptr_t voice)`------------------
        // De-instantiate a polyphonic voice. This method can
        // only be used if the `[style:poly]` metadata is used in
        // the Faust code or if `-nvoices` flag has been
        // provided before compilation.
        //
        // `deleteVoice` will return 0 if the object is not polyphonic
        // and 1 otherwise.
        //
        // #### Arguments
        //
        // * `voice`: the address of the voice given by `newVoice`
        //--------------------------------------------------------
        int deleteVoice(uintptr_t);

        //-----------------`void allNotesOff()`----------------
        // Terminates all the active voices, gently (with release when hard = false or immediately when hard = true).
        //--------------------------------------------------------
        void allNotesOff(bool hard = false);
   
        //-------`void propagateMidi(int count, double time, int type, int channel, int data1, int data2)`--------
        // Take a raw MIDI message and propagate it to the Faust
        // DSP object. This method can be used concurrently with
        // [`keyOn`](#keyOn) and [`keyOff`](#keyOff).
        //
        // `propagateMidi` can
        // only be used if the `[style:poly]` metadata is used in
        // the Faust code or if `-nvoices` flag has been
        // provided before compilation.
        //
        // #### Arguments
        //
        // * `count`: size of the message (1-3)
        // * `time`: time stamp
        // * `type`: message type (byte)
        // * `channel`: channel number
        // * `data1`: first data byte (should be `null` if `count<2`)
        // * `data2`: second data byte (should be `null` if `count<3`)
        //--------------------------------------------------------
        void propagateMidi(int, double, int, int, int, int);

        //-----------------`const char* getJSONUI()`----------------
        // Returns the JSON description of the UI of the Faust object.
        //--------------------------------------------------------
        const char* getJSONUI();

        //-----------------`const char* getJSONMeta()`----------------
        // Returns the JSON description of the metadata of the Faust object.
        //--------------------------------------------------------
        const char* getJSONMeta();

        //--------------`void buildUserInterface(UI* ui_interface)`---------------
        // Calls the polyphonic or monophonic buildUserInterface with the ui_interface parameter.
        //
        // #### Arguments
        //
        // * `ui_interface`: an UI* object
        //--------------------------------------------------------
        void buildUserInterface(UI*);

        //-----------------`int getParamsCount()`-----------------
        // Returns the number of parameters of the Faust object.
        //--------------------------------------------------------
        int getParamsCount();

        //----`void setParamValue(const char* address, float value)`------
        // Set the value of one of the parameters of the Faust
        // object in function of its address (path).
        //
        // #### Arguments
        //
        // * `address`: address (path) of the parameter
        // * `value`: value of the parameter
        //--------------------------------------------------------
        void setParamValue(const char*, float);

        //----`void setParamValue(int id, float value)`---
        // Set the value of one of the parameters of the Faust
        // object in function of its id.
        //
        // #### Arguments
        //
        // * `id`: id of the parameter
        // * `value`: value of the parameter
        //--------------------------------------------------------
        void setParamValue(int, float);

        //----`float getParamValue(const char* address)`----------
        // Returns the value of a parameter in function of its
        // address (path).
        //
        // #### Arguments
        //
        // * `address`: address (path) of the parameter
        //--------------------------------------------------------
        float getParamValue(const char*);

        //---------`float getParamValue(int id)`----------
        // Returns the value of a parameter in function of its
        // id.
        //
        // #### Arguments
        //
        // * `id`: id of the parameter
        //--------------------------------------------------------
        float getParamValue(int);

        //----`void setVoiceParamValue(const char* address, uintptr_t voice, float value)`-----
        // Set the value of one of the parameters of the Faust
        // object in function of its address (path) for a
        // specific voice.
        //
        // #### Arguments
        //
        // * `address`: address (path) of the parameter
        // * `voice`: address of the polyphonic voice (retrieved
        // from `keyOn`
        // * `value`: value of the parameter
        //--------------------------------------------------------
        void setVoiceParamValue(const char*, uintptr_t, float);

        //----`void setVoiceValue(int id, uintptr_t voice, float value)`-----
        // Set the value of one of the parameters of the Faust
        // object in function of its id for a
        // specific voice.
        //
        // #### Arguments
        //
        // * `id`: id of the parameter
        // * `voice`: address of the polyphonic voice (retrieved
        // from `keyOn`
        // * `value`: value of the parameter
        //--------------------------------------------------------
        void setVoiceParamValue(int, uintptr_t, float);

        //----`float getVoiceParamValue(const char* address, uintptr_t voice)`----
        // Returns the value of a parameter in function of its
        // address (path) for a specific voice.
        //
        // #### Arguments
        //
        // * `address`: address (path) of the parameter
        // * `voice`: address of the polyphonic voice (retrieved
        // from `keyOn`)
        //--------------------------------------------------------
        float getVoiceParamValue(const char*, uintptr_t);

        //----`float getVoiceParamValue(int id, uintptr_t voice)`----
        // Returns the value of a parameter in function of its
        // id for a specific voice.
        //
        // #### Arguments
        //
        // * `id`: id of the parameter
        // * `voice`: address of the polyphonic voice (retrieved
        // from `keyOn`)
        //--------------------------------------------------------
        float getVoiceParamValue(int, uintptr_t);

        //----`const char* getParamAddress(int id)`---------------
        // Returns the address (path) of a parameter in function
        // of its ID.
        //
        // #### Arguments
        //
        // * `id`: id of the parameter
        //--------------------------------------------------------
        const char* getParamAddress(int);

        //----`const char* getVoiceParamAddress(int id, uintptr_t voice)`-----
        // Returns the address (path) of a parameter in function
        // of its ID.
        //
        // #### Arguments
        //
        // * `id`: id of the parameter
        // * `voice`: address of the polyphonic voice (retrieved
        // from `keyOn`)
        //--------------------------------------------------------
        const char* getVoiceParamAddress(int, uintptr_t);

        //-------`float getParamMin(const char* address)`---------
        // Returns the minimum value of a parameter in function of
        // its address (path).
        //
        // #### Arguments
        //
        // * `address`: address (path) of the parameter
        //--------------------------------------------------------
        float getParamMin(const char*);

        //--------------`float getParamMin(int id)`---------------
        // Returns the minimum value of a parameter in function
        // of its ID.
        //
        // #### Arguments
        //
        // * `id`: id of the parameter
        //--------------------------------------------------------
        float getParamMin(int);

        //-------`float getParamMax(const char* address)`---------
        // Returns the maximum value of a parameter in function of
        // its address (path).
        //
        // #### Arguments
        //
        // * `address`: address (path) of the parameter
        //--------------------------------------------------------
        float getParamMax(const char*);

        //--------------`float getParamMax(int id)`---------------
        // Returns the maximum value of a parameter in function
        // of its ID.
        //
        // #### Arguments
        //
        // * `id`: id of the parameter
        //--------------------------------------------------------
        float getParamMax(int);

        //-------`float getParamInit(const char* address)`---------
        // Returns the default value of a parameter in function of
        // its address (path).
        //
        // #### Arguments
        //
        // * `address`: address (path) of the parameter
        //--------------------------------------------------------
        float getParamInit(const char*);

        //--------------`float getParamInit(int id)`---------------
        // Returns the default value of a parameter in function
        // of its ID.
        //
        // #### Arguments
        //
        // * `id`: id of the parameter
        //--------------------------------------------------------
        float getParamInit(int);

        //-----`const char* getMetadata(const char* address, const char* key)`-----
        // Returns the metadataof a parameter in function of
        // its address (path) and the metadata key.
        //
        // #### Arguments
        //
        // * `address`: address (path) of the parameter
        //--------------------------------------------------------
        const char* getMetadata(const char*, const char*);

        //----`const char* getMetadata(int id, const char* key)`---------------
        // Returns the metadataof a parameter in function of
        // its iD and the metadata key.
        //
        // #### Arguments
        //
        // * `id`: id of the parameter
        //--------------------------------------------------------
        const char* getMetadata(int, const char*);

        //----`void propagateAcc(int acc, float v)`---------------
        // Propagate the RAW value of a specific accelerometer
        // axis to the Faust object.
        //
        // #### Arguments
        //
        // * `acc`: the accelerometer axis (**0**: x, **1**: y, **2**: z)
        // * `v`: the RAW acceleromter value in m/s
        //--------------------------------------------------------
        void propagateAcc(int, float);

        //----`void setAccConverter(int p, int acc, int curve, float amin, float amid, float amax)`-----
        // Set the conversion curve for the accelerometer.
        //
        // #### Arguments
        //
        // * `p`: the UI parameter id
        // * `acc`: the accelerometer axis (**0**: x, **1**: y, **2**: z)
        // * `curve`: the curve (**0**: up, **1**: down, **2**: up and down)
        // * `amin`: mapping min point
        // * `amid`: mapping middle point
        // * `amax`: mapping max point
        //--------------------------------------------------------
        void setAccConverter(int, int, int, float, float, float);

        //----`void propagateGyr(int gyr, float v)`---------------
        // Propagate the RAW value of a specific gyroscope
        // axis to the Faust object.
        //
        // #### Arguments
        //
        // * `gyr`: the gyroscope axis (**0**: x, **1**: y, **2**: z)
        // * `v`: the RAW acceleromter value in m/s
        //--------------------------------------------------------
        void propagateGyr(int, float);

        //----`void setGyrConverter(int p, int gyr, int curve, float amin, float amid, float amax)`-----
        // Set the conversion curve for the gyroscope.
        //
        // #### Arguments
        //
        // * `p`: the UI parameter id
        // * `gyr`: the gyroscope axis (**0**: x, **1**: y, **2**: z)
        // * `curve`: the curve (**0**: up, **1**: down, **2**: up and down)
        // * `amin`: mapping min point
        // * `amid`: mapping middle point
        // * `amax`: mapping max point
        //--------------------------------------------------------
        void setGyrConverter(int, int, int, float, float, float);

        //------------------`float getCPULoad()`------------------
        // Returns the CPU load (between 0 and 1.0).
        //--------------------------------------------------------
        float getCPULoad();

        //----`void configureOSC(int xmit, int inport, int outport, int errport, const char* address)`---------------
        // Change the OSC configuration.
        //
        // #### Arguments
        //
        // * `xmit`: the xmit state (off-0 all-1 alias-2)
        // * `inport`: the input port number
        // * `outport`: the output port number
        // * `errport`: the error port number
        // * `address`: the destination IP address
        //--------------------------------------------------------
        bool configureOSC(int xmit, int inport, int outport, int errport, const char* address);

        //----------`bool isOSCOn()`---------------
        // Return OSC Status.
        //-----------------------------------------
        bool isOSCOn();
    
        int getScreenColor();
};

#endif