1 //-----------------------------------------------------
2 // name: "freeverb"
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 definitfreeion of a User Interface to be passed to the
68 // buildUserInterface methodfr 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 initfree, 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 initfree, float min, float max, float step) = 0;
87 	virtual void addNumEntry(const char* label, float* zone, float initfree, 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 definitfreeion 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 initfree(int samplingRate) 							= 0;
131  	virtual void computfr(int len, float** inputs, float** outputs) 	= 0;
132 };
133 
134 
135 //----------------------------------------------------------------------------
136 // 	FAUST generated code
137 //----------------------------------------------------------------------------
138 
139 
140 class frdsp : public dsp {
141   private:
142 	float 	fslider0;
143 	float 	fslider1;
144 	float 	fRec9[2];
145 	float 	fslider2;
146 	int 	IOTA;
147 	float 	fVec0[2048];
148 	float 	fRec8[2];
149 	float 	fRec11[2];
150 	float 	fVec1[2048];
151 	float 	fRec10[2];
152 	float 	fRec13[2];
153 	float 	fVec2[2048];
154 	float 	fRec12[2];
155 	float 	fRec15[2];
156 	float 	fVec3[2048];
157 	float 	fRec14[2];
158 	float 	fRec17[2];
159 	float 	fVec4[2048];
160 	float 	fRec16[2];
161 	float 	fRec19[2];
162 	float 	fVec5[2048];
163 	float 	fRec18[2];
164 	float 	fRec21[2];
165 	float 	fVec6[2048];
166 	float 	fRec20[2];
167 	float 	fRec23[2];
168 	float 	fVec7[2048];
169 	float 	fRec22[2];
170 	float 	fVec8[1024];
171 	float 	fRec6[2];
172 	float 	fVec9[512];
173 	float 	fRec4[2];
174 	float 	fVec10[512];
175 	float 	fRec2[2];
176 	float 	fVec11[256];
177 	float 	fRec0[2];
178 	float 	fcheckbox0;
179   public:
metadata(Meta * m)180 	static void metadata(Meta* m) 	{
181 		m->declare("name", "freeverb");
182 		m->declare("version", "0.1");
183 		m->declare("author", "brummer");
184 		m->declare("license", "GPL");
185 	}
186 
getNumInputs()187 	virtual int getNumInputs() 	{ return 1; }
getNumOutputs()188 	virtual int getNumOutputs() 	{ return 1; }
classinitfree(int samplingFreq)189 	static void classinitfree(int samplingFreq) {
190 	}
instanceinitfree(int samplingFreq)191 	virtual void instanceinitfree(int samplingFreq) {
192 		fSamplingFreq = samplingFreq;
193 		fslider0 = 0.3333f;
194 		fslider1 = 0.5f;
195 		for (int i=0; i<2; i++) fRec9[i] = 0;
196 		fslider2 = 0.5f;
197 		IOTA = 0;
198 		for (int i=0; i<2048; i++) fVec0[i] = 0;
199 		for (int i=0; i<2; i++) fRec8[i] = 0;
200 		for (int i=0; i<2; i++) fRec11[i] = 0;
201 		for (int i=0; i<2048; i++) fVec1[i] = 0;
202 		for (int i=0; i<2; i++) fRec10[i] = 0;
203 		for (int i=0; i<2; i++) fRec13[i] = 0;
204 		for (int i=0; i<2048; i++) fVec2[i] = 0;
205 		for (int i=0; i<2; i++) fRec12[i] = 0;
206 		for (int i=0; i<2; i++) fRec15[i] = 0;
207 		for (int i=0; i<2048; i++) fVec3[i] = 0;
208 		for (int i=0; i<2; i++) fRec14[i] = 0;
209 		for (int i=0; i<2; i++) fRec17[i] = 0;
210 		for (int i=0; i<2048; i++) fVec4[i] = 0;
211 		for (int i=0; i<2; i++) fRec16[i] = 0;
212 		for (int i=0; i<2; i++) fRec19[i] = 0;
213 		for (int i=0; i<2048; i++) fVec5[i] = 0;
214 		for (int i=0; i<2; i++) fRec18[i] = 0;
215 		for (int i=0; i<2; i++) fRec21[i] = 0;
216 		for (int i=0; i<2048; i++) fVec6[i] = 0;
217 		for (int i=0; i<2; i++) fRec20[i] = 0;
218 		for (int i=0; i<2; i++) fRec23[i] = 0;
219 		for (int i=0; i<2048; i++) fVec7[i] = 0;
220 		for (int i=0; i<2; i++) fRec22[i] = 0;
221 		for (int i=0; i<1024; i++) fVec8[i] = 0;
222 		for (int i=0; i<2; i++) fRec6[i] = 0;
223 		for (int i=0; i<512; i++) fVec9[i] = 0;
224 		for (int i=0; i<2; i++) fRec4[i] = 0;
225 		for (int i=0; i<512; i++) fVec10[i] = 0;
226 		for (int i=0; i<2; i++) fRec2[i] = 0;
227 		for (int i=0; i<256; i++) fVec11[i] = 0;
228 		for (int i=0; i<2; i++) fRec0[i] = 0;
229 		fcheckbox0 = 1.0;
230 	}
initfree(int samplingFreq)231 	virtual void initfree(int samplingFreq) {
232 		classinitfree(samplingFreq);
233 		instanceinitfree(samplingFreq);
234 	}
buildUserInterface(UI * interface)235 	virtual void buildUserInterface(UI* interface) {
236 		interface->openVerticalBox("freeverb");
237 		interface->addVerticalSlider("RoomSize", &fslider2, 0.5f, 0.0f, 1.0f, 2.500000e-02f);
238 		interface->addVerticalSlider("damp", &fslider1, 0.5f, 0.0f, 1.0f, 2.500000e-02f);
239 		interface->addHorizontalSlider("dry/wet/", &fslider0, 0.3333f, 0.0f, 1.0f, 2.500000e-02f);
240 		interface->closeBox();
241 	}
computfr(int count,float ** input,float ** output)242 		virtual void computfr (int count, float** input, float** output) {
243 			float 	fSlow0 = fslider0;
244 			float 	fSlow1 = (2 * (1 - fSlow0));
245 			float 	fSlow2 = (0.4f * fslider1);
246 			float 	fSlow3 = (1 - fSlow2);
247 			float 	fSlow4 = (0.7f + (0.28f * fslider2));
248 			int 	iSlow5 = int(fcheckbox0);
249 			float* input0 = input[0];
250 			float* output0 = output[0];
251 			for (int i=0; i<count; i++) {
252 				float 	S0[2];
253 				float fTemp0 = input0[i];
254 				S0[0] = fTemp0;
255 				float fTemp1 = (1.500000e-02f * fTemp0);
256 				fRec9[0] = ((fSlow3 * fRec8[1]) + (fSlow2 * fRec9[1]));
257 				fVec0[IOTA&2047] = (fTemp1 + (fSlow4 * fRec9[0]));
258 				fRec8[0] = fVec0[(IOTA-1640)&2047];
259 				fRec11[0] = ((fSlow3 * fRec10[1]) + (fSlow2 * fRec11[1]));
260 				fVec1[IOTA&2047] = (fTemp1 + (fSlow4 * fRec11[0]));
261 				fRec10[0] = fVec1[(IOTA-1580)&2047];
262 				fRec13[0] = ((fSlow3 * fRec12[1]) + (fSlow2 * fRec13[1]));
263 				fVec2[IOTA&2047] = (fTemp1 + (fSlow4 * fRec13[0]));
264 				fRec12[0] = fVec2[(IOTA-1514)&2047];
265 				fRec15[0] = ((fSlow3 * fRec14[1]) + (fSlow2 * fRec15[1]));
266 				fVec3[IOTA&2047] = (fTemp1 + (fSlow4 * fRec15[0]));
267 				fRec14[0] = fVec3[(IOTA-1445)&2047];
268 				fRec17[0] = ((fSlow3 * fRec16[1]) + (fSlow2 * fRec17[1]));
269 				fVec4[IOTA&2047] = (fTemp1 + (fSlow4 * fRec17[0]));
270 				fRec16[0] = fVec4[(IOTA-1379)&2047];
271 				fRec19[0] = ((fSlow3 * fRec18[1]) + (fSlow2 * fRec19[1]));
272 				fVec5[IOTA&2047] = (fTemp1 + (fSlow4 * fRec19[0]));
273 				fRec18[0] = fVec5[(IOTA-1300)&2047];
274 				fRec21[0] = ((fSlow3 * fRec20[1]) + (fSlow2 * fRec21[1]));
275 				fVec6[IOTA&2047] = (fTemp1 + (fSlow4 * fRec21[0]));
276 				fRec20[0] = fVec6[(IOTA-1211)&2047];
277 				fRec23[0] = ((fSlow3 * fRec22[1]) + (fSlow2 * fRec23[1]));
278 				fVec7[IOTA&2047] = (fTemp1 + (fSlow4 * fRec23[0]));
279 				fRec22[0] = fVec7[(IOTA-1139)&2047];
280 				float fTemp2 = (((((((fRec22[0] + fRec20[0]) + fRec18[0]) + fRec16[0]) + fRec14[0]) + fRec12[0]) + fRec10[0]) + fRec8[0]);
281 				fVec8[IOTA&1023] = (fTemp2 + (0.5f * fRec6[1]));
282 				fRec6[0] = fVec8[(IOTA-579)&1023];
283 				float 	fRec7 = (0 - (fTemp2 - fRec6[1]));
284 				fVec9[IOTA&511] = (fRec7 + (0.5f * fRec4[1]));
285 				fRec4[0] = fVec9[(IOTA-464)&511];
286 				float 	fRec5 = (fRec4[1] - fRec7);
287 				fVec10[IOTA&511] = (fRec5 + (0.5f * fRec2[1]));
288 				fRec2[0] = fVec10[(IOTA-364)&511];
289 				float 	fRec3 = (fRec2[1] - fRec5);
290 				fVec11[IOTA&255] = (fRec3 + (0.5f * fRec0[1]));
291 				fRec0[0] = fVec11[(IOTA-248)&255];
292 				float 	fRec1 = (fRec0[1] - fRec3);
293 				S0[1] = ((fSlow0 * (fRec1 + fTemp1)) + (fSlow1 * fTemp0));
294 				output0[i] = S0[iSlow5];
295 				// post processing
296 				fRec0[1] = fRec0[0];
297 				fRec2[1] = fRec2[0];
298 				fRec4[1] = fRec4[0];
299 				fRec6[1] = fRec6[0];
300 				fRec22[1] = fRec22[0];
301 				fRec23[1] = fRec23[0];
302 				fRec20[1] = fRec20[0];
303 				fRec21[1] = fRec21[0];
304 				fRec18[1] = fRec18[0];
305 				fRec19[1] = fRec19[0];
306 				fRec16[1] = fRec16[0];
307 				fRec17[1] = fRec17[0];
308 				fRec14[1] = fRec14[0];
309 				fRec15[1] = fRec15[0];
310 				fRec12[1] = fRec12[0];
311 				fRec13[1] = fRec13[0];
312 				fRec10[1] = fRec10[0];
313 				fRec11[1] = fRec11[0];
314 				fRec8[1] = fRec8[0];
315 				IOTA = IOTA+1;
316 				fRec9[1] = fRec9[0];
317 			}
318 		}
319 };
320 
321 
322 
323 
324 
325 
326 
327 //-----------------------------------portCollectorf--------------------------------------
328 //
329 // portCollectorf is passed to the buildUserInterface methodfr of a dsp object
330 // in order to build a description of its inputs, outputs and control ports.
331 // This description is used to fill a LADSPA_Descriptor
332 //
333 //--------------------------------------------------------------------------------------
334 
335 
336 
337 //--------------------------------useful constants--------------------------------------
338 
339 #define MAXPORT 1024
340 static const int ICONTROL 	= LADSPA_PORT_INPUT|LADSPA_PORT_CONTROL;
341 static const int OCONTROL 	= LADSPA_PORT_OUTPUT|LADSPA_PORT_CONTROL;
342 static const int RANGE 		= LADSPA_PORT_INPUT|LADSPA_PORT_CONTROL;
343 
344 static const char* inames[] = {
345 					"input00", "input01", "input02", "input03", "input04",
346 					"input05", "input06", "input07", "input08", "input09",
347 					"input10", "input11", "input12", "input13", "input14",
348 					"input15", "input16", "input17", "input18", "input19",
349 					"input20", "input21", "input22", "input23", "input24",
350 					"input25", "input26", "input27", "input28", "input29",
351 					"input30", "input31", "input32", "input33", "input34",
352 					"input35", "input36", "input37", "input38", "input39"
353 };
354 
355 static const char* onames[] = {
356 					"output00", "output01", "output02", "output03", "output04",
357 					"output05", "output06", "output07", "output08", "output09",
358 					"output10", "output11", "output12", "output13", "output14",
359 					"output15", "output16", "output17", "output18", "output19",
360 					"output20", "output21", "output22", "output23", "output24",
361 					"output25", "output26", "output27", "output28", "output29",
362 					"output30", "output31", "output32", "output33", "output34",
363 					"output35", "output36", "output37", "output38", "output39"
364 };
365 
366 
367 
368 class portCollectorf : public UI
369 {
370  private:
371 
372 	//--------------------------------------------------------------------------------------
373 
374 	const int				fInsCount;					// number of audio input ports
375 	const int				fOutsCount;					// number of audio output ports
376 	int						fCtrlCount;					// number of control ports
377 
378 	LADSPA_PortDescriptor 	fPortDescs[MAXPORT];		// table of port descriptors to be used in a LADSPA_Descriptor
379 	const char* 			fPortNames[MAXPORT];		// table of port names to be used in a LADSPA_Descriptor
380 	LADSPA_PortRangeHint 	fPortHints[MAXPORT];		// table of port hints to be used in a LADSPA_Descriptor
381 
382 	string					fPluginName;				// toplevel prefix used as plugin name
383 	stack<string>			fPrefix;					// current prefix for controls name
384 
385 
386 	//--------------------------------------------------------------------------------------
simplify(const string & src)387 	string simplify(const string& src)
388 	{
389 		int		i=0;
390 		int		level=2;
391 		string	dst;
392 
393 		while (src[i] ) {
394 
395 			switch (level) {
396 
397 				case 0 :
398 				case 1 :
399 				case 2 :
400 					// Skip the begin of the label "--foo-"
401 					// until 3 '-' have been read
402 					if (src[i]=='-') { level++; }
403 					break;
404 
405 				case 3 :
406 					// copy the content, but skip non alphnum
407 					// and content in parenthesis
408 					switch (src[i]) {
409 						case '(' :
410 						case '[' :
411 							level++;
412 							break;
413 
414 						case '-' :
415 							dst += '-';
416 							break;
417 
418 						default :
419 							if (isalnum(src[i])) {
420 								dst+= tolower(src[i]);
421 							}
422 
423 					}
424 					break;
425 
426 				default :
427 					// here we are inside parenthesis and
428 					// we skip the content until we are back to
429 					// level 3
430 					switch (src[i]) {
431 
432 						case '(' :
433 						case '[' :
434 							level++;
435 							break;
436 
437 						case ')' :
438 						case ']' :
439 							level--;
440 							break;
441 
442 						default :
443 							break;
444 					}
445 
446 			}
447 			i++;
448 		}
449 		return (dst.size() > 0) ? dst :src;
450 	}
451 
addPortDescrfr(int type,const char * label,int hint,float min=0.0,float max=0.0)452 	void addPortDescrfr(int type, const char* label, int hint, float min=0.0, float max=0.0)
453 	{
454 		string fullname = simplify(fPrefix.top() + "-" + label);
455 		char * str = strdup(fullname.c_str());
456 
457 		fPortDescs[fInsCount + fOutsCount + fCtrlCount] = type;
458 		fPortNames[fInsCount + fOutsCount + fCtrlCount] = str;
459 		fPortHints[fInsCount + fOutsCount + fCtrlCount].HintDescriptor = hint;
460 		fPortHints[fInsCount + fOutsCount + fCtrlCount].LowerBound = min;
461 		fPortHints[fInsCount + fOutsCount + fCtrlCount].UpperBound = max;
462 		fCtrlCount++;
463 	}
464 
openAnyBox(const char * label)465 	void openAnyBox(const char* label)
466 	{
467 		if (fPrefix.size() == 0) {
468 			// top level label is used as plugin name
469 			fPluginName = label;
470 			fPrefix.push(label);
471 
472 		} else {
473 			string s;
474 			if (label && label[0]) {
475 				s = fPrefix.top() + "-" + label;
476 			} else {
477 				s = fPrefix.top();
478 			}
479 			fPrefix.push(s);
480 		}
481 
482 	}
483 
484 
485 
486  public:
487 
488 
489 	//--------------------------------Collect the audio ports-------------------------------
490 
portCollectorf(int ins,int outs)491 	portCollectorf(int ins, int outs) : UI(), fInsCount(ins), fOutsCount(outs), fCtrlCount(0)
492 	{
493 		for (int i = 0; i < ins; i++) {
494 			fPortDescs[i] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
495 			fPortNames[i] = inames[i];
496 			fPortHints[i].HintDescriptor = 0;
497 		}
498 		for (int j = 0; j < outs; j++) {
499 			fPortDescs[ins + j] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
500 			fPortNames[ins + j] = onames[j];
501 			fPortHints[ins + j].HintDescriptor = 0;
502 		}
503 	};
504 
~portCollectorf()505 	virtual ~portCollectorf() {}
506 
507 
508 
509 	//------------------------------Collect the control ports-------------------------------
510 
addButton(const char * label,float * zone)511 	virtual void addButton(const char* label, float* zone) {
512 		addPortDescrfr(ICONTROL, label, LADSPA_HINT_TOGGLED);
513 	}
514 
addToggleButton(const char * label,float * zone)515 	virtual void addToggleButton(const char* label, float* zone) {
516 		addPortDescrfr(ICONTROL, label, LADSPA_HINT_TOGGLED|  LADSPA_HINT_DEFAULT_0 );
517 	}
518 
addCheckButton(const char * label,float * zone)519 	virtual void addCheckButton(const char* label, float* zone) {
520 		addPortDescrfr(ICONTROL, label, LADSPA_HINT_TOGGLED| LADSPA_HINT_DEFAULT_1 );
521 	}
522 
addVerticalSlider(const char * label,float * zone,float initdis,float min,float max,float step)523 	virtual void addVerticalSlider(const char* label, float* zone, float initdis, float min, float max, float step) {
524 		addPortDescrfr(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MIDDLE , min, max);
525 	}
526 
addVerticalSlider0(const char * label,float * zone,float initdis,float min,float max,float step)527 	virtual void addVerticalSlider0(const char* label, float* zone, float initdis, float min, float max, float step) {
528 		addPortDescrfr(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MINIMUM , min, max);
529 	}
530 
addVerticalSlider1(const char * label,float * zone,float initdis,float min,float max,float step)531 	virtual void addVerticalSlider1(const char* label, float* zone, float initdis, float min, float max, float step) {
532 		addPortDescrfr(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MAXIMUM, min, max);
533 	}
534 
addHorizontalSlider(const char * label,float * zone,float initdis,float min,float max,float step)535 	virtual void addHorizontalSlider(const char* label, float* zone, float initdis, float min, float max, float step) {
536 		addPortDescrfr(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE  | LADSPA_HINT_DEFAULT_LOW, min, max);
537 	}
538 
addNumEntry(const char * label,float * zone,float initfree,float min,float max,float step)539 	virtual void addNumEntry(const char* label, float* zone, float initfree, float min, float max, float step) {
540 		addPortDescrfr(ICONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
541 	}
542 
543 	// -- passive widgets
544 
addNumDisplay(const char * label,float * zone,int precision)545 	virtual void addNumDisplay(const char* label, float* zone, int precision) {
546 		addPortDescrfr(OCONTROL, label, 0, -10000, +10000);
547 	}
addTextDisplay(const char * label,float * zone,char * names[],float min,float max)548 	virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) {
549 		addPortDescrfr(OCONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
550 	}
addHorizontalBargraph(const char * label,float * zone,float min,float max)551 	virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) {
552 		addPortDescrfr(OCONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
553 	}
addVerticalBargraph(const char * label,float * zone,float min,float max)554 	virtual void addVerticalBargraph(const char* label, float* zone, float min, float max){
555 		addPortDescrfr(OCONTROL, label, LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, min, max);
556 	}
557 
openFrameBox(const char * label)558 	virtual void openFrameBox(const char* label)		{ openAnyBox(label); }
openTabBox(const char * label)559 	virtual void openTabBox(const char* label)		{ openAnyBox(label); }
openHorizontalBox(const char * label)560 	virtual void openHorizontalBox(const char* label)	{ openAnyBox(label); }
openVerticalBox(const char * label)561 	virtual void openVerticalBox(const char* label)	{ openAnyBox(label); }
562 
closeBox()563 	virtual void closeBox() 					{ fPrefix.pop(); }
564 
show()565 	virtual void show() {}
run()566 	virtual void run() 	{}
567 
568 
569 
570 	//---------------------------------Fill the LADSPA descriptor---------------------------
571 
572 	// generate an ID from a plugin name
makeID(const char * s)573 	int makeID (const char* s) {
574 		int h = 0;
575 		for (int i = 0; s[i]; i++) {
576 			h = (h << 3) + (s[i] & 7);
577 		}
578 		return 1+h%1000;
579 	}
580 
581 	// fill a ladspa descriptor with the information collected on ports
fillPortDescription(LADSPA_Descriptor * descriptor)582 	void fillPortDescription (LADSPA_Descriptor * descriptor) {
583 		const char* name = sym(frdsp);
584 		descriptor->PortCount 			= fCtrlCount+fInsCount+fOutsCount;
585 		descriptor->PortDescriptors 	= fPortDescs;
586 		descriptor->PortNames 			= fPortNames;
587 		descriptor->PortRangeHints 		= fPortHints;
588 
589 		descriptor->Label = strdup(name);
590 		descriptor->UniqueID = 4064;
591 //		descriptor->Label = strdup(fPluginName.c_str());
592 //		descriptor->UniqueID = makeID(fPluginName.c_str());
593 		descriptor->Properties = LADSPA_PROPERTY_HARD_RT_CAPABLE;
594 		descriptor->Name = name;
595 //		descriptor->Name = strdup(fPluginName.c_str());
596 		descriptor->Maker = "brummer";
597 		descriptor->Copyright = "GPL";
598 	}
599 };
600 
601 
602 
603 
604 //--------------------------------------portData----------------------------------------
605 //
606 // portData : a user interface used to associate the data buffers and the ports
607 //
608 //--------------------------------------------------------------------------------------
609 
610 
611 class portData : public UI
612 {
613 
614 
615  private:
616 
617 
618 	//--------------------------------------------------------------------------------------
619 
620 	const int				fInsCount;					// number of audio input ports
621 	const int				fOutsCount;					// number of audio output ports
622 	int						fCtrlCount;					// number of control ports
623 
624 	float* 					fPortZone[MAXPORT];			//
625 	float* 					fPortData[MAXPORT];
626 
627 
628 	//--------------------------------------------------------------------------------------
629 
addZone(float * zone)630 	void addZone(float* zone)
631 	{
632 		fPortZone[fInsCount + fOutsCount + fCtrlCount] = zone;
633 		fCtrlCount++;
634 	}
635 
636 
637 
638  public:
639 
640 
641 	//--------------------------------Collect the audio ports-------------------------------
642 
portData(int ins,int outs)643 	portData(int ins, int outs) : UI(), fInsCount(ins), fOutsCount(outs), fCtrlCount(0) {};
~portData()644 	virtual ~portData() {}
645 
646 
647 	//------------------------------Collect the control zones-------------------------------
648 
addButton(const char * label,float * zone)649 	virtual void addButton(const char* label, float* zone) 			{ addZone(zone); }
addToggleButton(const char * label,float * zone)650 	virtual void addToggleButton(const char* label, float* zone)  	{ addZone(zone); }
addCheckButton(const char * label,float * zone)651 	virtual void addCheckButton(const char* label, float* zone)  		{ addZone(zone); }
652 
addVerticalSlider(const char * label,float * zone,float initfree,float min,float max,float step)653 	virtual void addVerticalSlider(const char* label, float* zone, float initfree, float min, float max, float step) 		{ addZone(zone); }
addVerticalSlider1(const char * label,float * zone,float initdis,float min,float max,float step)654 	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)655 	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 initfree,float min,float max,float step)656 	virtual void addHorizontalSlider(const char* label, float* zone, float initfree, float min, float max, float step) 	{ addZone(zone); }
addNumEntry(const char * label,float * zone,float initfree,float min,float max,float step)657 	virtual void addNumEntry(const char* label, float* zone, float initfree, float min, float max, float step)  			{ addZone(zone); }
658 
659 	// -- passive widgets
660 
addNumDisplay(const char * label,float * zone,int precision)661 	virtual void addNumDisplay(const char* label, float* zone, int precision) 						{ addZone(zone); }
addTextDisplay(const char * label,float * zone,char * names[],float min,float max)662 	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)663 	virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) 			{ addZone(zone); }
addVerticalBargraph(const char * label,float * zone,float min,float max)664 	virtual void addVerticalBargraph(const char* label, float* zone, float min, float max)			{ addZone(zone); }
665 
openFrameBox(const char * label)666 	virtual void openFrameBox(const char* label)		{ }
openTabBox(const char * label)667 	virtual void openTabBox(const char* label)		{ }
openHorizontalBox(const char * label)668 	virtual void openHorizontalBox(const char* label)	{ }
openVerticalBox(const char * label)669 	virtual void openVerticalBox(const char* label)	{ }
closeBox()670 	virtual void closeBox() 					{ }
671 
show()672 	virtual void show() {}
run()673 	virtual void run() 	{}
674 
675 
676 	//---------------------------------interaction with LADSPA------------------------------
677 
setPortDatafr(unsigned long port,LADSPA_Data * data)678 	void setPortDatafr (unsigned long port, LADSPA_Data* data) {
679 		fPortData[port] = data;
680 	}
681 
updateCtrlZonesfr()682 	void updateCtrlZonesfr() {
683 		for (int i = fInsCount+fOutsCount; i < fInsCount+fOutsCount+fCtrlCount; i++)	*fPortZone[i] = *fPortData[i];
684 	}
685 
getInputs()686 	float** getInputs() {
687 		return &fPortData[0];
688 	}
689 
getOutputs()690 	float** getOutputs() {
691 		return &fPortData[fInsCount];
692 	}
693 };
694 
695 
696 
697 
698 //--------------------------------Faust-LADSPA plugin-----------------------------------
699 //
700 // Plugin structure, callbacks and LADSPA_descriptor(i) entry point
701 //
702 //--------------------------------------------------------------------------------------
703 
704 LADSPA_Descriptor* 	gDescriptorfe = 0;
705 
706 struct PLUGIN
707 {
708 	unsigned long	fSampleRate;
709 	portData*		fPortData;
710 	dsp*			fDsp;
711 
PLUGINPLUGIN712 	PLUGIN(unsigned long r, portData* d, dsp* p) : fSampleRate(r), fPortData(d), fDsp(p) {}
713 };
714 
instantiate_methodfr(const struct _LADSPA_Descriptor * Descriptor,unsigned long SampleRate)715 LADSPA_Handle instantiate_methodfr (const struct _LADSPA_Descriptor * Descriptor, unsigned long SampleRate)
716 {
717 	dsp*		p = new frdsp();
718 	portData* 	d = new portData(p->getNumInputs(), p->getNumOutputs());
719 
720 	p->buildUserInterface(d);
721 	return new PLUGIN (SampleRate, d, p);
722 }
723 
connect_methodfr(LADSPA_Handle Instance,unsigned long Port,LADSPA_Data * DataLocation)724 void connect_methodfr (LADSPA_Handle Instance, unsigned long Port, LADSPA_Data * DataLocation)
725 {
726 	PLUGIN* p = (PLUGIN*) Instance;
727 	p->fPortData->setPortDatafr(Port, DataLocation);
728 }
729 
activate_methodfr(LADSPA_Handle Instance)730 void activate_methodfr (LADSPA_Handle Instance)
731 {
732 	PLUGIN* p = (PLUGIN*) Instance;
733 	p->fDsp->initfree(p->fSampleRate);
734 }
735 
run_methodfr(LADSPA_Handle Instance,unsigned long SampleCount)736 void run_methodfr (LADSPA_Handle Instance, unsigned long SampleCount)
737 {
738 	PLUGIN* p = (PLUGIN*) Instance;
739 	p->fPortData->updateCtrlZonesfr();
740 	p->fDsp->computfr(SampleCount, p->fPortData->getInputs(), p->fPortData->getOutputs());
741 }
742 
deactivate_methodfr(LADSPA_Handle Instance)743 void deactivate_methodfr (LADSPA_Handle Instance)
744 {
745 }
746 
cleanup_methodfr(LADSPA_Handle Instance)747 void cleanup_methodfr (LADSPA_Handle Instance)
748 {
749 	PLUGIN* p = (PLUGIN*) Instance;
750 	delete p->fPortData;
751 	delete p->fDsp;
752 	delete p;
753 }
754 
755 
756 //--------------------------------------------------------------------------------------
757 
initfree_descriptor(LADSPA_Descriptor * descriptor)758 void initfree_descriptor(LADSPA_Descriptor* descriptor)
759 {
760 	descriptor->UniqueID = 4064;
761 	descriptor->Label = "freeverb";
762 	descriptor->Properties = LADSPA_PROPERTY_HARD_RT_CAPABLE;
763 	descriptor->Name = "freeverb";
764 	descriptor->Maker = "brummer";
765 	descriptor->Copyright = "GPL";
766 
767 	descriptor->ImplementationData = 0;
768 
769 	// description des methodfrs
770 	descriptor->instantiate = instantiate_methodfr;
771 	descriptor->connect_port = connect_methodfr;
772 	descriptor->activate = activate_methodfr;
773 	descriptor->run = run_methodfr;
774 	descriptor->run_adding = 0;
775 	descriptor->set_run_adding_gain = 0;
776 	descriptor->deactivate = deactivate_methodfr;
777 	descriptor->cleanup = cleanup_methodfr;
778 }
779 
780 
781 
782 //--------------------------------------------------------------------------------------
783 
ladspa_descriptor(unsigned long Index)784 const LADSPA_Descriptor * ladspa_descriptor(unsigned long Index)
785 {
786     if (Index == 0) {
787 		if (gDescriptorfe == 0)
788 		{
789 			// allocate temporaries dsp and portCollectorf to build the plugin description
790 			frdsp* p = new frdsp();
791 			if (p) {
792 				portCollectorf*	c=new portCollectorf(p->getNumInputs(), p->getNumOutputs());
793 				p->buildUserInterface(c);
794 				gDescriptorfe = new LADSPA_Descriptor;
795 				initfree_descriptor(gDescriptorfe);
796 				c->fillPortDescription(gDescriptorfe);
797 				delete p;
798 			} else {
799 				printf("Memory Error : unable to allocate the dsp object\n");
800 			}
801 		}
802 		return gDescriptorfe;
803 	} else {
804 		return NULL;
805 	}
806 }
807 
808