This file is indexed.

/usr/share/faust/jack-internal.cpp is in faust-common 0.9.95~repack1-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
/************************************************************************

	IMPORTANT NOTE : this file contains two clearly delimited sections : 
	the ARCHITECTURE section (in two parts) and the USER section. Each section 
	is governed by its own copyright and license. Please check individually 
	each section for license and copyright information.
*************************************************************************/

/*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/

/************************************************************************
    FAUST Architecture File
	Copyright (C) 2003-2011 GRAME, Centre National de Creation Musicale
    ---------------------------------------------------------------------
    This Architecture section is free software; you can redistribute it 
    and/or modify it under the terms of the GNU General Public License 
	as published by the Free Software Foundation; either version 3 of 
	the License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License 
	along with this program; If not, see <http://www.gnu.org/licenses/>.

	EXCEPTION : As a special exception, you may create a larger work 
	that contains this FAUST architecture section and distribute  
	that work under terms of your choice, so long as this FAUST 
	architecture section is not modified. 


 ************************************************************************
 ************************************************************************/


#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <errno.h>
#include <time.h>
#include <vector>
#include <stack>
#include <string>
#include <map>
#include <list>
#include <iostream> 
#include <assert.h> 

#include <libgen.h>
#include <jack/jack.h>
#include <jack/jslist.h>

using namespace std;

// On Intel set FZ (Flush to Zero) and DAZ (Denormals Are Zero)
// flags to avoid costly denormals
#ifdef __SSE__
    #include <xmmintrin.h>
    #ifdef __SSE2__
        #define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8040)
    #else
        #define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8000)
    #endif
#else
    #define AVOIDDENORMALS 
#endif

struct Meta : map<const char*, const char*>
{
    void declare(const char* key, const char* value) { (*this)[key]=value; }
};


// abs is now predefined
//template<typename T> T abs (T a)			{ return (a<T(0)) ? -a : a; }

inline int		lsr (int x, int n)			{ return int(((unsigned int)x) >> n); }

/******************************************************************************
*******************************************************************************

							       VECTOR INTRINSICS

*******************************************************************************
*******************************************************************************/

//inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((unsigned)(calloc((nmemb*size)+15,sizeof(char)))+15 & 0xfffffff0); }
//inline void *aligned_calloc(size_t nmemb, size_t size) { return (void*)((size_t)(calloc((nmemb*size)+15,sizeof(char)))+15 & ~15); }

<<includeIntrinsic>>


/******************************************************************************
*******************************************************************************

								GRAPHIC USER INTERFACE (v2)
								  abstract interfaces

*******************************************************************************
*******************************************************************************/

using namespace std;


struct uiItem;
typedef void (*uiCallback)(float val, void* data);

/**
 * Graphic User Interface : abstract definition
 */

class UI 
{
	typedef list<uiItem*> clist;
	typedef map<float*, clist*> zmap;
	
 private:
 	static list<UI*>	fGuiList;
	zmap				fZoneMap;
	bool				fStopped;
	
 public:
		
	UI() : fStopped(false) {	
		fGuiList.push_back(this);
	}
	
	virtual ~UI() {
		// suppression de this dans fGuiList
	}

	// -- zone management
	
	void registerZone(float* z, uiItem* c)
	{
		if (fZoneMap.find(z) == fZoneMap.end()) fZoneMap[z] = new clist();
		fZoneMap[z]->push_back(c);
	} 	
	
	void updateAllZones();
	
	void updateZone(float* z);
	
	static void updateAllGuis()
	{
		list<UI*>::iterator g;
		for (g = fGuiList.begin(); g != fGuiList.end(); g++) {
			(*g)->updateAllZones();
		}
	}
	
	// -- active widgets
	
