1 //-----------------------------------------------------
2 // name: "crybaby"
3 // version: "0.1"
4 // author: "brummer"
5 // license: "GPL"
6 //
7 // Code generated with Faust 0.9.9.4k-par (http://faust.grame.fr)
8 //-----------------------------------------------------
9 /* link with */
10 #include <math.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <stdio.h>
14
15 #include <stack>
16 #include <string>
17 #include <iostream>
18 #include <map>
19
20 #include "ladspa.h"
21
22
23 using namespace std;
24
25 struct Meta : map<const char*, const char*>
26 {
declareMeta27 void declare (const char* key, const char* value) { (*this)[key]=value; }
28 };
29
30
31 #define max(x,y) (((x)>(y)) ? (x) : (y))
32 #define min(x,y) (((x)<(y)) ? (x) : (y))
33
34 #define sym(name) xsym(name)
35 #define xsym(name) #name
36
37
38 // abs is now predefined
39 //template<typename T> T abs (T a) { return (a<T(0)) ? -a : a; }
40
41
lsr(int x,int n)42 inline int lsr (int x, int n) { return int(((unsigned int)x) >> n); }
43
int2pow2(int x)44 inline int int2pow2 (int x) { int r=0; while ((1<<r)<x) r++; return r; }
45
46
47
48 /******************************************************************************
49 *******************************************************************************
50
51 VECTOR INTRINSICS
52
53 *******************************************************************************
54 *******************************************************************************/
55
56 //inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((unsigned)(calloc((nmemb*size)+15,sizeof(char)))+15 & 0xfffffff0); }
57 //inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((size_t)(calloc((nmemb*size)+15,sizeof(char)))+15 & ~15); }
58
59
60
61
62
63
64
65 //---------------------Abstract User Interface--------------------
66 //
67 // Abstract definitcryion of a User Interface to be passed to the
68 // buildUserInterface methodcry of a Faust Signal Processor
69 //
70 //----------------------------------------------------------------
71
72 class UI
73 {
74 bool fStopped;
75 public:
76
UI()77 UI() : fStopped(false) {}
~UI()78 virtual ~UI() {}
79
80 virtual void addButton(const char* label, float* zone) = 0;
81 virtual void addToggleButton(const char* label, float* zone) = 0;
82 virtual void addCheckButton(const char* label, float* zone) = 0;
83 virtual void addVerticalSlider(const char* label, float* zone, float initcry, float min, float max, float step) = 0;
84 virtual void addVerticalSlider1(const char* label, float* zone, float initdis, float min, float max, float step) = 0;
85 virtual void addVerticalSlider0(const char* label, float* zone, float initdis, float min, float max, float step) = 0;
86 virtual void addHorizontalSlider(const char* label, float* zone, float initcry, float min, float max, float step) = 0;
87 virtual void addNumEntry(const char* label, float* zone, float initcry, float min, float max, float step) = 0;
88
89 // -- passive widgets
90
91 virtual void addNumDisplay(const char* label, float* zone, int precision) = 0;
92 virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) = 0;
93 virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) = 0;
94 virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) = 0;
95
96 // -- frames and labels
97
98 virtual void openFrameBox(const char* label) = 0;
99 virtual void openTabBox(const char* label) = 0;
100 virtual void openHorizontalBox(const char* label) = 0;
101 virtual void openVerticalBox(const char* label) = 0;
102 virtual void closeBox() = 0;
103
104 virtual void show() = 0;
105 virtual void run() = 0;
106
stop()107 void stop() { fStopped = true; }
stopped()108 bool stopped() { return fStopped; }
109
declare(float * zone,const char * key,const char * value)110 virtual void declare(float* zone, const char* key, const char* value) {}
111 };
112
113
114
115 //------------------Abstract Signal Processor---------------------
116 //
117 // Abstract definitcryion of a Faust Signal Processor
118 //
119 //----------------------------------------------------------------
120
121 class dsp {
122 protected:
123 int fSamplingFreq;
124 public:
dsp()125 dsp() {}
~dsp()126 virtual ~dsp() {}
127 virtual int getNumInputs() = 0;
128 virtual int getNumOutputs() = 0;
129 virtual void buildUserInterface(UI* interface) = 0;
130 virtual void initcry(int samplingRate) = 0;
131 virtual void compute(int len, float** inputs, float** outputs) = 0;
132 };
133
134
135 //----------------------------------------------------------------------------
136 // FAUST generated code
137 //----------------------------------------------------------------------------
138
139
140 class crydsp : public dsp {
141 private:
142 float fslider0;
143 float fRec1[2];
144 float fslider1;
145 float fslider2;
146 float fConst0;
147 float fConst1;
148 float fRec2[2];
149 float fRec3[2];
150 float fRec0[3];
151 float fcheckbox0;
152 public:
metadata(Meta * m)153 static void metadata(Meta* m) {
154 m->declare("name", "emptty");
155 m->declare("version", "0.01");
156 m->declare("author", "brummer");
157 m->declare("license", "GPL");
158 }
159
getNumInputs()160 virtual int getNumInputs() { return 1; }
getNumOutputs()161 virtual int getNumOutputs() { return 1; }
classinitcry(int samplingFreq)162 static void classinitcry(int samplingFreq) {
163 }
instanceinitcry(int samplingFreq)164 virtual void instanceinitcry(int samplingFreq) {
165 fSamplingFreq = samplingFreq;
166 fslider0 = 0.0f;
167 for (int i=0; i<2; i++) fRec1[i] = 0;
168 fslider1 = 0.1f;
169 fslider2 = 0.0f;
170 fConst0 = (2827.43335f / fSamplingFreq);
171 fConst1 = (1413.716675f / fSamplingFreq);
172 for (int i=0; i<2; i++) fRec2[i] = 0;
173 for (int i=0; i<2; i++) fRec3[i] = 0;
174 for (int i=0; i<3; i++) fRec0[i] = 0;
175 fcheckbox0 = 1.0;
176 }
initcry(int samplingFreq)177 virtual void initcry(int samplingFreq) {
178 classinitcry(samplingFreq);
179 instanceinitcry(samplingFreq);
180 }
buildUserInterface(UI * interface)181 virtual void buildUserInterface(UI* interface) {
182 interface->openHorizontalBox("crybaby");
183 interface->addHorizontalSlider("level", &fslider1, 0.1f, 0.0f, 1.0f, 1.000000e-02f);
184 interface->addVerticalSlider0("wah", &fslider0, 0.0f, 0.0f, 1.0f, 1.000000e-02f);
185 interface->addVerticalSlider("wet/dry", &fslider2, 0.0f, -1.0f, 1.0f, 1.000000e-03f);
186 interface->closeBox();
187 }
compute(int count,float ** input,float ** output)188 virtual void compute (int count, float** input, float** output) {
189 float fSlow0 = fslider0;
190 float fSlow1 = (9.999872e-05f * powf(4.0f, fSlow0));
191 float fSlow2 = fslider2;
192 float fSlow3 = ((1 - max(0, (0 - fSlow2))) * fslider1);
193 float fSlow4 = powf(2.0f, (2.3f * fSlow0));
194 float fSlow5 = (1 - (fConst1 * (fSlow4 / powf(2.0f, (1.0f + (2.0f * (1.0f - fSlow0)))))));
195 float fSlow6 = (9.999871e-04f * (0 - (2.0f * (fSlow5 * cosf((fConst0 * fSlow4))))));
196 float fSlow7 = (9.999871e-04f * (fSlow5 * fSlow5));
197 float fSlow8 = (1 - max(0, fSlow2));
198 int iSlow9 = int(fcheckbox0);
199 float* input0 = input[0];
200 float* output0 = output[0];
201 for (int i=0; i<count; i++) {
202 float S0[2];
203 float fTemp0 = input0[i];
204 S0[0] = fTemp0;
205 fRec1[0] = (fSlow1 + (0.999f * fRec1[1]));
206 fRec2[0] = (fSlow6 + (0.999f * fRec2[1]));
207 fRec3[0] = (fSlow7 + (0.999f * fRec3[1]));
208 fRec0[0] = (0 - (((fRec3[0] * fRec0[2]) + (fRec2[0] * fRec0[1])) - (fSlow3 * (fTemp0 * fRec1[0]))));
209 S0[1] = ((fRec0[0] + (fSlow8 * fTemp0)) - fRec0[1]);
210 output0[i] = S0[iSlow9];
211 // post processing
212 fRec0[2] = fRec0[1]; fRec0[1] = fRec0[0];
213 fRec3[1] = fRec3[0];
214 fRec2[1] = fRec2[0];
215 fRec1[1] = fRec1[0];
216 }
217 }
218 };
219
220
221
222
223
224
225
226 //-----------------------------------portCollector--------------------------------------
227 //
228 // portCollector is passed to the buildUserInterface methodcry of a dsp object
229 // in order to build a description of its inputs, outputs and control ports.
230 // This description is used to fill a LADSPA_Descriptor
231 //
232 //--------------------------------------------------------------------------------------
233
234
235
236 //--------------------------------useful constants--------------------------------------
237
238 #define MAXPORT 1024
239 static const int ICONTROL = LADSPA_PORT_INPUT|LADSPA_PORT_CONTROL;
240 static const int OCONTROL = LADSPA_PORT_OUTPUT|LADSPA_PORT_CONTROL;
241 static const int RANGE = LADSPA_PORT_INPUT|LADSPA_PORT_CONTROL;
242
243 static const char* inames[] = {
244 "input00", "input01", "input02", "input03", "input04",
245 "input05", "input06", "input07", "input08", "input09",
246 "input10", "input11", "input12", "input13", "input14",
247 "input15", "input16", "input17", "input18", "input19",
248 "input20", "input21", "input22", "input23", "input24",
249 "input25", "input26", "input27", "input28", "input29",
250 "input30", "input31", "input32", "input33", "input34",
251 "input35", "input36", "input37", "input38", "input39"
252 };
253
254 static const char* onames[] = {
255 "output00", "output01", "output02", "output03", "output04",
256 "output05", "output06", "output07", "output08", "output09",
257 "output10", "output11", "output12", "output13", "output14",
258 "output15", "output16", "output17", "output18", "output19",
259 "output20", "output21", "output22", "output23", "output24",
260 "output25", "output26", "output27", "output28", "output29",
261 "output30", "output31", "output32", "output33", "output34",
262 "output35", "output36", "output37", "output38", "output39"
263 };
264
265
266
267 class portCollector : public UI
268 {
269 private:
270
271 //--------------------------------------------------------------------------------------
272
273 const int fInsCount; // number of audio input ports
274 const int fOutsCount; // number of audio output ports
275 int fCtrlCount; // number of control ports
276
277 LADSPA_PortDescriptor fPortDescs[MAXPORT]; // table of port descriptors to be used in a LADSPA_Descriptor
278 const char* fPortNames[MAXPORT]; // table of port names to be used in a LADSPA_Descriptor
279 LADSPA_PortRangeHint fPortHints[MAXPORT]; // table of port hints to be used in a LADSPA_Descriptor
280
281 string fPluginName; // toplevel prefix used as plugin name
282 stack<string> fPrefix; // current prefix for controls name
283
284
285 //--------------------------------------------------------------------------------------
simplify(const string & src)286 string simplify(const string& src)
287 {
288 int i=0;
289 int level=2;
290 string dst;
291
292 while (src[i] ) {
293
294 switch (level) {
295
296 case 0 :
297 case 1 :
298 case 2 :
299 // Skip the begin of the label "--foo-"
300 // until 3 '-' have been read
301 if (src[i]=='-') { level++; }
302 break;
303
304 case 3 :
305 // copy the content, but skip non alphnum
306 // and content in parenthesis
307 switch (src[i]) {
308 case '(' :
309 case '[' :
310 level++;
311 break;
312
313 case '-' :
314 dst += '-';
315 break;
316
317 default :
318 if (isalnum(src[i])) {
319 dst+= tolower(src[i]);
320 }
321
322 }
323 break;
324
325 default :
326 // here we are inside parenthesis and
327 // we skip the content until we are back to
328 // level 3
329 switch (src[i]) {
330
331 case '(' :
332 case '[' :
333 level++;
334 break;
335
336 case ')' :
337 case ']' :
338 level--;
339 break;
340
341 default :
342 break;
343 }
344
345 }
346 i++;
347 }
348 return (dst.size() > 0) ? dst :src;
349 }
350
addPortDescrcry(int type,const char * label,int hint,float min=0.0,float max=0.0)351 void addPortDescrcry(int type, const char* label, int hint, float min=0.0, float max=0.0)
352 {
353 string fullname = simplify(fPrefix.top() + "-" + label);
354 char * str = strdup(fullname.c_str());
355
356 fPortDescs[fInsCount + fOutsCount + fCtrlCount] = type;
357 fPortNames[fInsCount + fOutsCount + fCtrlCount] = str;
358 fPortHints[fInsCount + fOutsCount + fCtrlCount].HintDescriptor = hint;
359 fPortHints[fInsCount + fOutsCount + fCtrlCount].LowerBound = min;
360 fPortHints[fInsCount + fOutsCount + fCtrlCount].UpperBound = max;
361 fCtrlCount++;
362 }
363
openAnyBox(const char * label)364 void openAnyBox(const char* label)
365 {
366 if (fPrefix.size() == 0) {
367 // top level label is used as plugin name
368 fPluginName = label;
369 fPrefix.push(label);
370
371 } else {
372 string s;
373 if (label && label[0]) {
374 s = fPrefix.top() + "-" + label;
375 } else {
376 s = fPrefix.top();
377 }
378 fPrefix.push(s);
379 }
380
381 }
382
383
384
385 public:
386
387
388 //--------------------------------Collect the audio ports-------------------------------
389
portCollector(int ins,int outs)390 portCollector(int ins, int outs) : UI(), fInsCount(ins), fOutsCount(outs), fCtrlCount(0)
391 {
392 for (int i = 0; i < ins; i++) {
393 fPortDescs[i] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
394 fPortNames[i] = inames[i];
395 fPortHints[i].HintDescriptor = 0;
396 }
397 for (int j = 0; j < outs; j++) {
398 fPortDescs[ins + j] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
399 fPortNames[ins + j] = onames[j];
400 fPortHints[ins + j].HintDescriptor = 0;
401 }
402 };
403
~portCollector()404 virtual ~portCollector() {}
405
406
407
408 //------------------------------Collect the control ports-------------------------------
409
addButton(const char * label,float * zone)410 virtual void addButton(const char* label, float* zone) {
411 addPortDescrcry(ICONTROL, label, LADSPA_HINT_TOGGLED);
412 }
413
addToggleButton(const char * label,float * zone)414 virtual void addToggleButton(const char* label, float* zone) {
415 addPortDescrcry(ICONTROL, label, LADSPA_HINT_TOGGLED| LADSPA_HINT_DEFAULT_0 );
416 }
417
addCheckButton(const char * label,float * zone)418 virtual void addCheckButton(const char* label, float* zone) {
419 addPortDescrcry(ICONTROL, label, LADSPA_HINT_TOGGLED| LADSPA_HINT_DEFAULT_1 );
420 }
421
addVerticalSlider(const char * label,float * zone,float initdis,float min,float max,float step)422 virtual void addVerticalSlider(const char* label, float* zone, float initdis, float min, float max, float step) {
423 addPortDescrcry(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MIDDLE , min, max);
424 }
425
addVerticalSlider0(const char * label,float * zone,float initdis,float min,float max,float step)426 virtual void addVerticalSlider0(const char* label, float* zone, float initdis, float min, float max, float step) {
427 addPortDescrcry(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MINIMUM , min, max);
428 }
429
addVerticalSlider1(const char * label,float * zone,float initdis,float min,float max,float step)430 virtual void addVerticalSlider1(const char* label, float* zone, float initdis, float min, float max, float step) {
431 addPortDescrcry(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MAXIMUM, min, max);
432 }
433
addHorizontalSlider(const char * label,float * zone,float initdis,float min,float max,float step)434 virtual void addHorizontalSlider(const char* label, float* zone, float initdis, float min, float max, float step) {
435 addPortDescrcry(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_LOW, min, max);
436 }
437
addNumEntry(const char * label,float * zone,float initcry,float min,float max,float step)438 virtual void addNumEntry(const char* label, float* zone, float initcry, float min, float max, float step) {
439 addPortDescrcry(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
440 }
441
442 // -- passive widgets
443
addNumDisplay(const char * label,float * zone,int precision)444 virtual void addNumDisplay(const char* label, float* zone, int precision) {
445 addPortDescrcry(OCONTROL, label, 0, -10000, +10000);
446 }
addTextDisplay(const char * label,float * zone,char * names[],float min,float max)447 virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) {
448 addPortDescrcry(OCONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
449 }
addHorizontalBargraph(const char * label,float * zone,float min,float max)450 virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) {
451 addPortDescrcry(OCONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
452 }
addVerticalBargraph(const char * label,float * zone,float min,float max)453 virtual void addVerticalBargraph(const char* label, float* zone, float min, float max){
454 addPortDescrcry(OCONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
455 }
456
openFrameBox(const char * label)457 virtual void openFrameBox(const char* label) { openAnyBox(label); }
openTabBox(const char * label)458 virtual void openTabBox(const char* label) { openAnyBox(label); }
openHorizontalBox(const char * label)459 virtual void openHorizontalBox(const char* label) { openAnyBox(label); }
openVerticalBox(const char * label)460 virtual void openVerticalBox(const char* label) { openAnyBox(label); }
461
closeBox()462 virtual void closeBox() { fPrefix.pop(); }
463
show()464 virtual void show() {}
run()465 virtual void run() {}
466
467
468
469 //---------------------------------Fill the LADSPA descriptor---------------------------
470
471 // generate an ID from a plugin name
makeID(const char * s)472 int makeID (const char* s) {
473 int h = 0;
474 for (int i = 0; s[i]; i++) {
475 h = (h << 3) + (s[i] & 7);
476 }
477 return 1+h%1000;
478 }
479
480 // fill a ladspa descriptor with the information collected on ports
fillPortDescription(LADSPA_Descriptor * descriptor)481 void fillPortDescription (LADSPA_Descriptor * descriptor) {
482 const char* name = sym(crydsp);
483 descriptor->PortCount = fCtrlCount+fInsCount+fOutsCount;
484 descriptor->PortDescriptors = fPortDescs;
485 descriptor->PortNames = fPortNames;
486 descriptor->PortRangeHints = fPortHints;
487
488 descriptor->Label = strdup(name);
489 descriptor->UniqueID = 4062;
490 // descriptor->Label = strdup(fPluginName.c_str());
491 // descriptor->UniqueID = makeID(fPluginName.c_str());
492 descriptor->Properties = LADSPA_PROPERTY_HARD_RT_CAPABLE;
493 descriptor->Name = name;
494 // descriptor->Name = strdup(fPluginName.c_str());
495 descriptor->Maker = "brummer";
496 descriptor->Copyright = "GPL";
497 }
498 };
499
500
501
502
503 //--------------------------------------portData----------------------------------------
504 //
505 // portData : a user interface used to associate the data buffers and the ports
506 //
507 //--------------------------------------------------------------------------------------
508
509
510 class portData : public UI
511 {
512
513
514 private:
515
516
517 //--------------------------------------------------------------------------------------
518
519 const int fInsCount; // number of audio input ports
520 const int fOutsCount; // number of audio output ports
521 int fCtrlCount; // number of control ports
522
523 float* fPortZone[MAXPORT]; //
524 float* fPortData[MAXPORT];
525
526
527 //--------------------------------------------------------------------------------------
528
addZone(float * zone)529 void addZone(float* zone)
530 {
531 fPortZone[fInsCount + fOutsCount + fCtrlCount] = zone;
532 fCtrlCount++;
533 }
534
535
536
537 public:
538
539
540 //--------------------------------Collect the audio ports-------------------------------
541
portData(int ins,int outs)542 portData(int ins, int outs) : UI(), fInsCount(ins), fOutsCount(outs), fCtrlCount(0) {};
~portData()543 virtual ~portData() {}
544
545
546 //------------------------------Collect the control zones-------------------------------
547
addButton(const char * label,float * zone)548 virtual void addButton(const char* label, float* zone) { addZone(zone); }
addToggleButton(const char * label,float * zone)549 virtual void addToggleButton(const char* label, float* zone) { addZone(zone); }
addCheckButton(const char * label,float * zone)550 virtual void addCheckButton(const char* label, float* zone) { addZone(zone); }
551
addVerticalSlider(const char * label,float * zone,float initcry,float min,float max,float step)552 virtual void addVerticalSlider(const char* label, float* zone, float initcry, float min, float max, float step) { addZone(zone); }
addVerticalSlider1(const char * label,float * zone,float initdis,float min,float max,float step)553 virtual void addVerticalSlider1(const char* label, float* zone, float initdis, float min, float max, float step) { addZone(zone); }
addVerticalSlider0(const char * label,float * zone,float initdis,float min,float max,float step)554 virtual void addVerticalSlider0(const char* label, float* zone, float initdis, float min, float max, float step) { addZone(zone); }
addHorizontalSlider(const char * label,float * zone,float initcry,float min,float max,float step)555 virtual void addHorizontalSlider(const char* label, float* zone, float initcry, float min, float max, float step) { addZone(zone); }
addNumEntry(const char * label,float * zone,float initcry,float min,float max,float step)556 virtual void addNumEntry(const char* label, float* zone, float initcry, float min, float max, float step) { addZone(zone); }
557
558 // -- passive widgets
559
addNumDisplay(const char * label,float * zone,int precision)560 virtual void addNumDisplay(const char* label, float* zone, int precision) { addZone(zone); }
addTextDisplay(const char * label,float * zone,char * names[],float min,float max)561 virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) { addZone(zone); }
addHorizontalBargraph(const char * label,float * zone,float min,float max)562 virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) { addZone(zone); }
addVerticalBargraph(const char * label,float * zone,float min,float max)563 virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) { addZone(zone); }
564
openFrameBox(const char * label)565 virtual void openFrameBox(const char* label) { }
openTabBox(const char * label)566 virtual void openTabBox(const char* label) { }
openHorizontalBox(const char * label)567 virtual void openHorizontalBox(const char* label) { }
openVerticalBox(const char * label)568 virtual void openVerticalBox(const char* label) { }
closeBox()569 virtual void closeBox() { }
570
show()571 virtual void show() {}
run()572 virtual void run() {}
573
574
575 //---------------------------------interaction with LADSPA------------------------------
576
setPortDatacry(unsigned long port,LADSPA_Data * data)577 void setPortDatacry (unsigned long port, LADSPA_Data* data) {
578 fPortData[port] = data;
579 }
580
updateCtrlZones()581 void updateCtrlZones() {
582 for (int i = fInsCount+fOutsCount; i < fInsCount+fOutsCount+fCtrlCount; i++) *fPortZone[i] = *fPortData[i];
583 }
584
getInputs()585 float** getInputs() {
586 return &fPortData[0];
587 }
588
getOutputs()589 float** getOutputs() {
590 return &fPortData[fInsCount];
591 }
592 };
593
594
595
596
597 //--------------------------------Faust-LADSPA plugin-----------------------------------
598 //
599 // Plugin structure, callbacks and LADSPA_descriptor(i) entry point
600 //
601 //--------------------------------------------------------------------------------------
602
603 LADSPA_Descriptor* gDescriptorc = 0;
604
605 struct PLUGIN
606 {
607 unsigned long fSampleRate;
608 portData* fPortData;
609 dsp* fDsp;
610
PLUGINPLUGIN611 PLUGIN(unsigned long r, portData* d, dsp* p) : fSampleRate(r), fPortData(d), fDsp(p) {}
612 };
613
instantiate_methodcry(const struct _LADSPA_Descriptor * Descriptor,unsigned long SampleRate)614 LADSPA_Handle instantiate_methodcry (const struct _LADSPA_Descriptor * Descriptor, unsigned long SampleRate)
615 {
616 dsp* p = new crydsp();
617 portData* d = new portData(p->getNumInputs(), p->getNumOutputs());
618
619 p->buildUserInterface(d);
620 return new PLUGIN (SampleRate, d, p);
621 }
622
connect_methodcry(LADSPA_Handle Instance,unsigned long Port,LADSPA_Data * DataLocation)623 void connect_methodcry (LADSPA_Handle Instance, unsigned long Port, LADSPA_Data * DataLocation)
624 {
625 PLUGIN* p = (PLUGIN*) Instance;
626 p->fPortData->setPortDatacry(Port, DataLocation);
627 }
628
activate_methodcry(LADSPA_Handle Instance)629 void activate_methodcry (LADSPA_Handle Instance)
630 {
631 PLUGIN* p = (PLUGIN*) Instance;
632 p->fDsp->initcry(p->fSampleRate);
633 }
634
run_methodcry(LADSPA_Handle Instance,unsigned long SampleCount)635 void run_methodcry (LADSPA_Handle Instance, unsigned long SampleCount)
636 {
637 PLUGIN* p = (PLUGIN*) Instance;
638 p->fPortData->updateCtrlZones();
639 p->fDsp->compute(SampleCount, p->fPortData->getInputs(), p->fPortData->getOutputs());
640 }
641
deactivate_methodcry(LADSPA_Handle Instance)642 void deactivate_methodcry (LADSPA_Handle Instance)
643 {
644 }
645
cleanup_methodcry(LADSPA_Handle Instance)646 void cleanup_methodcry (LADSPA_Handle Instance)
647 {
648 PLUGIN* p = (PLUGIN*) Instance;
649 delete p->fPortData;
650 delete p->fDsp;
651 delete p;
652 }
653
654
655 //--------------------------------------------------------------------------------------
656
initcry_descriptor(LADSPA_Descriptor * descriptor)657 void initcry_descriptor(LADSPA_Descriptor* descriptor)
658 {
659 descriptor->UniqueID = 4062;
660 descriptor->Label = "crybaby";
661 descriptor->Properties = LADSPA_PROPERTY_HARD_RT_CAPABLE;
662 descriptor->Name = "crybaby";
663 descriptor->Maker = "brummer";
664 descriptor->Copyright = "GPL";
665
666 descriptor->ImplementationData = 0;
667
668 // description des methodcrys
669 descriptor->instantiate = instantiate_methodcry;
670 descriptor->connect_port = connect_methodcry;
671 descriptor->activate = activate_methodcry;
672 descriptor->run = run_methodcry;
673 descriptor->run_adding = 0;
674 descriptor->set_run_adding_gain = 0;
675 descriptor->deactivate = deactivate_methodcry;
676 descriptor->cleanup = cleanup_methodcry;
677 }
678
679
680
681 //--------------------------------------------------------------------------------------
682
ladspa_descriptor(unsigned long Index)683 const LADSPA_Descriptor * ladspa_descriptor(unsigned long Index)
684 {
685 if (Index == 0) {
686 if (gDescriptorc == 0)
687 {
688 // allocate temporaries dsp and portCollector to build the plugin description
689 crydsp* p = new crydsp();
690 if (p) {
691 portCollector* c=new portCollector(p->getNumInputs(), p->getNumOutputs());
692 p->buildUserInterface(c);
693 gDescriptorc = new LADSPA_Descriptor;
694 initcry_descriptor(gDescriptorc);
695 c->fillPortDescription(gDescriptorc);
696 delete p;
697 } else {
698 printf("Memory Error : unable to allocate the dsp object\n");
699 }
700 }
701 return gDescriptorc;
702 } else {
703 return NULL;
704 }
705 }
706
707