1 /************************************************************************
2 ************************************************************************
3 FAUST Architecture File
4 Copyright (C) 2006-2011 Albert Graef <Dr.Graef@t-online.de>
5 ---------------------------------------------------------------------
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 ************************************************************************
21 ************************************************************************/
23 /* Q architecture file. Derived from minimal.cpp included in the Faust
24 distribution. Please note that this is to be compiled as a shared library,
25 which is then loaded dynamically by Q's faust module. */
32 void declare (const char* key
, const char* value
) { }
35 //-------------------------------------------------------------------
36 // Generic min and max using c++ inline
37 //-------------------------------------------------------------------
39 inline int max (unsigned int a
, unsigned int b
) { return (a
>b
) ? a
: b
; }
40 inline int max (int a
, int b
) { return (a
>b
) ? a
: b
; }
42 inline long max (long a
, long b
) { return (a
>b
) ? a
: b
; }
43 inline long max (int a
, long b
) { return (a
>b
) ? a
: b
; }
44 inline long max (long a
, int b
) { return (a
>b
) ? a
: b
; }
46 inline float max (float a
, float b
) { return (a
>b
) ? a
: b
; }
47 inline float max (int a
, float b
) { return (a
>b
) ? a
: b
; }
48 inline float max (float a
, int b
) { return (a
>b
) ? a
: b
; }
49 inline float max (long a
, float b
) { return (a
>b
) ? a
: b
; }
50 inline float max (float a
, long b
) { return (a
>b
) ? a
: b
; }
52 inline double max (double a
, double b
) { return (a
>b
) ? a
: b
; }
53 inline double max (int a
, double b
) { return (a
>b
) ? a
: b
; }
54 inline double max (double a
, int b
) { return (a
>b
) ? a
: b
; }
55 inline double max (long a
, double b
) { return (a
>b
) ? a
: b
; }
56 inline double max (double a
, long b
) { return (a
>b
) ? a
: b
; }
57 inline double max (float a
, double b
) { return (a
>b
) ? a
: b
; }
58 inline double max (double a
, float b
) { return (a
>b
) ? a
: b
; }
61 inline int min (int a
, int b
) { return (a
<b
) ? a
: b
; }
63 inline long min (long a
, long b
) { return (a
<b
) ? a
: b
; }
64 inline long min (int a
, long b
) { return (a
<b
) ? a
: b
; }
65 inline long min (long a
, int b
) { return (a
<b
) ? a
: b
; }
67 inline float min (float a
, float b
) { return (a
<b
) ? a
: b
; }
68 inline float min (int a
, float b
) { return (a
<b
) ? a
: b
; }
69 inline float min (float a
, int b
) { return (a
<b
) ? a
: b
; }
70 inline float min (long a
, float b
) { return (a
<b
) ? a
: b
; }
71 inline float min (float a
, long b
) { return (a
<b
) ? a
: b
; }
73 inline double min (double a
, double b
) { return (a
<b
) ? a
: b
; }
74 inline double min (int a
, double b
) { return (a
<b
) ? a
: b
; }
75 inline double min (double a
, int b
) { return (a
<b
) ? a
: b
; }
76 inline double min (long a
, double b
) { return (a
<b
) ? a
: b
; }
77 inline double min (double a
, long b
) { return (a
<b
) ? a
: b
; }
78 inline double min (float a
, double b
) { return (a
<b
) ? a
: b
; }
79 inline double min (double a
, float b
) { return (a
<b
) ? a
: b
; }
81 // abs is now predefined
82 //template<typename T> T abs (T a) { return (a<T(0)) ? -a : a; }
85 inline int lsr (int x
, int n
) { return int(((unsigned int)x
) >> n
); }
87 /******************************************************************************
88 *******************************************************************************
92 *******************************************************************************
93 *******************************************************************************/
95 //inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((unsigned)(calloc((nmemb*size)+15,sizeof(char)))+15 & 0xfffffff0); }
96 //inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((size_t)(calloc((nmemb*size)+15,sizeof(char)))+15 & ~15); }
100 /******************************************************************************
101 *******************************************************************************
103 ABSTRACT USER INTERFACE
105 *******************************************************************************
106 *******************************************************************************/
113 UI() : fStopped(false) {}
116 virtual void addButton(char* label
, float* zone
) = 0;
117 virtual void addToggleButton(char* label
, float* zone
) = 0;
118 virtual void addCheckButton(char* label
, float* zone
) = 0;
119 virtual void addVerticalSlider(char* label
, float* zone
, float init
, float min
, float max
, float step
) = 0;
120 virtual void addHorizontalSlider(char* label
, float* zone
, float init
, float min
, float max
, float step
) = 0;
121 virtual void addNumEntry(char* label
, float* zone
, float init
, float min
, float max
, float step
) = 0;
123 virtual void addNumDisplay(char* label
, float* zone
, int precision
) = 0;
124 virtual void addTextDisplay(char* label
, float* zone
, char* names
[], float min
, float max
) = 0;
125 virtual void addHorizontalBargraph(char* label
, float* zone
, float min
, float max
) = 0;
126 virtual void addVerticalBargraph(char* label
, float* zone
, float min
, float max
) = 0;
128 virtual void openFrameBox(char* label
) = 0;
129 virtual void openTabBox(char* label
) = 0;
130 virtual void openHorizontalBox(char* label
) = 0;
131 virtual void openVerticalBox(char* label
) = 0;
132 virtual void closeBox() = 0;
134 virtual void run() = 0;
136 void stop() { fStopped
= true; }
137 bool stopped() { return fStopped
; }
139 virtual void declare(float* zone
, const char* key
, const char* value
) {}
142 /***************************************************************************
144 ***************************************************************************/
146 enum ui_elem_type_t
{
147 UI_BUTTON
, UI_TOGGLE_BUTTON
, UI_CHECK_BUTTON
,
148 UI_V_SLIDER
, UI_H_SLIDER
, UI_NUM_ENTRY
,
149 UI_V_BARGRAPH
, UI_H_BARGRAPH
,
150 UI_END_GROUP
, UI_V_GROUP
, UI_H_GROUP
, UI_T_GROUP
158 float init
, min
, max
, step
;
161 class QUI
: public UI
171 void add_elem(ui_elem_type_t type
, char *label
= NULL
);
172 void add_elem(ui_elem_type_t type
, char *label
, float *zone
);
173 void add_elem(ui_elem_type_t type
, char *label
, float *zone
,
174 float init
, float min
, float max
, float step
);
175 void add_elem(ui_elem_type_t type
, char *label
, float *zone
,
176 float min
, float max
);
179 virtual void addButton(char* label
, float* zone
);
180 virtual void addToggleButton(char* label
, float* zone
);
181 virtual void addCheckButton(char* label
, float* zone
);
182 virtual void addVerticalSlider(char* label
, float* zone
, float init
, float min
, float max
, float step
);
183 virtual void addHorizontalSlider(char* label
, float* zone
, float init
, float min
, float max
, float step
);
184 virtual void addNumEntry(char* label
, float* zone
, float init
, float min
, float max
, float step
);
186 virtual void addNumDisplay(char* label
, float* zone
, int precision
);
187 virtual void addTextDisplay(char* label
, float* zone
, char* names
[], float min
, float max
);
188 virtual void addHorizontalBargraph(char* label
, float* zone
, float min
, float max
);
189 virtual void addVerticalBargraph(char* label
, float* zone
, float min
, float max
);
191 virtual void openFrameBox(char* label
);
192 virtual void openTabBox(char* label
);
193 virtual void openHorizontalBox(char* label
);
194 virtual void openVerticalBox(char* label
);
195 virtual void closeBox();
208 if (elems
) free(elems
);
211 inline void QUI::add_elem(ui_elem_type_t type
, char *label
)
213 ui_elem_t
*elems1
= (ui_elem_t
*)realloc(elems
, (nelems
+1)*sizeof(ui_elem_t
));
218 elems
[nelems
].type
= type
;
219 elems
[nelems
].label
= label
;
220 elems
[nelems
].zone
= NULL
;
221 elems
[nelems
].ref
= NULL
;
222 elems
[nelems
].init
= 0.0;
223 elems
[nelems
].min
= 0.0;
224 elems
[nelems
].max
= 0.0;
225 elems
[nelems
].step
= 0.0;
229 inline void QUI::add_elem(ui_elem_type_t type
, char *label
, float *zone
)
231 ui_elem_t
*elems1
= (ui_elem_t
*)realloc(elems
, (nelems
+1)*sizeof(ui_elem_t
));
236 elems
[nelems
].type
= type
;
237 elems
[nelems
].label
= label
;
238 elems
[nelems
].zone
= zone
;
239 elems
[nelems
].ref
= NULL
;
240 elems
[nelems
].init
= 0.0;
241 elems
[nelems
].min
= 0.0;
242 elems
[nelems
].max
= 0.0;
243 elems
[nelems
].step
= 0.0;
247 inline void QUI::add_elem(ui_elem_type_t type
, char *label
, float *zone
,
248 float init
, float min
, float max
, float step
)
250 ui_elem_t
*elems1
= (ui_elem_t
*)realloc(elems
, (nelems
+1)*sizeof(ui_elem_t
));
255 elems
[nelems
].type
= type
;
256 elems
[nelems
].label
= label
;
257 elems
[nelems
].zone
= zone
;
258 elems
[nelems
].ref
= NULL
;
259 elems
[nelems
].init
= init
;
260 elems
[nelems
].min
= min
;
261 elems
[nelems
].max
= max
;
262 elems
[nelems
].step
= step
;
266 inline void QUI::add_elem(ui_elem_type_t type
, char *label
, float *zone
,
267 float min
, float max
)
269 ui_elem_t
*elems1
= (ui_elem_t
*)realloc(elems
, (nelems
+1)*sizeof(ui_elem_t
));
274 elems
[nelems
].type
= type
;
275 elems
[nelems
].label
= label
;
276 elems
[nelems
].zone
= zone
;
277 elems
[nelems
].ref
= NULL
;
278 elems
[nelems
].init
= 0.0;
279 elems
[nelems
].min
= min
;
280 elems
[nelems
].max
= max
;
281 elems
[nelems
].step
= 0.0;
285 void QUI::addButton(char* label
, float* zone
)
286 { add_elem(UI_BUTTON
, label
, zone
); }
287 void QUI::addToggleButton(char* label
, float* zone
)
288 { add_elem(UI_TOGGLE_BUTTON
, label
, zone
); }
289 void QUI::addCheckButton(char* label
, float* zone
)
290 { add_elem(UI_CHECK_BUTTON
, label
, zone
); }
291 void QUI::addVerticalSlider(char* label
, float* zone
, float init
, float min
, float max
, float step
)
292 { add_elem(UI_V_SLIDER
, label
, zone
, init
, min
, max
, step
); }
293 void QUI::addHorizontalSlider(char* label
, float* zone
, float init
, float min
, float max
, float step
)
294 { add_elem(UI_H_SLIDER
, label
, zone
, init
, min
, max
, step
); }
295 void QUI::addNumEntry(char* label
, float* zone
, float init
, float min
, float max
, float step
)
296 { add_elem(UI_NUM_ENTRY
, label
, zone
, init
, min
, max
, step
); }
298 // FIXME: addNumDisplay and addTextDisplay not implemented in Faust yet?
299 void QUI::addNumDisplay(char* label
, float* zone
, int precision
) {}
300 void QUI::addTextDisplay(char* label
, float* zone
, char* names
[], float min
, float max
) {}
301 void QUI::addHorizontalBargraph(char* label
, float* zone
, float min
, float max
)
302 { add_elem(UI_H_BARGRAPH
, label
, zone
, min
, max
); }
303 void QUI::addVerticalBargraph(char* label
, float* zone
, float min
, float max
)
304 { add_elem(UI_V_BARGRAPH
, label
, zone
, min
, max
); }
306 void QUI::openFrameBox(char* label
) {}
307 void QUI::openTabBox(char* label
)
308 { add_elem(UI_T_GROUP
, label
); }
309 void QUI::openHorizontalBox(char* label
)
310 { add_elem(UI_H_GROUP
, label
); }
311 void QUI::openVerticalBox(char* label
)
312 { add_elem(UI_V_GROUP
, label
); }
314 { add_elem(UI_END_GROUP
); }
318 /******************************************************************************
319 *******************************************************************************
323 *******************************************************************************
324 *******************************************************************************/
328 //----------------------------------------------------------------
329 // abstract definition of a signal processor
330 //----------------------------------------------------------------
338 virtual int getNumInputs() = 0;
339 virtual int getNumOutputs() = 0;
340 virtual void buildUserInterface(UI
* interface
) = 0;
341 virtual void init(int samplingRate
) = 0;
342 virtual void compute(int len
, float** inputs
, float** outputs
) = 0;
345 //----------------------------------------------------------------------------
346 // FAUST generated signal processor
347 //----------------------------------------------------------------------------
352 /* The class factory, used to create and destroy mydsp objects in the
353 client. Implemented using C linkage to facilitate dlopen access. */
355 extern "C" dsp
*newdsp()
357 mydsp
*d
= new mydsp();
361 extern "C" void deldsp(dsp
* d
)