	virtual void addButton(const char* label, float* zone) = 0;
	virtual void addToggleButton(const char* label, float* zone) = 0;
	virtual void addCheckButton(const char* label, float* zone) = 0;
	virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0;
	virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) = 0;
	virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step) = 0;
	
	// -- passive widgets
	
	virtual void addNumDisplay(const char* label, float* zone, int precision) = 0;
	virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) = 0;
	virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) = 0;
	virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) = 0;
	
	void addCallback(float* zone, uiCallback foo, void* data);
	
	// -- widget's layouts
	
	virtual void openFrameBox(const char* label) = 0;
	virtual void openTabBox(const char* label) = 0;
	virtual void openHorizontalBox(const char* label) = 0;
	virtual void openVerticalBox(const char* label) = 0;
	virtual void closeBox() = 0;

    virtual void declare(float* zone, const char* key, const char* value) {}
};

class OSCUI : public UI 
{
 public:
		
	OSCUI() : UI() 
    {}
	
	virtual ~OSCUI() {
		// suppression de this dans fGuiList
	}

	
	// -- active widgets
	
	virtual void addButton(const char* label, float* zone) {}
	virtual void addToggleButton(const char* label, float* zone) {}
	virtual void addCheckButton(const char* label, float* zone) {}
	virtual void addVerticalSlider(const char* label, float* zone, float init, float min, float max, float step) {}
	virtual void addHorizontalSlider(const char* label, float* zone, float init, float min, float max, float step) {}
	virtual void addNumEntry(const char* label, float* zone, float init, float min, float max, float step) {}
	
	// -- passive widgets
	
	virtual void addNumDisplay(const char* label, float* zone, int precision) {}
	virtual void addTextDisplay(const char* label, float* zone, char* names[], float min, float max) {}
	virtual void addHorizontalBargraph(const char* label, float* zone, float min, float max) {}
	virtual void addVerticalBargraph(const char* label, float* zone, float min, float max) {}
	
	void addCallback(float* zone, uiCallback foo, void* data);
	
	// -- widget's layouts
	
	virtual void openFrameBox(const char* label) {}
	virtual void openTabBox(const char* label) {}
	virtual void openHorizontalBox(const char* label) {}
	virtual void openVerticalBox(const char* label) {}
	virtual void closeBox() {}

    virtual void declare(float* zone, const char* key, const char* value) {}
};

list<UI*> UI::fGuiList;

/**
 * User Interface Item: abstract definition
 */

class uiItem
{
  protected :
		  
	UI*		fGUI;
	float*	fZone;
	float	fCache;
	
	uiItem (UI* ui, float* zone) : fGUI(ui), fZone(zone), fCache(-123456.654321) 
	{ 
		ui->registerZone(zone, this); 
	}	
	
  public :

	virtual ~uiItem() {}
	
	void modifyZone(float v) 	
	{ 
		fCache = v;
		if (*fZone != v) {
			*fZone = v;
			fGUI->updateZone(fZone);
		}
	}
		  	
	float			cache()			{ return fCache; }
	virtual void 	reflectZone() 	= 0;	
};


/**
 * Callback Item
 */

struct uiCallbackItem : public uiItem
{
	uiCallback	fCallback;
	void*		fData;
	
	uiCallbackItem(UI* ui, float* zone, uiCallback foo, void* data) 
			: uiItem(ui, zone), fCallback(foo), fData(data) {}
	
	virtual void 	reflectZone() {		
		float 	v = *fZone;
		fCache = v; 
		fCallback(v, fData);	
	}
};

/**
 * Update all user items reflecting zone z
 */

inline void UI::updateZone(float* z)
{
	float 	v = *z;
	clist* 	l = fZoneMap[z];
	for (clist::iterator c = l->begin(); c != l->end(); c++) {
		if ((*c)->cache() != v) (*c)->reflectZone();
	}
}

/**
 * Update all user items not up to date
 */

