Merge branch 'master' of https://scm.cri.ensmp.fr/git/Faustine
[Faustine.git] / interpretor / faust-0.9.47mr3 / tools / faust2ck-1.0 / src / chuck_faust.template
1
2 #include "ugen_clip.h"
3 #include "chuck_type.h"
4 #include "chuck_ugen.h"
5 #include "chuck_vm.h"
6 #include "chuck_globals.h"
7
8 /* UI class - do-nothing (from FAUST/minimal.cpp) */
9
10 class UI
11 {
12 bool fStopped;
13 public:
14
15 UI() : fStopped(false) {}
16 virtual ~UI() {}
17
18 virtual void addButton(const char* label, float* zone) {}
19 virtual void addToggleButton(const char* label, float* zone) {}
20 virtual void addCheckButton(const char* label, float* zone) {}
21 virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) {}
22 virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) {}
23 virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step) {}
24
25 virtual void openFrameBox(const char* label) {}
26 virtual void openTabBox(const char* label) {}
27 virtual void openHorizontalBox(const char* label) {}
28 virtual void openVerticalBox(const char* label) {}
29 virtual void closeBox() {}
30
31 virtual void run() {}
32
33 void stop() { fStopped = true; }
34 bool stopped() { return fStopped; }
35 };
36
37 class dsp { public: float fSamplingFreq; };
38
39 /*
40 * FAUST intrinsic
41 */
42 <<includeIntrinsic>>
43
44 /*
45 * FAUST defines UI values as private, but provides no getters/setters.
46 * In our particular case it's way more convenient to access them directly
47 * than to set up a complicated UI structure. Also get rid of everything
48 * being "virtual", since it may stop the compiler from inlining properly!
49 */
50 #define private public
51 #define virtual
52
53 /* Rename the class the name of our DSP. */
54 #define mydsp %dsp_name%
55
56 /*
57 * FAUST class
58 */
59 <<includeclass>>
60
61 #undef private
62 #undef virtual
63 #undef mydsp
64
65 /*
66 * ChucK glue code
67 */
68 static t_CKUINT %dsp_name%_offset_data = 0;
69 static int g_sr = 44100;
70
71 static void %dsp_name%_ctor( Chuck_Object * SELF, void * ARGS, Chuck_VM_Shred * SHRED )
72 {
73 // return data to be used later
74 %dsp_name% *d = new %dsp_name%;
75 OBJ_MEMBER_UINT(SELF, %dsp_name%_offset_data) = (t_CKUINT)d;
76 d->init(g_sr);
77 }
78
79 static void %dsp_name%_dtor( Chuck_Object * SELF, Chuck_VM_Shred * SHRED )
80 {
81 delete (%dsp_name%*) OBJ_MEMBER_UINT(SELF, %dsp_name%_offset_data);
82 OBJ_MEMBER_UINT(SELF, %dsp_name%_offset_data) = 0;
83 }
84
85 static t_CKBOOL %dsp_name%_tick( Chuck_Object * SELF, float in, float * out, Chuck_VM_Shred * SHRED )
86 {
87 %dsp_name% *d = (%dsp_name%*)OBJ_MEMBER_UINT(SELF, %dsp_name%_offset_data);
88 float * input, * output;
89 input = &in;
90 output = out;
91 d->compute (1, &input, &output);
92 return TRUE;
93 }
94
95 %ctrl_cget_functions%
96
97 DLL_QUERY %dsp_name%_query( Chuck_DL_Query * QUERY )
98 {
99 Chuck_Env * env = Chuck_Env::instance();
100 Chuck_DL_Func * func = NULL;
101
102 g_sr = QUERY->srate;
103
104 if( !type_engine_import_ugen_begin( env, "%dsp_name%", "UGen", env->global(),
105 %dsp_name%_ctor, %dsp_name%_dtor, %dsp_name%_tick, NULL ) )
106 return FALSE;
107
108 // add member variable
109 %dsp_name%_offset_data = type_engine_import_mvar( env, "int", "@%dsp_name%_data", FALSE );
110 if( %dsp_name%_offset_data == CK_INVALID_OFFSET ) goto error;
111
112 %ctrl_cget_query%
113
114 // end import
115 if( !type_engine_import_class_end( env ) )
116 return FALSE;
117
118 return TRUE;
119
120 error:
121 // end import
122 if( !type_engine_import_class_end( env ) )
123 return FALSE;
124
125 return FALSE;
126 }