1
/************************************************************************
2
************************************************************************
3
FAUST Architecture File
4
Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
5
---------------------------------------------------------------------
7
This is sample code. This file is provided as an example of minimal
8
FAUST architecture file. Redistribution and use in source and binary
9
forms, with or without modification, in part or in full are permitted.
10
In particular you can create a derived work of this FAUST architecture
11
and distribute that work under terms of your choice.
13
This sample code is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
************************************************************************
17
************************************************************************/
45
41
*******************************************************************************
46
42
*******************************************************************************/
48
//inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((unsigned)(calloc((nmemb*size)+15,sizeof(char)))+15 & 0xfffffff0); }
49
//inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((size_t)(calloc((nmemb*size)+15,sizeof(char)))+15 & ~15); }
51
44
<<includeIntrinsic>>
53
/******************************************************************************
54
*******************************************************************************
56
GRAPHIC USER INTERFACE (v2)
59
*******************************************************************************
60
*******************************************************************************/
69
typedef void (*uiCallback)(float val, void* data);
72
* Graphic User Interface : abstract definition
77
typedef list<uiItem*> clist;
78
typedef map<float*, clist*> zmap;
81
static list<UI*> fGuiList;
87
UI() : fStopped(false) {
88
fGuiList.push_back(this);
92
// suppression de this dans fGuiList
97
void registerZone(float* z, uiItem* c)
99
if (fZoneMap.find(z) == fZoneMap.end()) fZoneMap[z] = new clist();
100
fZoneMap[z]->push_back(c);
103
void updateAllZones();
105
void updateZone(float* z);
107
static void updateAllGuis()
109
list<UI*>::iterator g;
110
for (g = fGuiList.begin(); g != fGuiList.end(); g++) {
111
(*g)->updateAllZones();
117
virtual void addButton(const char* label, float* zone) = 0;
118
virtual void addToggleButton(const char* label, float* zone) = 0;
119
virtual void addCheckButton(const char* label, float* zone) = 0;
120
virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0;
121
virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0;
122
virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step) = 0;
124
// -- passive widgets
126
virtual void addNumDisplay(const char* label, float* zone, int precision) = 0;
127
virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) = 0;
128
virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) = 0;
129
virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) = 0;
131
void addCallback(float* zone, uiCallback foo, void* data);
133
// -- widget's layouts
135
virtual void openFrameBox(const char* label) = 0;
136
virtual void openTabBox(const char* label) = 0;
137
virtual void openHorizontalBox(const char* label) = 0;
138
virtual void openVerticalBox(const char* label) = 0;
139
virtual void closeBox() = 0;
141
virtual void show() = 0;
142
virtual void run() = 0;
144
void stop() { fStopped = true; }
145
bool stopped() { return fStopped; }
150
* User Interface Item: abstract definition
161
uiItem (UI* ui, float* zone) : fGUI(ui), fZone(zone), fCache(-123456.654321)
163
ui->registerZone(zone, this);
171
void modifyZone(float v)
176
fGUI->updateZone(fZone);
180
float cache() { return fCache; }
181
virtual void reflectZone() = 0;
189
struct uiCallbackItem : public uiItem
191
uiCallback fCallback;
194
uiCallbackItem(UI* ui, float* zone, uiCallback foo, void* data)
195
: uiItem(ui, zone), fCallback(foo), fData(data) {}
197
virtual void reflectZone() {
206
* Update all user items reflecting zone z
209
inline void UI::updateZone(float* z)
212
clist* l = fZoneMap[z];
213
for (clist::iterator c = l->begin(); c != l->end(); c++) {
214
if ((*c)->cache() != v) (*c)->reflectZone();
220
* Update all user items not up to date
223
inline void UI::updateAllZones()
225
for (zmap::iterator m = fZoneMap.begin(); m != fZoneMap.end(); m++) {
227
clist* l = m->second;
229
for (clist::iterator c = l->begin(); c != l->end(); c++) {
230
if ((*c)->cache() != v) (*c)->reflectZone();
235
inline void UI::addCallback(float* zone, uiCallback foo, void* data)
237
new uiCallbackItem(this, zone, foo, data);
243
//----------------------------------------------------------------
244
// d�inition du processeur de signal
245
//----------------------------------------------------------------
254
virtual int getNumInputs() = 0;
255
virtual int getNumOutputs() = 0;
256
virtual void buildUserInterface(UI* interface) = 0;
257
virtual void init(int samplingRate) = 0;
258
virtual void compute(int len, float** inputs, float** outputs) = 0;
259
virtual void conclude() {}
46
//----------------------------------------------------------------
47
// Signal processor definition
48
//----------------------------------------------------------------
266
52
extern "C" dsp* newDsp() { return new mydsp(); }
267
53
extern "C" void deleteDsp(dsp* self) { delete self; }