inline void UI::updateAllZones()
{
	for (zmap::iterator m = fZoneMap.begin(); m != fZoneMap.end(); m++) {
		float* 	z = m->first;
		clist*	l = m->second;
		float	v = *z;
		for (clist::iterator c = l->begin(); c != l->end(); c++) {
			if ((*c)->cache() != v) (*c)->reflectZone();
		}
	}
}

inline void UI::addCallback(float* zone, uiCallback foo, void* data) 
{ 
	new uiCallbackItem(this, zone, foo, data); 
};		

//----------------------------------------------------------------
//  definition du processeur de signal
//----------------------------------------------------------------
			
class dsp {
 protected:
	int fSamplingFreq;
 public:
	dsp() {}
	virtual ~dsp() {}
	
	virtual int getNumInputs() 										= 0;
	virtual int getNumOutputs() 									= 0;
	virtual void buildUserInterface(UI* interface) 					= 0;
	virtual void init(int samplingRate) 							= 0;
 	virtual void compute(int len, float** inputs, float** outputs) 	= 0;
 	virtual void conclude() 										{}
};

		
/********************END ARCHITECTURE SECTION (part 1/2)****************/

/**************************BEGIN USER SECTION **************************/
		
<<includeclass>>

/***************************END USER SECTION ***************************/

/*******************BEGIN ARCHITECTURE SECTION (part 2/2)***************/
					

/******************************************************************************
*******************************************************************************

							JACK AUDIO INTERFACE

*******************************************************************************
*******************************************************************************/

#define JACK_DRIVER_NAME_MAX          15
#define JACK_DRIVER_PARAM_NAME_MAX    15
#define JACK_DRIVER_PARAM_STRING_MAX  63
#define JACK_DRIVER_PARAM_DESC        255
#define JACK_PATH_MAX                 511

/** Driver parameter types */
typedef enum
{
    JackDriverParamInt = 1,
    JackDriverParamUInt,
    JackDriverParamChar,
    JackDriverParamString,
    JackDriverParamBool
} jack_driver_param_type_t;

/** Driver parameter value */
typedef union
{
    uint32_t ui;
    int32_t i;
    char c;
    char str[JACK_DRIVER_PARAM_STRING_MAX + 1];
} jack_driver_param_value_t;


/** A driver parameter descriptor */
typedef struct {
    char name[JACK_DRIVER_NAME_MAX + 1]; /**< The parameter's name */
    char character;                    /**< The parameter's character (for getopt, etc) */
    jack_driver_param_type_t type;     /**< The parameter's type */
    jack_driver_param_value_t value;   /**< The parameter's (default) value */
    char short_desc[64];               /**< A short (~30 chars) description for the user */
    char long_desc[1024];              /**< A longer description for the user */
}
jack_driver_param_desc_t;

/** A driver parameter */
typedef struct {
    char character;
    jack_driver_param_value_t value;
}
jack_driver_param_t;

/** A struct for describing a jack driver */
typedef struct {
    char name[JACK_DRIVER_NAME_MAX + 1];      /**< The driver's canonical name */
    char desc[JACK_DRIVER_PARAM_DESC + 1];    /**< The driver's extended description */
    char file[JACK_PATH_MAX + 1];             /**< The filename of the driver's shared object file */
    uint32_t nparams;                         /**< The number of parameters the driver has */
    jack_driver_param_desc_t * params;        /**< An array of parameter descriptors */
}
jack_driver_desc_t;

// class JackArgParser ***************************************************
class  JackArgParser
{
    private:

        std::string fArgString;
        int fArgc;
        std::vector<std::string> fArgv;

    public:

        JackArgParser (const char* arg);
        ~JackArgParser();
        std::string GetArgString();
        int GetNumArgv();
        int GetArgc();
        int GetArgv (std::vector<std::string>& argv);
        int GetArgv (char** argv);
        void DeleteArgv (const char** argv);
        void ParseParams (jack_driver_desc_t* desc, JSList** param_list);
        void FreeParams (JSList* param_list);
};

JackArgParser::JackArgParser (const char* arg)
{
    printf ("JackArgParser::JackArgParser, arg_string : '%s' \n", arg);

    fArgc = 0;
    //if empty string
    if (strlen(arg) == 0)
        return;
    fArgString = string(arg);
    //else parse the arg string
    const size_t arg_len = fArgString.length();
    unsigned int i = 0;
    size_t pos = 0;
    size_t start = 0;
    size_t copy_start = 0;
    size_t copy_length = 0;
    //we need a 'space terminated' string
    fArgString += " ";
    //first fill a vector with args
    do {
        //find the first non-space character from the actual position
        start = fArgString.find_first_not_of (' ', start);
        //get the next quote or space position
        pos = fArgString.find_first_of (" \"" , start);
        //no more quotes or spaces, consider the end of the string
        if (pos == string::npos)
            pos = arg_len;
        //if double quote
        if (fArgString[pos] == '\"') {
            //first character : copy the substring
            if (pos == start) {
                copy_start = start + 1;
                pos = fArgString.find ('\"', ++pos);
                copy_length = pos - copy_start;
                start = pos + 1;
            }
            //else there is someting before the quote, first copy that
            else {
                copy_start = start;
                copy_length = pos - copy_start;
                start = pos;
            }
        }
        //if space
        if (fArgString[pos] == ' ') {
            //short option descriptor
            if ((fArgString[start] == '-') && (fArgString[start + 1] != '-')) {
                copy_start = start;
                copy_length = 2;
                start += copy_length;
            }
            //else copy all the space delimitated string
            else {
                copy_start = start;
                copy_length = pos - copy_start;
                start = pos + 1;
            }
        }
        //then push the substring to the args vector
        fArgv.push_back (fArgString.substr (copy_start, copy_length));
        printf("JackArgParser::JackArgParser, add : '%s' \n", (*fArgv.rbegin()).c_str());
    } while (start < arg_len);

    //finally count the options
    for (i = 0; i < fArgv.size(); i++)
        if (fArgv[i].at(0) == '-')
            fArgc++;
}

JackArgParser::~JackArgParser()
{}

string JackArgParser::GetArgString()
{
    return fArgString;
}

int JackArgParser::GetNumArgv()
{
    return fArgv.size();
}

int JackArgParser::GetArgc()
{
    return fArgc;
}

int JackArgParser::GetArgv(vector<string>& argv)
{
    argv = fArgv;
    return 0;
}

int JackArgParser::GetArgv(char** argv)
{
    //argv must be NULL
    if (argv)
        return -1;
    //else allocate and fill it
    argv = (char**)calloc(fArgv.size(), sizeof(char*));
    for (unsigned int i = 0; i < fArgv.size(); i++) {
        argv[i] = (char*)calloc(fArgv[i].length(), sizeof(char));
        fill_n(argv[i], fArgv[i].length() + 1, 0);
        fArgv[i].copy(argv[i], fArgv[i].length());
    }
    return 0;
}

void JackArgParser::DeleteArgv(const char** argv)
{
    unsigned int i;
    for (i = 0; i < fArgv.size(); i++)
        free((void*)argv[i]);
    free((void*)argv);
}

void JackArgParser::ParseParams(jack_driver_desc_t* desc, JSList** param_list)
{
    string options_list;
    unsigned long i = 0;
    unsigned int param = 0;
    size_t param_id = 0;
    JSList* params = NULL;
    jack_driver_param_t* intclient_param;

    for (i = 0; i < desc->nparams; i++)
        options_list += desc->params[i].character;

    for (param = 0; param < fArgv.size(); param++)
    {
        if (fArgv[param][0] == '-')
        {
            //valid option
            if ((param_id = options_list.find_first_of(fArgv[param].at(1))) != string::npos)
            {
                intclient_param = static_cast<jack_driver_param_t*>(calloc(1, sizeof(jack_driver_param_t)));
                intclient_param->character = desc->params[param_id].character;

                switch (desc->params[param_id].type)
                {
                    case JackDriverParamInt:
                        if (param + 1 < fArgv.size()) // something to parse
                            intclient_param->value.i = atoi(fArgv[param + 1].c_str());
                        break;
                        
                    case JackDriverParamUInt:
                        if (param + 1 < fArgv.size()) // something to parse
                            intclient_param->value.ui = strtoul(fArgv[param + 1].c_str(), NULL, 10);
                        break;
                        
                    case JackDriverParamChar:
                        if (param + 1 < fArgv.size()) // something to parse
                            intclient_param->value.c = fArgv[param + 1][0];
                        break;
                        
                    case JackDriverParamString:
                        if (param + 1 < fArgv.size()) // something to parse
                            fArgv[param + 1].copy(intclient_param->value.str, min(static_cast<int>(fArgv[param + 1].length()), JACK_DRIVER_PARAM_STRING_MAX));
                        break;
                        
                    case JackDriverParamBool:
                        intclient_param->value.i = true;
                        break;
                }
                //add to the list
                params = jack_slist_append(params, intclient_param);
            }
            //invalid option
            else
                printf("Invalid option '%c'\n", fArgv[param][1]);
        }
    }

    assert(param_list);
    *param_list = params;
}

void JackArgParser::FreeParams(JSList* param_list)
{
    JSList *node_ptr = param_list;
    JSList *next_node_ptr;

    while (node_ptr) {
        next_node_ptr = node_ptr->next;
        free(node_ptr->data);
        free(node_ptr);
        node_ptr = next_node_ptr;
    }
}

struct JackFaustInternal {

    //----------------------------------------------------------------------------
    // 	number of input and output channels
    //----------------------------------------------------------------------------

    int	fNumInChans;
    int	fNumOutChans;

    //----------------------------------------------------------------------------
    // Jack ports
    //----------------------------------------------------------------------------

    jack_port_t* fInputPorts[256];
    jack_port_t* fOutputPorts[256];

    //----------------------------------------------------------------------------
    // tables of noninterleaved input and output channels for FAUST
    //----------------------------------------------------------------------------

    float* fInChannel[256];
    float* fOutChannel[256];
    
    jack_client_t* fClient;
    UI* fInterface;
    mydsp fDSP;
    
    JackFaustInternal(jack_client_t* client, const JSList* params)
        :fClient(client)
    {}
    
    ~JackFaustInternal()
    {
        delete fInterface;
    }
    
    int Open()
    {
        char**	physicalInPorts;
        char**	physicalOutPorts;
 
        fInterface = new OSCUI();
        fDSP.buildUserInterface(fInterface);
         
        jack_set_process_callback(fClient, process, this);
        jack_set_sample_rate_callback(fClient, srate, this);
        
        fNumInChans = fDSP.getNumInputs();
        fNumOutChans = fDSP.getNumOutputs();
        
        for (int i = 0; i < fNumInChans; i++) {
            char buf[256];
            snprintf(buf, 256, "in_%d", i); 
            fInputPorts[i] = jack_port_register(fClient, buf, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
        }
        for (int i = 0; i < fNumOutChans; i++) {
            char buf[256];
            snprintf(buf, 256, "out_%d", i); 
            fOutputPorts[i] = jack_port_register(fClient, buf, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
        }
        
        fDSP.init(jack_get_sample_rate(fClient));
        
        physicalInPorts = (char **)jack_get_ports(fClient, NULL, NULL, JackPortIsPhysical|JackPortIsInput);
        physicalOutPorts = (char **)jack_get_ports(fClient, NULL, NULL, JackPortIsPhysical|JackPortIsOutput);
            
        if (jack_activate(fClient)) {
            fprintf(stderr, "cannot activate client");
            return -1;
        }
        
        if (physicalOutPorts != NULL) {
            for (int i = 0; i < fNumInChans && physicalOutPorts[i]; i++) {
                jack_connect(fClient, physicalOutPorts[i], jack_port_name(fInputPorts[i]));
            }
        }
        
        if (physicalInPorts != NULL) {
            for (int i = 0; i < fNumOutChans && physicalInPorts[i]; i++) {
                jack_connect(fClient, jack_port_name(fOutputPorts[i]), physicalInPorts[i]);
            } 		
        }
  
        return 0;
    }    
 
    //----------------------------------------------------------------------------
    // Jack Callbacks 
    //----------------------------------------------------------------------------

    static int srate(jack_nframes_t nframes, void *arg)
    {
        printf("the sample rate is now %u/sec\n", nframes);
        return 0;
    }

    static int process(jack_nframes_t nframes, void *arg)
    {
        JackFaustInternal* obj = (JackFaustInternal*)arg;
        AVOIDDENORMALS;
        
        for (int i = 0; i < obj->fNumInChans; i++) {
            obj->fInChannel[i] = (float *)jack_port_get_buffer(obj->fInputPorts[i], nframes);
        }
        for (int i = 0; i < obj->fNumOutChans; i++) {
            obj->fOutChannel[i] = (float *)jack_port_get_buffer(obj->fOutputPorts[i], nframes);
        }
        obj->fDSP.compute(nframes, obj->fInChannel, obj->fOutChannel);
        
        return 0;
    }
    
};

#ifdef __cplusplus
extern "C"
{
#endif

jack_driver_desc_t* jack_get_descriptor() 
{
    jack_driver_desc_t *desc;
    unsigned int i;
    desc = (jack_driver_desc_t*)calloc(1, sizeof(jack_driver_desc_t));

    strcpy(desc->name, "faust");                                    // size MUST be less then JACK_DRIVER_NAME_MAX + 1
    strcpy(desc->desc, " Faust generated internal");      // size MUST be less then JACK_DRIVER_PARAM_DESC + 1
    
    desc->nparams = 0;
    /*
    desc->nparams = 2;
    desc->params = (jack_driver_param_desc_t*)calloc(desc->nparams, sizeof(jack_driver_param_desc_t));

    i = 0;
    strcpy(desc->params[i].name, "channels");
    desc->params[i].character = 'c';
    desc->params[i].type = JackDriverParamInt;
    desc->params[i].value.ui = 0;
    strcpy(desc->params[i].short_desc, "Maximum number of channels");
    strcpy(desc->params[i].long_desc, desc->params[i].short_desc);

    i++;
    strcpy(desc->params[i].name, "inchannels");
    desc->params[i].character = 'i';
    desc->params[i].type = JackDriverParamInt;
    desc->params[i].value.ui = 0;
    strcpy(desc->params[i].short_desc, "Maximum number of input channels");
    strcpy(desc->params[i].long_desc, desc->params[i].short_desc);
    */

    return desc;
}

int jack_internal_initialize(jack_client_t* client, const JSList* params)
{
    try {
    
        JackFaustInternal* internal = new JackFaustInternal(client, params);
        if (internal->Open() == 0) {
            return 0;
        } else {
            delete internal;
            return 1;
        }
    
    } catch (...) {
        return 1;
    }
}

int jack_initialize(jack_client_t* client, const char* load_init)
{
    JSList* params = NULL;
    jack_driver_desc_t *desc = jack_get_descriptor();

    JackArgParser parser(load_init);
    if (parser.GetArgc() > 0) 
        parser.ParseParams(desc, &params);
    
    int res = jack_internal_initialize(client, params);
    parser.FreeParams(params);
    return res;
}

void jack_finish(void* arg)
{
    JackFaustInternal* internal = static_cast<JackFaustInternal*>(arg);

    if (internal) {
        printf("Unloading internal\n");
        delete internal;
    }
}

#ifdef __cplusplus
}
#endif
	
		
/********************END ARCHITECTURE SECTION (part 2/2)****************/