1 /*
2     csoundCore.h:
3 
4     Copyright (C) 1991-2006 Barry Vercoe, John ffitch, Istvan Varga
5 
6     This file is part of Csound.
7 
8     The Csound Library is free software; you can redistribute it
9     and/or modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation; either
11     version 2.1 of the License, or (at your option) any later version.
12 
13     Csound 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.  See the
16     GNU Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public
19     License along with Csound; if not, write to the Free Software
20     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21     02110-1301 USA
22 */
23 
24 #if !defined(__BUILDING_LIBCSOUND) && !defined(CSOUND_CSDL_H)
25 #  error "Csound plugins and host applications should not include csoundCore.h"
26 #endif
27 
28 #ifndef CSOUNDCORE_H
29 #define CSOUNDCORE_H
30 
31 #if defined(__EMSCRIPTEN__) && !defined(EMSCRIPTEN)
32 #define EMSCRIPTEN
33 #endif
34 
35 #include "sysdep.h"
36 #if !defined(EMSCRIPTEN) && !defined(CABBAGE)
37 #if defined(HAVE_PTHREAD)
38 #include <pthread.h>
39 #endif
40 #endif
41 #include "cs_par_structs.h"
42 #include <stdarg.h>
43 #include <setjmp.h>
44 #include "csound_type_system.h"
45 #include "csound.h"
46 #include "cscore.h"
47 #include "csound_data_structures.h"
48 #include "csound_standard_types.h"
49 #include "pools.h"
50 
51 #ifndef CSOUND_CSDL_H
52 /* VL not sure if we need to check for SSE */
53 #if defined(__SSE__) && !defined(EMSCRIPTEN)
54 #include <xmmintrin.h>
55 #ifndef _MM_DENORMALS_ZERO_ON
56 #define _MM_DENORMALS_ZERO_MASK   0x0040
57 #define _MM_DENORMALS_ZERO_ON     0x0040
58 #define _MM_DENORMALS_ZERO_OFF    0x0000
59 #define _MM_SET_DENORMALS_ZERO_MODE(mode)                                   \
60             _mm_setcsr((_mm_getcsr() & ~_MM_DENORMALS_ZERO_MASK) | (mode))
61 #define _MM_GET_DENORMALS_ZERO_MODE()                                       \
62             (_mm_getcsr() & _MM_DENORMALS_ZERO_MASK)
63 #endif
64 #else
65 #ifndef _MM_DENORMALS_ZERO_ON
66 #define _MM_DENORMALS_ZERO_MASK   0
67 #define _MM_DENORMALS_ZERO_ON     0
68 #define _MM_DENORMALS_ZERO_OFF    0
69 #define _MM_SET_DENORMALS_ZERO_MODE(mode)
70 #endif
71 #endif
72 #endif
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif /*  __cplusplus */
77 
78 #ifdef __MACH__
79 #include <xlocale.h>
80 #endif
81 
82 #if (defined(__MACH__) || defined(ANDROID) || defined(NACL) || defined(__CYGWIN__))
83 #include <pthread.h>
84 #define BARRIER_SERIAL_THREAD (-1)
85 typedef struct {
86   pthread_mutex_t mut;
87   pthread_cond_t cond;
88   unsigned int count, max, iteration;
89 } barrier_t;
90 
91 #ifndef PTHREAD_BARRIER_SERIAL_THREAD
92 #define pthread_barrier_t barrier_t
93 #endif /* PTHREAD_BARRIER_SERIAL_THREAd */
94 #endif /* __MACH__ */
95 
96 #define OK        (0)
97 #define NOTOK     (-1)
98 
99 #define CSFILE_FD_R     1
100 #define CSFILE_FD_W     2
101 #define CSFILE_STD      3
102 #define CSFILE_SND_R    4
103 #define CSFILE_SND_W    5
104 
105 #define MAXINSNO  (200)
106 #define PMAX      (1998)
107 #define VARGMAX   (1999)
108 
109 #define ORTXT       h.optext->t
110 #define INCOUNT     ORTXT.inlist->count
111 #define OUTCOUNT    ORTXT.outlist->count   /* Not used */
112 //#define INOCOUNT    ORTXT.inoffs->count
113 //#define OUTOCOUNT   ORTXT.outoffs->count
114 #define INOCOUNT    ORTXT.inArgCount
115 #define OUTOCOUNT   ORTXT.outArgCount
116 #define IS_ASIG_ARG(x) (csoundGetTypeForArg(x) == &CS_VAR_TYPE_A)
117 #define IS_STR_ARG(x) (csoundGetTypeForArg(x) == &CS_VAR_TYPE_S)
118 
119 #define CURTIME (((double)csound->icurTime)/((double)csound->esr))
120 #define CURTIME_inc (((double)csound->ksmps)/((double)csound->esr))
121 
122 #ifdef  B64BIT
123 #define MAXLEN     0x40000000
124 #define FMAXLEN    ((MYFLT)(MAXLEN))
125 #define PHMASK     0x3fffffff
126 #else
127 #define MAXLEN     0x1000000L
128 #define FMAXLEN    ((MYFLT)(MAXLEN))
129 #define PHMASK     0x0FFFFFFL
130 #endif
131 
132 #define MAX_STRING_CHANNEL_DATASIZE 16384
133 
134 #define PFRAC(x)   ((MYFLT)((x) & ftp->lomask) * ftp->lodiv)
135 #define MAXPOS     0x7FFFFFFFL
136 
137 #define BYTREVS(n) ((n>>8  & 0xFF) | (n<<8 & 0xFF00))
138 #define BYTREVL(n) ((n>>24 & 0xFF) | (n>>8 & 0xFF00L) | \
139                     (n<<8 & 0xFF0000L) | (n<<24 & 0xFF000000L))
140 
141 #define OCTRES     8192
142 #define CPSOCTL(n) ((MYFLT)(1<<((int)(n)>>13))*csound->cpsocfrc[(int)(n)&8191])
143 
144 #define LOBITS     10
145 #define LOFACT     1024
146   /* LOSCAL is 1/LOFACT as MYFLT */
147 #define LOSCAL     FL(0.0009765625)
148 
149 #define LOMASK     1023
150 
151 #ifdef USE_DOUBLE
152   extern int64_t MYNAN;
153   //#define SSTRCOD    (nan("0"))
154 #define SSTRCOD    (double)NAN
155 #else
156   extern int32 MYNAN;
157 #define SSTRCOD    (float)NAN
158   //#define SSTRCOD    (nanf("0"))
159 #endif
160   //#define ISSTRCOD(X) isnan(X)
161   //#ifndef __MACH__
162 extern int ISSTRCOD(MYFLT);
163   //#else
164 //#define ISSTRCOD(X) isnan(X)
165 //#endif
166 
167 #define SSTRSIZ    1024
168 #define ALLCHNLS   0x7fff
169 #define DFLT_SR    FL(44100.0)
170 #define DFLT_KR    FL(4410.0)
171 #define DFLT_KSMPS 10
172 #define DFLT_NCHNLS 1
173 #define MAXCHNLS   256
174 
175 #define MAXNAME   (256)
176 
177 #define DFLT_DBFS (FL(32768.0))
178 
179 #define MAXOCTS         8
180 #define MAXCHAN         16      /* 16 MIDI channels; only one port for now */
181 
182          /* A440 tuning factor */
183 #define ONEPT           (csound->A4/430.5389646099018460319362438314060262605)
184 #define LOG10D20        0.11512925              /* for db to ampfac   */
185 #define DV32768         FL(0.000030517578125)
186 
187 #ifndef PI
188 #define PI      (3.141592653589793238462643383279502884197)
189 #endif /* pi */
190 #define TWOPI   (6.283185307179586476925286766559005768394)
191 #define HALFPI  (1.570796326794896619231321691639751442099)
192 #define PI_F    ((MYFLT) PI)
193 #define TWOPI_F ((MYFLT) TWOPI)
194 #define HALFPI_F ((MYFLT) HALFPI)
195 #define INF     (2147483647.0)
196 #define ROOT2   (1.414213562373095048801688724209698078569)
197 
198 #define AMPLMSG 01
199 #define RNGEMSG 02
200 #define WARNMSG 04
201 #define RAWMSG  0x40
202 #define TIMEMSG 0x80
203 #define IGN(X)  (void) X
204 
205 #define ARG_CONSTANT 0
206 #define ARG_STRING 1
207 #define ARG_PFIELD 2
208 #define ARG_GLOBAL 3
209 #define ARG_LOCAL 4
210 #define ARG_LABEL 5
211 
212 #define ASYNC_GLOBAL 1
213 #define ASYNC_LOCAL  2
214 
215 enum {FFT_LIB=0, PFFT_LIB, VDSP_LIB};
216 enum {FFT_FWD=0, FFT_INV};
217 
218 /* advance declaration for
219   API  message queue struct
220 */
221 struct _message_queue;
222 
223 typedef struct CORFIL {
224     char    *body;
225     unsigned int     len;
226     unsigned int     p;
227   } CORFIL;
228 
229   typedef struct {
230     int     odebug;
231     int     sfread, sfwrite, sfheader, filetyp;
232     int     inbufsamps, outbufsamps;
233     int     informat, outformat;
234     int     sfsampsize;
235     int     displays, graphsoff, postscript, msglevel;
236     int     Beatmode, oMaxLag;
237     int     usingcscore, Linein;
238     int     RTevents, Midiin, FMidiin, RMidiin;
239     int     ringbell, termifend;
240     int     rewrt_hdr, heartbeat, gen01defer;
241     double  cmdTempo;
242     float   sr_override, kr_override;
243     int     nchnls_override, nchnls_i_override;
244     char    *infilename, *outfilename;
245     CORFIL  *playscore;
246     char    *Linename, *Midiname, *FMidiname;
247     char    *Midioutname;   /* jjk 09252000 - MIDI output device, -Q option */
248     char    *FMidioutname;
249     int     midiKey, midiKeyCps, midiKeyOct, midiKeyPch;
250     int     midiVelocity, midiVelocityAmp;
251     int     noDefaultPaths;  /* syy - Oct 25, 2006: for disabling relative paths
252                                 from files */
253     int     numThreads;
254     int     syntaxCheckOnly;
255     int     useCsdLineCounts;
256     int     sampleAccurate;  /* switch for score events sample accuracy */
257     int     realtime; /* realtime priority mode  */
258     MYFLT   e0dbfs_override;
259     int     daemon;
260     double  quality;        /* for ogg encoding */
261     int     ksmps_override;
262     int     fft_lib;
263     int     echo;
264   } OPARMS;
265 
266   typedef struct arglst {
267     int     count;
268     char    *arg[1];
269   } ARGLST;
270 
271   typedef struct arg {
272     int type;
273     void* argPtr;
274     int index;
275     struct arg* next;
276   } ARG;
277 //  typedef struct argoffs {
278 //    int     count;
279 //    int     indx[1];
280 //  } ARGOFFS;
281 
282     typedef struct oentry {
283         char    *opname;
284         uint16  dsblksiz;
285         uint16  flags;
286         uint8_t thread;
287         char    *outypes;
288         char    *intypes;
289         int     (*iopadr)(CSOUND *, void *p);
290         int     (*kopadr)(CSOUND *, void *p);
291         int     (*aopadr)(CSOUND *, void *p);
292         void    *useropinfo;    /* user opcode parameters */
293     } OENTRY;
294 
295   /**
296    * Storage for parsed orchestra code, for each opcode in an INSTRTXT.
297    */
298   typedef struct text {
299     int             linenum;        /* Line num in orch file (currently buggy!)  */
300     OENTRY          *oentry;
301     char            *opcod;         /* Pointer to opcode name in global pool */
302     ARGLST          *inlist;        /* Input args (pointer to item in name list) */
303     ARGLST          *outlist;
304     ARG             *inArgs;        /* Input args (index into list of values) */
305     unsigned int    inArgCount;
306     ARG             *outArgs;
307     unsigned        int outArgCount;
308     char            intype;         /* Type of first input argument (g,k,a,w etc) */
309     char            pftype;         /* Type of output argument (k,a etc) */
310   } TEXT;
311 
312 
313   /**
314    * This struct is filled out by otran() at orch parse time.
315    * It is used as a template for instrument events.
316    */
317   typedef struct instr {
318     struct op * nxtop;              /* Linked list of instr opcodes */
319     TEXT    t;                      /* Text of instrument (same in nxtop) */
320     int     pmax, vmax, pextrab;    /* Arg count, size of data for all
321                                        opcodes in instr */
322     //int     mdepends;               /* Opcode type (i/k/a) */
323     CS_VAR_POOL* varPool;
324 
325     //    int     optxtcount;
326     int16   muted;
327 //    int32   localen;
328     int32   opdstot;                /* Total size of opds structs in instr */
329 //    int32   *inslist;               /* Only used in parsing (?) */
330     MYFLT   *psetdata;              /* Used for pset opcode */
331     struct insds * instance;        /* Chain of allocated instances of
332                                        this instrument */
333     struct insds * lst_instance;    /* last allocated instance */
334     struct insds * act_instance;    /* Chain of free (inactive) instances */
335                                     /* (pointer to next one is INSDS.nxtact) */
336     struct instr * nxtinstxt;       /* Next instrument in orch (num order) */
337     int     active;                 /* To count activations for control */
338     int     pending_release;        /* To count instruments in release phase */
339     int     maxalloc;
340     MYFLT   cpuload;                /* % load this instrumemnt makes */
341     struct opcodinfo *opcode_info;  /* UDO info (when instrs are UDOs) */
342     char    *insname;               /* instrument name */
343     int     instcnt;                /* Count number of instances ever */
344     int     isNew;                  /* is this a new definition */
345     int     nocheckpcnt;            /* Control checks on pcnt */
346   } INSTRTXT;
347 
348   typedef struct namedInstr {
349     int32        instno;
350     char        *name;
351     INSTRTXT    *ip;
352     struct namedInstr   *next;
353   } INSTRNAME;
354 
355   /**
356    * A chain of TEXT structs. Note that this is identical with the first two
357    * members of struct INSTRTEXT, and is so typecast at various points in code.
358    */
359   typedef struct op {
360     struct op *nxtop;
361     TEXT    t;
362   } OPTXT;
363 
364   typedef struct fdch {
365     struct fdch *nxtchp;
366     /** handle returned by csound->FileOpen() */
367     void    *fd;
368   } FDCH;
369 
370   typedef struct auxch {
371     struct auxch *nxtchp;
372     size_t  size;
373     void    *auxp, *endp;
374   } AUXCH;
375 
376   /**  this callback is used to notify the
377        availability of new storage in AUXCH *.
378        It can be used to swap the old storage
379        for the new one and return it for deallocation.
380   */
381   typedef AUXCH* (*aux_cb)(CSOUND *, void *, AUXCH *);
382 
383   /**
384    * AuxAllocAsync data
385    */
386   typedef struct {
387     CSOUND *csound;
388     size_t nbytes;
389     AUXCH *auxchp;
390     void *userData;
391     aux_cb notify;
392   } AUXASYNC;
393 
394   typedef struct {
395     int      dimensions;
396     int*     sizes;             /* size of each dimensions */
397     int      arrayMemberSize;
398     CS_TYPE* arrayType;
399     MYFLT*   data;
400 //    AUXCH   aux;
401   } ARRAYDAT;
402 
403    typedef struct {
404       int     size;             /* 0...size-1 */
405       MYFLT   *data;
406       AUXCH   aux;
407    } TABDAT;
408 
409   typedef struct {
410     char *data;
411     int size;
412   } STRINGDAT;
413 
414   typedef struct monblk {
415     int16   pch;
416     struct monblk *prv;
417   } MONPCH;
418 
419   typedef struct {
420     int     notnum[4];
421   } DPEXCL;
422 
423   typedef struct {
424     DPEXCL  dpexcl[8];
425     /** for keys 25-99 */
426     int     exclset[75];
427   } DPARM;
428 
429   typedef struct dklst {
430     struct dklst *nxtlst;
431     int32    pgmno;
432     /** cnt + keynos */
433     MYFLT   keylst[1];
434   } DKLST;
435 
436   typedef struct mchnblk {
437     /** most recently received program change */
438     int16   pgmno;
439     /** instrument number assigned to this channel */
440     int16   insno;
441     int16   RegParNo;
442     int16   mono;
443     MONPCH  *monobas;
444     MONPCH  *monocur;
445     /** list of active notes (NULL: not active) */
446     struct insds *kinsptr[128];
447     /** polyphonic pressure indexed by note number */
448     MYFLT   polyaft[128];
449     /** ... with GS vib_rate, stored in c128-c135 */
450     MYFLT   ctl_val[136];
451     /** program change to instr number (<=0: ignore) */
452     int16   pgm2ins[128];
453     /** channel pressure (0-127) */
454     MYFLT   aftouch;
455     /** pitch bend (-1 to 1) */
456     MYFLT   pchbend;
457     /** pitch bend sensitivity in semitones */
458     MYFLT   pbensens;
459     /** number of held (sustaining) notes */
460     int16   ksuscnt;
461     /** current state of sustain pedal (0: off) */
462     int16   sustaining;
463     int     dpmsb;
464     int     dplsb;
465     int     datenabl;
466     /** chain of dpgm keylists */
467     DKLST   *klists;
468     /** drumset params         */
469     DPARM   *dparms;
470   } MCHNBLK;
471 
472   /**
473    * This struct holds the data for one score event.
474    */
475   typedef struct event {
476     /** String argument(s) (NULL if none) */
477     int     scnt;
478     char    *strarg;
479     /* instance pointer */
480     void  *pinstance;  /* used in nstance opcode */
481     /** Event type */
482     char    opcod;
483     /** Number of p-fields */
484     int16   pcnt;
485     /** Event start time */
486     MYFLT   p2orig;
487     /** Length */
488     MYFLT   p3orig;
489     /** All p-fields for this event (SSTRCOD: string argument) */
490     MYFLT   p[PMAX + 1];
491     union {                   /* To ensure size is same as earlier */
492       MYFLT   *extra;
493       MYFLT   p[2];
494     } c;
495   } EVTBLK;
496   /**
497    * This struct holds the info for a concrete instrument event
498    * instance in performance.
499    */
500   typedef struct insds {
501     /* Chain of init-time opcodes */
502     struct opds * nxti;
503     /* Chain of performance-time opcodes */
504     struct opds * nxtp;
505     /* Next allocated instance */
506     struct insds * nxtinstance;
507     /* Previous allocated instance */
508     struct insds * prvinstance;
509     /* Next in list of active instruments */
510     struct insds * nxtact;
511     /* Previous in list of active instruments */
512     struct insds * prvact;
513     /* Next instrument to terminate */
514     struct insds * nxtoff;
515     /* Chain of files used by opcodes in this instr */
516     FDCH    *fdchp;
517     /* Extra memory used by opcodes in this instr */
518     AUXCH   *auxchp;
519     /* Extra release time requested with xtratim opcode */
520     int      xtratim;
521     /* MIDI note info block if event started from MIDI */
522     MCHNBLK *m_chnbp;
523     /* ptr to next overlapping MIDI voice */
524     struct insds * nxtolap;
525     /* Instrument number */
526     int16   insno;
527     /* Instrument def address */
528     INSTRTXT *instr;
529     /* non-zero for sustaining MIDI note */
530     int16    m_sust;
531     /* MIDI pitch, for simple access */
532     unsigned char m_pitch;
533     /* ...ditto velocity */
534     unsigned char m_veloc;
535     /* Flag to indicate we are releasing, test with release opcode */
536     char     relesing;
537     /* Set if instr instance is active (perfing) */
538     char     actflg;
539     /* Time to turn off event, in score beats */
540     double   offbet;
541     /* Time to turn off event, in seconds (negative on indef/tie) */
542     double   offtim;
543     /* Python namespace for just this instance. */
544     void    *pylocal;
545     /* pointer to Csound engine and API for externals */
546     CSOUND  *csound;
547     uint64_t kcounter;
548     unsigned int     ksmps;     /* Instrument copy of ksmps */
549     MYFLT    ekr;                /* and of rates */
550     MYFLT    onedksmps, onedkr, kicvt;
551     struct opds  *pds;          /* Used for jumping */
552     MYFLT    scratchpad[4];      /* Persistent data */
553 
554     /* user defined opcode I/O buffers */
555     void    *opcod_iobufs;
556     void    *opcod_deact, *subins_deact;
557     /* opcodes to be run at note deactivation */
558     void    *nxtd;
559     uint32_t ksmps_offset; /* ksmps offset for sample accuracy */
560     uint32_t no_end;      /* samps left at the end for sample accuracy
561                              (calculated) */
562     uint32_t ksmps_no_end; /* samps left at the end for sample accuracy
563                               (used by opcodes) */
564     MYFLT   *spin;         /* offset into csound->spin */
565     MYFLT   *spout;        /* offset into csound->spout, or local spout */
566     int      init_done;
567     int      tieflag;
568     int      reinitflag;
569     MYFLT    retval;
570     MYFLT   *lclbas;  /* base for variable memory pool */
571     char    *strarg;       /* string argument */
572     /* Copy of required p-field values for quick access */
573     CS_VAR_MEM  p0;
574     CS_VAR_MEM  p1;
575     CS_VAR_MEM  p2;
576     CS_VAR_MEM  p3;
577   } INSDS;
578 
579 #define CS_KSMPS     (p->h.insdshead->ksmps)
580 #define CS_KCNT      (p->h.insdshead->kcounter)
581 #define CS_EKR       (p->h.insdshead->ekr)
582 #define CS_ONEDKSMPS (p->h.insdshead->onedksmps)
583 #define CS_ONEDKR    (p->h.insdshead->onedkr)
584 #define CS_KICVT     (p->h.insdshead->kicvt)
585 #define CS_ESR       (csound->esr)
586 #define CS_PDS       (p->h.insdshead->pds)
587 #define CS_SPIN      (p->h.insdshead->spin)
588 #define CS_SPOUT     (p->h.insdshead->spout)
589 
590   typedef int (*SUBR)(CSOUND *, void *);
591 
592   /**
593    * This struct holds the info for one opcode in a concrete
594    * instrument instance in performance.
595    */
596   typedef struct opds {
597     /** Next opcode in init-time chain */
598     struct opds * nxti;
599     /** Next opcode in perf-time chain */
600     struct opds * nxtp;
601     /** Initialization (i-time) function pointer */
602     SUBR    iopadr;
603     /** Perf-time (k- or a-rate) function pointer */
604     SUBR    opadr;
605     /** Orch file template part for this opcode */
606     OPTXT   *optext;
607     /** Owner instrument instance data structure */
608     INSDS   *insdshead;
609   } OPDS;
610 
611   typedef struct lblblk {
612     OPDS    h;
613     OPDS    *prvi;
614     OPDS    *prvp;
615   } LBLBLK;
616 
617   typedef struct {
618     MYFLT   *begp, *curp, *endp, feedback[6];
619     int32    scount;
620   } OCTDAT;
621 
622   typedef struct {
623     int32    npts, nocts, nsamps;
624     MYFLT   lofrq, hifrq, looct, srate;
625     OCTDAT  octdata[MAXOCTS];
626     AUXCH   auxch;
627   } DOWNDAT;
628 
629   typedef struct {
630     uint32_t   ktimstamp, ktimprd;
631     int32    npts, nfreqs, dbout;
632     DOWNDAT *downsrcp;
633     AUXCH   auxch;
634   } SPECDAT;
635 
636 
637 
638   typedef struct {
639     MYFLT   gen01;
640     MYFLT   ifilno;
641     MYFLT   iskptim;
642     MYFLT   iformat;
643     MYFLT   channel;
644     MYFLT   sample_rate;
645     char    strarg[SSTRSIZ];
646   } GEN01ARGS;
647 
648   typedef struct {
649     /** table length, not including the guard point */
650     uint32_t flen;
651     /** length mask ( = flen - 1) for power of two table size, 0 otherwise */
652     int32    lenmask;
653     /** log2(MAXLEN / flen) for power of two table size, 0 otherwise */
654     int32    lobits;
655     /** 2^lobits - 1 */
656     int32    lomask;
657     /** 1 / 2^lobits */
658     MYFLT   lodiv;
659     /** LOFACT * (table_sr / orch_sr), cpscvt = cvtbas / base_freq */
660     MYFLT   cvtbas, cpscvt;
661     /** sustain loop mode (0: none, 1: forward, 2: forward and backward) */
662     int16   loopmode1;
663     /** release loop mode (0: none, 1: forward, 2: forward and backward) */
664     int16   loopmode2;
665     /** sustain loop start and end in sample frames */
666     int32    begin1, end1;
667     /** release loop start and end in sample frames */
668     int32    begin2, end2;
669     /** sound file length in sample frames (flenfrms = soundend - 1) */
670     int32    soundend, flenfrms;
671     /** number of channels */
672     int32    nchanls;
673     /** table number */
674     int32    fno;
675     /** args  */
676     MYFLT args[PMAX - 4];
677     /** arg count */
678     int argcnt;
679     /** GEN01 parameters */
680     GEN01ARGS gen01args;
681     /** table data (flen + 1 MYFLT values) */
682     MYFLT   *ftable;
683   } FUNC;
684 
685   typedef struct {
686     CSOUND  *csound;
687     int32   flen;
688     int     fno, guardreq;
689     EVTBLK  e;
690   } FGDATA;
691 
692   typedef struct {
693     char    *name;
694     int     (*fn)(FGDATA *, FUNC *);
695   } NGFENS;
696 
697   typedef int (*GEN)(FGDATA *, FUNC *);
698 
699   typedef struct MEMFIL {
700     char    filename[256];      /* Made larger RWD */
701     char    *beginp;
702     char    *endp;
703     int32    length;
704     struct MEMFIL *next;
705   } MEMFIL;
706 
707   typedef struct {
708     int16   type;
709     int16   chan;
710     int16   dat1;
711     int16   dat2;
712   } MEVENT;
713 
714   typedef struct SNDMEMFILE_ {
715     /** file ID (short name)          */
716     char            *name;
717     struct SNDMEMFILE_ *nxt;
718     /** full path filename            */
719     char            *fullName;
720     /** file length in sample frames  */
721     size_t          nFrames;
722     /** sample rate in Hz             */
723     double          sampleRate;
724     /** number of channels            */
725     int             nChannels;
726     /** AE_SHORT, AE_FLOAT, etc.      */
727     int             sampleFormat;
728     /** TYP_WAV, TYP_AIFF, etc.       */
729     int             fileType;
730     /**
731      * loop mode:
732      *   0: no loop information
733      *   1: off
734      *   2: forward
735      *   3: backward
736      *   4: bidirectional
737      */
738     int             loopMode;
739     /** playback start offset frames  */
740     double          startOffs;
741     /** loop start (sample frames)    */
742     double          loopStart;
743     /** loop end (sample frames)      */
744     double          loopEnd;
745     /** base frequency (in Hz)        */
746     double          baseFreq;
747     /** amplitude scale factor        */
748     double          scaleFac;
749     /** interleaved sample data       */
750     float           data[1];
751   } SNDMEMFILE;
752 
753   typedef struct pvx_memfile_ {
754     char        *filename;
755     struct pvx_memfile_ *nxt;
756     float       *data;
757     uint32 nframes;
758     int         format;
759     int         fftsize;
760     int         overlap;
761     int         winsize;
762     int         wintype;
763     int         chans;
764     MYFLT       srate;
765   } PVOCEX_MEMFILE;
766 
767 #ifdef __BUILDING_LIBCSOUND
768 
769 #define INSTR   1
770 #define ENDIN   2
771 #define OPCODE  3
772 #define ENDOP   4
773 #define LABEL   5
774 #define SETBEG  6
775 #define PSET    6
776 #define USEROPCODE    7
777 #define SETEND  8
778 
779 #define TOKMAX  50L     /* Should be 50 but bust */
780 
781 /* max number of input/output args for user defined opcodes */
782 #define OPCODENUMOUTS_LOW   16
783 #define OPCODENUMOUTS_HIGH  64
784 #define OPCODENUMOUTS_MAX   256
785 
786 #define MBUFSIZ         (4096)
787 #define MIDIINBUFMAX    (1024)
788 #define MIDIINBUFMSK    (MIDIINBUFMAX-1)
789 
790 
791 
792   typedef union {
793     uint32 dwData;
794     unsigned char bData[4];
795   } MIDIMESSAGE;
796 
797   /* MIDI globals */
798 
799   typedef struct midiglobals {
800     MEVENT  *Midevtblk;
801     int     sexp;
802     int     MIDIoutDONE;
803     int     MIDIINbufIndex;
804     MIDIMESSAGE MIDIINbuffer2[MIDIINBUFMAX];
805     int     (*MidiInOpenCallback)(CSOUND *, void **, const char *);
806     int     (*MidiReadCallback)(CSOUND *, void *, unsigned char *, int);
807     int     (*MidiInCloseCallback)(CSOUND *, void *);
808     int     (*MidiOutOpenCallback)(CSOUND *, void **, const char *);
809     int     (*MidiWriteCallback)(CSOUND *, void *, const unsigned char *, int);
810     int     (*MidiOutCloseCallback)(CSOUND *, void *);
811     const char *(*MidiErrorStringCallback)(int);
812     void    *midiInUserData;
813     void    *midiOutUserData;
814     void    *midiFileData;
815     void    *midiOutFileData;
816     int     rawControllerMode;
817     char    muteTrackList[256];
818     unsigned char mbuf[MBUFSIZ];
819     unsigned char *bufp, *endatp;
820     int16   datreq, datcnt;
821   } MGLOBAL;
822 
823   typedef struct eventnode {
824     struct eventnode  *nxt;
825     uint32     start_kcnt;
826     EVTBLK            evt;
827   } EVTNODE;
828 
829   typedef struct {
830     OPDS    h;
831     MYFLT   *ktempo, *istartempo;
832     MYFLT   prvtempo;
833   } TEMPO;
834 
835   /* typedef struct token { */
836   /*   char    *str; */
837   /*   int16   prec; */
838   /* } TOKEN; */
839 
840   typedef struct names {
841     char    *mac;
842     struct names *next;
843   } NAMES;
844 
845   typedef struct threadInfo {
846     struct threadInfo *next;
847     void * threadId;
848   } THREADINFO;
849 
850 #include "sort.h"
851 #include "text.h"
852 #include "prototyp.h"
853 #include "cwindow.h"
854 #include "envvar.h"
855 #include "remote.h"
856 
857 #define CS_STATE_PRE    (1)
858 #define CS_STATE_COMP   (2)
859 #define CS_STATE_UTIL   (4)
860 #define CS_STATE_CLN    (8)
861 #define CS_STATE_JMP    (16)
862 
863 /* These are used to set/clear bits in csound->tempStatus.
864    If the bit is set, it indicates that the given file is
865    a temporary. */
866   extern const uint32_t csOrcMask;
867   extern const uint32_t csScoInMask;
868   extern const uint32_t csScoSortMask;
869   extern const uint32_t csMidiScoMask;
870   extern const uint32_t csPlayScoMask;
871 
872 /* kperf function protoypes. Used by the debugger to switch between debug
873  * and nodebug kperf functions */
874   int kperf_nodebug(CSOUND *csound);
875   int kperf_debug(CSOUND *csound);
876 
877 #endif  /* __BUILDING_LIBCSOUND */
878 
879 #define MARGS   (3)
880 typedef struct S_MACRO {          /* To store active macros */
881     char        *name;          /* Use is by name */
882     int         acnt;           /* Count of arguments */
883     CORFIL      *body;          /* The text of the macro */
884     struct S_MACRO *next;         /* Chain of active macros */
885     int         margs;          /* ammount of space for args */
886     char        *arg[MARGS];    /* With these arguments */
887 } S_MACRO;
888 
889 typedef struct in_stack_s {     /* Stack of active inputs */
890     int16       is_marked_repeat;     /* 1 if this input created by 'n' stmnt */
891     int16       args;                 /* Argument count for macro */
892   //CORFIL      *cf;                  /* In core file */
893   //void        *fd;                  /* for closing stream */
894     S_MACRO       *mac;
895     int         line;
896     int32       oposit;
897 } IN_STACK;
898 
899 typedef struct marked_sections {
900     char        *name;
901     int32       posit;
902     int         line;
903 } MARKED_SECTIONS;
904 
905 typedef struct namelst {
906   char           *name;
907   struct namelst *next;
908 } NAMELST;
909 
910 typedef struct NAME__ {
911     char          *namep;
912     struct NAME__  *nxt;
913     int           type, count;
914 } NAME;
915 
916   /* Holds UDO information, when an instrument is
917      defined as a UDO
918   */
919   typedef struct opcodinfo {
920     int32    instno;
921     char    *name, *intypes, *outtypes;
922     int16   inchns, outchns;
923     CS_VAR_POOL* out_arg_pool;
924     CS_VAR_POOL* in_arg_pool;
925     INSTRTXT *ip;
926     struct opcodinfo *prv;
927   } OPCODINFO;
928 
929   /**
930    * This struct will hold the current engine state after compilation
931    */
932   typedef struct engine_state {
933     CS_VAR_POOL    *varPool;  /* global variable pool */
934     CS_HASH_TABLE  *constantsPool;
935     CS_HASH_TABLE  *stringPool;
936     int            maxopcno;
937     INSTRTXT      **instrtxtp; /* instrument list      */
938     INSTRTXT      instxtanchor;
939     CS_HASH_TABLE *instrumentNames; /* instrument names */
940     int           maxinsno;
941   } ENGINE_STATE;
942 
943 
944   /**
945    * Nen FFT interface
946    */
947   typedef struct _FFT_SETUP{
948     int N, M;
949     void  *setup;
950     MYFLT *buffer;
951     int    lib;
952     int    d;
953     int  p2;
954   } CSOUND_FFT_SETUP;
955 
956 
957   /**
958    * plugin module info
959    */
960   typedef struct {
961     char module[12];
962     char type[12];
963   } MODULE_INFO;
964 
965 
966 #define MAX_ALLOC_QUEUE 1024
967 
968 typedef struct _alloc_data_ {
969   int type;
970   int insno;
971   EVTBLK blk;
972   MCHNBLK *chn;
973   MEVENT mep;
974   INSDS *ip;
975   OPDS *ids;
976 } ALLOC_DATA;
977 
978 #define MAX_MESSAGE_STR 1024
979 typedef struct _message_queue_t_ {
980     int attr;
981     char str[MAX_MESSAGE_STR];
982 } message_string_queue_t;
983 
984 
985   /**
986    * Contains all function pointers, data, and data pointers required
987    * to run one instance of Csound.
988    *
989    * \b PUBLIC functions in CSOUND_
990    * These are used by plugins to access the
991    * Csound library functionality without the requirement
992    * of compile-time linkage to the csound library
993    * New functions only need to be added here if
994    * they are required by plugins.
995    */
996   struct CSOUND_ {
997 
998     /** @name Attributes */
999     /**@{ */
1000     MYFLT (*GetSr)(CSOUND *);
1001     MYFLT (*GetKr)(CSOUND *);
1002     uint32_t (*GetKsmps)(CSOUND *);
1003      /** Get number of output channels */
1004     uint32_t (*GetNchnls)(CSOUND *);
1005     /** Get number of input channels */
1006     uint32_t (*GetNchnls_i)(CSOUND *);
1007     MYFLT (*Get0dBFS) (CSOUND *);
1008     /** Get number of control blocks elapsed */
1009     uint64_t (*GetKcounter)(CSOUND *);
1010     int64_t (*GetCurrentTimeSamples)(CSOUND *);
1011     long (*GetInputBufferSize)(CSOUND *);
1012     long (*GetOutputBufferSize)(CSOUND *);
1013     MYFLT *(*GetInputBuffer)(CSOUND *);
1014     MYFLT *(*GetOutputBuffer)(CSOUND *);
1015     /** Set internal debug mode */
1016     void (*SetDebug)(CSOUND *, int d);
1017     int (*GetDebug)(CSOUND *);
1018     int (*GetSizeOfMYFLT)(void);
1019     void (*GetOParms)(CSOUND *, OPARMS *);
1020     /** Get environment variable */
1021     const char *(*GetEnv)(CSOUND *, const char *name);
1022     /**@}*/
1023     /** @name Message printout */
1024     /**@{ */
1025     CS_PRINTF2 void (*Message)(CSOUND *, const char *fmt, ...);
1026     CS_PRINTF3 void (*MessageS)(CSOUND *, int attr, const char *fmt, ...);
1027     void (*MessageV)(CSOUND *, int attr, const char *format, va_list args);
1028     int (*GetMessageLevel)(CSOUND *);
1029     void (*SetMessageLevel)(CSOUND *, int messageLevel);
1030     void (*SetMessageCallback)(CSOUND *,
1031                 void (*csoundMessageCallback)(CSOUND *,
1032                                               int attr, const char *format,
1033                                               va_list valist));
1034     /**@}*/
1035     /** @name Event and MIDI functionality for opcodes */
1036     /**@{ */
1037     int (*SetReleaseLength)(void *p, int n);
1038     MYFLT (*SetReleaseLengthSeconds)(void *p, MYFLT n);
1039     int (*GetMidiChannelNumber)(void *p);
1040     MCHNBLK *(*GetMidiChannel)(void *p);
1041     int (*GetMidiNoteNumber)(void *p);
1042     int (*GetMidiVelocity)(void *p);
1043     int (*GetReleaseFlag)(void *p);
1044     double (*GetOffTime)(void *p);
1045     MYFLT *(*GetPFields)(void *p);
1046     int (*GetInstrumentNumber)(void *p);
1047     int (*GetZakBounds)(CSOUND *, MYFLT **);
1048     int (*GetTieFlag)(CSOUND *);
1049     int (*GetReinitFlag)(CSOUND *);
1050     /** Current maximum number of strings, accessible through the strset
1051         and strget opcodes */
1052     int (*GetStrsmax)(CSOUND *);
1053     char *(*GetStrsets)(CSOUND *, long);
1054     /* Fast power of two function from a precomputed table */
1055     MYFLT (*Pow2)(CSOUND *, MYFLT a);
1056     /* Fast power function for positive integers */
1057     MYFLT (*intpow)(MYFLT, int32);
1058     /* Returns a string name for the file type */
1059     char *(*type2string)(int type);
1060     /**@}*/
1061     /** @name Arguments to opcodes */
1062     /**@{ */
1063     CS_TYPE *(*GetTypeForArg)(void *p);
1064     int (*GetInputArgCnt)(void *p);
1065     char *(*GetInputArgName)(void *p, int n);
1066     int (*GetOutputArgCnt)(void *p);
1067     char *(*GetOutputArgName)(void *p, int n);
1068     char *(*GetString)(CSOUND *, MYFLT);
1069     int32 (*strarg2insno)(CSOUND *, void *p, int is_string);
1070     char *(*strarg2name)(CSOUND *, char *, void *, const char *, int);
1071 
1072     /**@}*/
1073     /** @name Memory allocation */
1074     /**@{ */
1075     void (*AuxAlloc)(CSOUND *, size_t nbytes, AUXCH *auxchp);
1076     void *(*Malloc)(CSOUND *, size_t nbytes);
1077     void *(*Calloc)(CSOUND *, size_t nbytes);
1078     void *(*ReAlloc)(CSOUND *, void *oldp, size_t nbytes);
1079     char *(*Strdup)(CSOUND *, char*);
1080     void (*Free)(CSOUND *, void *ptr);
1081 
1082     /**@}*/
1083     /** @name Function tables */
1084     /**@{ */
1085     int (*hfgens)(CSOUND *, FUNC **, const EVTBLK *, int);
1086     int (*FTAlloc)(CSOUND *, int tableNum, int len);
1087     int (*FTDelete)(CSOUND *, int tableNum);
1088     /** Find tables with power of two size. If table exists but is
1089         not a power of 2, NULL is returned. */
1090     FUNC *(*FTFind)(CSOUND *, MYFLT *argp);
1091     /** Find any table, except deferred load tables. */
1092     FUNC *(*FTFindP)(CSOUND *, MYFLT *argp);
1093     /** Find any table. */
1094     FUNC *(*FTnp2Find)(CSOUND *, MYFLT *argp);
1095     int (*GetTable)(CSOUND *, MYFLT **tablePtr, int tableNum);
1096     int (*TableLength)(CSOUND *, int table);
1097     MYFLT (*TableGet)(CSOUND *, int table, int index);
1098     void (*TableSet)(CSOUND *, int table, int index, MYFLT value);
1099     void *(*GetNamedGens)(CSOUND *);
1100 
1101     /**@}*/
1102     /** @name Global and config variable manipulation */
1103     /**@{ */
1104     int (*CreateGlobalVariable)(CSOUND *, const char *name, size_t nbytes);
1105     void *(*QueryGlobalVariable)(CSOUND *, const char *name);
1106     void *(*QueryGlobalVariableNoCheck)(CSOUND *, const char *name);
1107     int (*DestroyGlobalVariable)(CSOUND *, const char *name);
1108     int (*CreateConfigurationVariable)(CSOUND *, const char *name,
1109                                        void *p, int type, int flags,
1110                                        void *min, void *max,
1111                                        const char *shortDesc,
1112                                        const char *longDesc);
1113     int (*SetConfigurationVariable)(CSOUND *, const char *name, void *value);
1114     int (*ParseConfigurationVariable)(CSOUND *,
1115                                       const char *name, const char *value);
1116     csCfgVariable_t *(*QueryConfigurationVariable)(CSOUND *, const char *name);
1117     csCfgVariable_t **(*ListConfigurationVariables)(CSOUND *);
1118     int (*DeleteConfigurationVariable)(CSOUND *, const char *name);
1119     const char *(*CfgErrorCodeToString)(int errcode);
1120 
1121     /**@}*/
1122     /** @name FFT support */
1123     /**@{ */
1124     MYFLT (*GetInverseComplexFFTScale)(CSOUND *, int FFTsize);
1125     MYFLT (*GetInverseRealFFTScale)(CSOUND *, int FFTsize);
1126     void (*ComplexFFT)(CSOUND *, MYFLT *buf, int FFTsize);
1127     void (*InverseComplexFFT)(CSOUND *, MYFLT *buf, int FFTsize);
1128     void (*RealFFT)(CSOUND *, MYFLT *buf, int FFTsize);
1129     void (*InverseRealFFT)(CSOUND *, MYFLT *buf, int FFTsize);
1130     void (*RealFFTMult)(CSOUND *, MYFLT *outbuf, MYFLT *buf1, MYFLT *buf2,
1131                                   int FFTsize, MYFLT scaleFac);
1132     void (*RealFFTnp2)(CSOUND *, MYFLT *buf, int FFTsize);
1133     void (*InverseRealFFTnp2)(CSOUND *, MYFLT *buf, int FFTsize);
1134 
1135     /**@}*/
1136     /** @name PVOC-EX system */
1137     /**@{ */
1138     int (*PVOC_CreateFile)(CSOUND *, const char *,
1139                            uint32, uint32, uint32,
1140                            uint32, int32, int, int,
1141                            float, float *, uint32);
1142     int (*PVOC_OpenFile)(CSOUND *, const char *, void  *, void *);
1143     int (*PVOC_CloseFile)(CSOUND *, int);
1144     int (*PVOC_PutFrames)(CSOUND *, int, const float *, int32);
1145     int (*PVOC_GetFrames)(CSOUND *, int, float *, uint32);
1146     int (*PVOC_FrameCount)(CSOUND *, int);
1147     int (*PVOC_fseek)(CSOUND *, int, int);
1148     const char *(*PVOC_ErrorString)(CSOUND *);
1149     int (*PVOCEX_LoadFile)(CSOUND *, const char *, PVOCEX_MEMFILE *);
1150 
1151     /**@}*/
1152     /** @name Error messages */
1153     /**@{ */
1154     CS_NORETURN CS_PRINTF2 void (*Die)(CSOUND *, const char *msg, ...);
1155     CS_PRINTF2 int (*InitError)(CSOUND *, const char *msg, ...);
1156     CS_PRINTF3 int (*PerfError)(CSOUND *, INSDS *ip,  const char *msg, ...);
1157     CS_PRINTF2 void (*Warning)(CSOUND *, const char *msg, ...);
1158     CS_PRINTF2 void (*DebugMsg)(CSOUND *, const char *msg, ...);
1159     CS_NORETURN void (*LongJmp)(CSOUND *, int);
1160     CS_PRINTF2 void (*ErrorMsg)(CSOUND *, const char *fmt, ...);
1161     void (*ErrMsgV)(CSOUND *, const char *hdr, const char *fmt, va_list);
1162 
1163     /**@}*/
1164     /** @name Random numbers */
1165     /**@{ */
1166     uint32_t (*GetRandomSeedFromTime)(void);
1167     void (*SeedRandMT)(CsoundRandMTState *p,
1168                        const uint32_t *initKey, uint32_t keyLength);
1169     uint32_t (*RandMT)(CsoundRandMTState *p);
1170     int (*Rand31)(int *seedVal);
1171     int (*GetRandSeed)(CSOUND *, int which);
1172 
1173     /**@}*/
1174     /** @name Threads and locks */
1175     /**@{ */
1176     void *(*CreateThread)(uintptr_t (*threadRoutine)(void *), void *userdata);
1177     uintptr_t (*JoinThread)(void *thread);
1178     void *(*CreateThreadLock)(void);
1179     void (*DestroyThreadLock)(void *lock);
1180     int (*WaitThreadLock)(void *lock, size_t milliseconds);
1181     void (*NotifyThreadLock)(void *lock);
1182     void (*WaitThreadLockNoTimeout)(void *lock);
1183     void *(*Create_Mutex)(int isRecursive);
1184     int (*LockMutexNoWait)(void *mutex_);
1185     void (*LockMutex)(void *mutex_);
1186     void (*UnlockMutex)(void *mutex_);
1187     void (*DestroyMutex)(void *mutex_);
1188     void *(*CreateBarrier)(unsigned int max);
1189     int (*DestroyBarrier)(void *);
1190     int (*WaitBarrier)(void *);
1191     void *(*GetCurrentThreadID)(void);
1192     void (*Sleep)(size_t milliseconds);
1193     void (*InitTimerStruct)(RTCLOCK *);
1194     double (*GetRealTime)(RTCLOCK *);
1195     double (*GetCPUTime)(RTCLOCK *);
1196 
1197     /**@}*/
1198     /** @name Circular lock-free buffer */
1199     /**@{ */
1200     void *(*CreateCircularBuffer)(CSOUND *, int, int);
1201     int (*ReadCircularBuffer)(CSOUND *, void *, void *, int);
1202     int (*WriteCircularBuffer)(CSOUND *, void *, const void *, int);
1203     void (*FlushCircularBuffer)(CSOUND *, void *);
1204     void (*DestroyCircularBuffer)(CSOUND *, void *);
1205 
1206     /**@}*/
1207     /** @name File access */
1208     /**@{ */
1209     char *(*FindInputFile)(CSOUND *, const char *filename, const char *envList);
1210     char *(*FindOutputFile)(CSOUND *,
1211                             const char *filename, const char *envList);
1212     void *(*SAsndgetset)(CSOUND *,
1213                          char *, void *, MYFLT *, MYFLT *, MYFLT *, int);
1214     void *(*sndgetset)(CSOUND *, void *);
1215     int (*getsndin)(CSOUND *, void *, MYFLT *, int, void *);
1216     void (*rewriteheader)(void *ofd);
1217     SNDMEMFILE *(*LoadSoundFile)(CSOUND *, const char *, void *);
1218     void (*FDRecord)(CSOUND *, FDCH *fdchp);
1219     void (*FDClose)(CSOUND *, FDCH *fdchp);
1220     void *(*CreateFileHandle)(CSOUND *, void *, int, const char *);
1221     char *(*GetFileName)(void *);
1222     int (*FileClose)(CSOUND *, void *);
1223     void *(*FileOpen2)(CSOUND *, void *, int, const char *, void *,
1224                       const char *, int, int);
1225     int (*type2csfiletype)(int type, int encoding);
1226     void (*NotifyFileOpened)(CSOUND*, const char*, int, int, int);
1227     int (*sftype2csfiletype)(int type);
1228     MEMFIL *(*ldmemfile2withCB)(CSOUND *, const char *, int,
1229                                 int (*callback)(CSOUND *, MEMFIL *));
1230     void *(*FileOpenAsync)(CSOUND *, void *, int, const char *, void *,
1231                            const char *, int, int, int);
1232     unsigned int (*ReadAsync)(CSOUND *, void *, MYFLT *, int);
1233     unsigned int (*WriteAsync)(CSOUND *, void *, MYFLT *, int);
1234     int  (*FSeekAsync)(CSOUND *, void *, int, int);
1235     char *(*getstrformat)(int format);
1236     int (*sfsampsize)(int format);
1237 
1238     /**@}*/
1239     /** @name RT audio IO and callbacks */
1240     /**@{ */
1241     void (*SetPlayopenCallback)(CSOUND *,
1242                 int (*playopen__)(CSOUND *, const csRtAudioParams *parm));
1243     void (*SetRtplayCallback)(CSOUND *,
1244                 void (*rtplay__)(CSOUND *, const MYFLT *outBuf, int nbytes));
1245     void (*SetRecopenCallback)(CSOUND *,
1246                 int (*recopen__)(CSOUND *, const csRtAudioParams *parm));
1247     void (*SetRtrecordCallback)(CSOUND *,
1248                 int (*rtrecord__)(CSOUND *, MYFLT *inBuf, int nbytes));
1249     void (*SetRtcloseCallback)(CSOUND *, void (*rtclose__)(CSOUND *));
1250     void (*SetAudioDeviceListCallback)(CSOUND *csound,
1251           int (*audiodevlist__)(CSOUND *, CS_AUDIODEVICE *list, int isOutput));
1252     void **(*GetRtRecordUserData)(CSOUND *);
1253     void **(*GetRtPlayUserData)(CSOUND *);
1254     int (*GetDitherMode)(CSOUND *);
1255     /**@}*/
1256     /** @name RT MIDI and callbacks */
1257     /**@{ */
1258     void (*SetExternalMidiInOpenCallback)(CSOUND *,
1259                 int (*func)(CSOUND *, void **, const char *));
1260     void (*SetExternalMidiReadCallback)(CSOUND *,
1261                 int (*func)(CSOUND *, void *, unsigned char *, int));
1262     void (*SetExternalMidiInCloseCallback)(CSOUND *,
1263                 int (*func)(CSOUND *, void *));
1264     void (*SetExternalMidiOutOpenCallback)(CSOUND *,
1265                 int (*func)(CSOUND *, void **, const char *));
1266     void (*SetExternalMidiWriteCallback)(CSOUND *,
1267                 int (*func)(CSOUND *, void *, const unsigned char *, int));
1268     void (*SetExternalMidiOutCloseCallback)(CSOUND *,
1269                 int (*func)(CSOUND *, void *));
1270     void (*SetExternalMidiErrorStringCallback)(CSOUND *,
1271                 const char *(*func)(int));
1272     void (*SetMIDIDeviceListCallback)(CSOUND *csound,
1273           int (*audiodevlist__)(CSOUND *, CS_MIDIDEVICE *list, int isOutput));
1274     void (*module_list_add)(CSOUND *, char *, char *);
1275     /**@}*/
1276     /** @name Displays & graphs */
1277     /**@{ */
1278     void (*dispset)(CSOUND *, WINDAT *, MYFLT *, int32, char *, int, char *);
1279     void (*display)(CSOUND *, WINDAT *);
1280     int (*dispexit)(CSOUND *);
1281     void (*dispinit)(CSOUND *);
1282     int (*SetIsGraphable)(CSOUND *, int isGraphable);
1283     void (*SetMakeGraphCallback)(CSOUND *,
1284                 void (*makeGraphCallback)(CSOUND *, WINDAT *p,
1285                                                     const char *name));
1286     void (*SetDrawGraphCallback)(CSOUND *,
1287                 void (*drawGraphCallback)(CSOUND *, WINDAT *p));
1288     void (*SetKillGraphCallback)(CSOUND *,
1289                 void (*killGraphCallback)(CSOUND *, WINDAT *p));
1290     void (*SetExitGraphCallback)(CSOUND *, int (*exitGraphCallback)(CSOUND *));
1291     /**@}*/
1292     /** @name Generic callbacks */
1293     /**@{ */
1294     void (*SetYieldCallback)(CSOUND *, int (*yieldCallback)(CSOUND *));
1295     int (*Set_KeyCallback)(CSOUND *, int (*func)(void *, void *, unsigned int),
1296                         void *userData, unsigned int typeMask);
1297     void (*Remove_KeyCallback)(CSOUND *,
1298                             int (*func)(void *, void *, unsigned int));
1299     int (*RegisterSenseEventCallback)(CSOUND *, void (*func)(CSOUND *, void *),
1300                                                 void *userData);
1301     int (*RegisterDeinitCallback)(CSOUND *, void *p,
1302                                             int (*func)(CSOUND *, void *));
1303     int (*RegisterResetCallback)(CSOUND *, void *userData,
1304                                            int (*func)(CSOUND *, void *));
1305     void (*SetInternalYieldCallback)(CSOUND *,
1306                        int (*yieldCallback)(CSOUND *));
1307     /**@}*/
1308     /** @name Opcodes and instruments */
1309     /**@{ */
1310     int (*AppendOpcode)(CSOUND *, const char *opname, int dsblksiz, int flags,
1311                         int thread, const char *outypes, const char *intypes,
1312                         int (*iopadr)(CSOUND *, void *),
1313                         int (*kopadr)(CSOUND *, void *),
1314                         int (*aopadr)(CSOUND *, void *));
1315     int (*AppendOpcodes)(CSOUND *, const OENTRY *opcodeList, int n);
1316     char *(*GetOpcodeName)(void *p);
1317     INSTRTXT **(*GetInstrumentList)(CSOUND *);
1318     /**@}*/
1319     /** @name Events and performance */
1320     /**@{ */
1321     int (*CheckEvents)(CSOUND *);
1322     int (*insert_score_event)(CSOUND *, EVTBLK *, double);
1323     int (*insert_score_event_at_sample)(CSOUND *, EVTBLK *, int64_t);
1324     int (*PerformKsmps)(CSOUND *);
1325     /**@}*/
1326     /** @name Utilities */
1327     /**@{ */
1328     int (*AddUtility)(CSOUND *, const char *name,
1329                       int (*UtilFunc)(CSOUND *, int, char **));
1330     int (*RunUtility)(CSOUND *, const char *name, int argc, char **argv);
1331     char **(*ListUtilities)(CSOUND *);
1332     int (*SetUtilityDescription)(CSOUND *, const char *utilName,
1333                                            const char *utilDesc);
1334     const char *(*GetUtilityDescription)(CSOUND *, const char *utilName);
1335     void (*SetUtilSr)(CSOUND *, MYFLT);
1336     void (*SetUtilNchnls)(CSOUND *, int);
1337     /**@}*/
1338     /** @name Miscellaneous */
1339     /**@{ */
1340     long (*RunCommand)(const char * const *argv, int noWait);
1341     int (*OpenLibrary)(void **library, const char *libraryPath);
1342     int (*CloseLibrary)(void *library);
1343     void *(*GetLibrarySymbol)(void *library, const char *procedureName);
1344 #if defined (__CUDACC__) || defined (__MACH__)
1345     char *(*LocalizeString)(const char *);
1346 #else
1347     char *(*LocalizeString)(const char *) __attribute__ ((format_arg (1)));
1348 #endif
1349     char *(*strtok_r)(char*, char*, char**);
1350     double (*strtod)(char*, char**);
1351     int (*sprintf)(char *str, const char *format, ...);
1352     int (*sscanf)(char *str, const char *format, ...);
1353     MYFLT (*system_sr)(CSOUND *, MYFLT );
1354     /**@}*/
1355     /** @name Score Event s*/
1356     /**@{ */
1357     MYFLT (*GetScoreOffsetSeconds)(CSOUND *);
1358     void (*SetScoreOffsetSeconds)(CSOUND *, MYFLT offset);
1359     void (*RewindScore)(CSOUND *);
1360     void (*InputMessage)(CSOUND *, const char *message__);
1361     int  (*ISSTRCOD)(MYFLT);
1362     void *(*RealFFT2Setup)(CSOUND *csound,
1363                            int FFTsize,
1364                            int d);
1365     void (*RealFFT2)(CSOUND *csound,
1366                      void *p, MYFLT *sig);
1367     int  (*ftError)(const FGDATA *, const char *, ...);
1368     MYFLT (*GetA4)(CSOUND *csound);
1369     int (*AuxAllocAsync)(CSOUND *, size_t, AUXCH  *,
1370                          AUXASYNC *, aux_cb, void *);
1371     void *(*GetHostData)(CSOUND *);
1372     char *(*strNcpy)(char *dst, const char *src, size_t siz);
1373        /**@}*/
1374     /** @name Placeholders
1375         To allow the API to grow while maintining backward binary compatibility. */
1376     /**@{ */
1377     SUBR dummyfn_2[37];
1378     /**@}*/
1379 #ifdef __BUILDING_LIBCSOUND
1380     /* ------- private data (not to be used by hosts or externals) ------- */
1381     /** @name Private Data
1382       Private Data in the CSOUND struct to be used internally by the Csound
1383       library and should be hidden from plugins.
1384       If a new variable member is needed by the library, add it below, as a
1385       private data member. If access is required solely by plugins (and not
1386       internally by the library), use the CreateGlobalVariable() etc. interface,
1387       instead of adding to CSOUND.
1388 
1389       If you find that a plugin needs to access existing private data,
1390       first check above for an existing interface; if none is available,
1391       add one. Please avoid giving full access, or allowing plugins to
1392       change the values of private members, by using one of the two methods
1393       below:
1394 
1395       1) To get the data member value:
1396       \code
1397          returnType (*GetVar)(CSOUND *)
1398       \endcode
1399       2) in case of pointers, data should be copied out to a supplied memory
1400          slot, rather than the pointer being obtained:
1401       \code
1402          void (*GetData)(CSOUND *, dataType *)
1403 
1404          dataType var;
1405          csound->GetData(csound, &var);
1406       \endcode
1407     */
1408     /**@{ */
1409     SUBR          first_callback_;
1410     channelCallback_t InputChannelCallback_;
1411     channelCallback_t OutputChannelCallback_;
1412     void          (*csoundMessageCallback_)(CSOUND *, int attr,
1413                                             const char *format, va_list args);
1414     int           (*csoundConfigureCallback_)(CSOUND *);
1415     void          (*csoundMakeGraphCallback_)(CSOUND *, WINDAT *windat,
1416                                                         const char *name);
1417     void          (*csoundDrawGraphCallback_)(CSOUND *, WINDAT *windat);
1418     void          (*csoundKillGraphCallback_)(CSOUND *, WINDAT *windat);
1419     int           (*csoundExitGraphCallback_)(CSOUND *);
1420     int           (*csoundYieldCallback_)(CSOUND *);
1421     void          (*cscoreCallback_)(CSOUND *);
1422     void          (*FileOpenCallback_)(CSOUND*, const char*, int, int, int);
1423     SUBR          last_callback_;
1424     /* these are not saved on RESET */
1425     int           (*playopen_callback)(CSOUND *, const csRtAudioParams *parm);
1426     void          (*rtplay_callback)(CSOUND *, const MYFLT *outBuf, int nbytes);
1427     int           (*recopen_callback)(CSOUND *, const csRtAudioParams *parm);
1428     int           (*rtrecord_callback)(CSOUND *, MYFLT *inBuf, int nbytes);
1429     void          (*rtclose_callback)(CSOUND *);
1430     int           (*audio_dev_list_callback)(CSOUND *, CS_AUDIODEVICE *, int);
1431     int           (*midi_dev_list_callback)(CSOUND *, CS_MIDIDEVICE *, int);
1432     int           (*doCsoundCallback)(CSOUND *, void *, unsigned int);
1433     int           (*csoundInternalYieldCallback_)(CSOUND *);
1434     /* end of callbacks */
1435     void          (*spinrecv)(CSOUND *);
1436     void          (*spoutran)(CSOUND *);
1437     int           (*audrecv)(CSOUND *, MYFLT *, int);
1438     void          (*audtran)(CSOUND *, const MYFLT *, int);
1439     void          *hostdata;
1440     char          *orchname, *scorename;
1441     CORFIL        *orchstr, *scorestr;
1442     OPDS          *ids;             /* used by init loops */
1443     ENGINE_STATE  engineState;      /* current Engine State merged after
1444                                        compilation */
1445     INSTRTXT      *instr0;          /* instr0     */
1446     INSTRTXT      **dead_instr_pool;
1447     int           dead_instr_no;
1448     TYPE_POOL*    typePool;
1449     unsigned int  ksmps;
1450     uint32_t      nchnls;
1451     int           inchnls;
1452     int           spoutactive;
1453     uint64_t      kcounter, global_kcounter;
1454     MYFLT         esr;
1455     MYFLT         ekr;
1456     /** current time in seconds, inc. per kprd */
1457     int64_t       icurTime;   /* Current time in samples */
1458     double        curTime_inc;
1459     /** start time of current section    */
1460     double        timeOffs, beatOffs;
1461     /** current time in beats, inc per kprd */
1462     double        curBeat, curBeat_inc;
1463     /** beat time = 60 / tempo           */
1464     int64_t       ibeatTime;   /* Beat time in samples */
1465     EVTBLK        *currevent;
1466     INSDS         *curip;
1467     MYFLT         cpu_power_busy;
1468     char          *xfilename;
1469     int           peakchunks;
1470     int           keep_tmp;
1471     CS_HASH_TABLE *opcodes;
1472     int32         nrecs;
1473     FILE*         Linepipe;
1474     int           Linefd;
1475     void          *csoundCallbacks_;
1476     FILE*         scfp;
1477     CORFIL        *scstr;
1478     FILE*         oscfp;
1479     MYFLT         maxamp[MAXCHNLS];
1480     MYFLT         smaxamp[MAXCHNLS];
1481     MYFLT         omaxamp[MAXCHNLS];
1482     uint32        maxpos[MAXCHNLS], smaxpos[MAXCHNLS], omaxpos[MAXCHNLS];
1483     FILE*         scorein;
1484     FILE*         scoreout;
1485     int           *argoffspace;
1486     INSDS         *frstoff;
1487     MYFLT         *zkstart;
1488     int64_t          zklast;
1489     MYFLT         *zastart;
1490     int64_t          zalast;
1491     /** reserved for std opcode library  */
1492     void          *stdOp_Env;
1493     int           holdrand;
1494     int           randSeed1;
1495     int           randSeed2;
1496     CsoundRandMTState *csRandState;
1497     RTCLOCK       *csRtClock;
1498     int           strsmax;
1499     char          **strsets;
1500     MYFLT         *spin;
1501     MYFLT         *spout;
1502     MYFLT         *spraw;
1503     int           nspin;
1504     int           nspout;
1505     MYFLT         *auxspin;
1506     OPARMS        *oparms;
1507     /** reserve space for up to 4 MIDI devices */
1508     MCHNBLK       *m_chnbp[64];
1509     int           dither_output;
1510     MYFLT         onedsr, sicvt;
1511     MYFLT         tpidsr, pidsr, mpidsr, mtpdsr;
1512     MYFLT         onedksmps;
1513     MYFLT         onedkr;
1514     MYFLT         kicvt;
1515     int           reinitflag;
1516     int           tieflag;
1517     MYFLT         e0dbfs, dbfs_to_float;
1518     double        A4;
1519     void          *rtRecord_userdata;
1520     void          *rtPlay_userdata;
1521     jmp_buf       exitjmp;
1522     SRTBLK        *frstbp;
1523     int           sectcnt;
1524     int           inerrcnt, synterrcnt, perferrcnt;
1525     INSDS         actanchor;
1526     int32         rngcnt[MAXCHNLS];
1527     int16         rngflg, multichan;
1528     void          *evtFuncChain;
1529     EVTNODE       *OrcTrigEvts;             /* List of events to be started */
1530     EVTNODE       *freeEvtNodes;
1531     int           csoundIsScorePending_;
1532     int64_t       advanceCnt;
1533     int           initonly;
1534     int           evt_poll_cnt;
1535     int           evt_poll_maxcnt;
1536     int           Mforcdecs, Mxtroffs, MTrkend;
1537     OPCODINFO     *opcodeInfo;
1538     FUNC**        flist;
1539     int           maxfnum;
1540     GEN           *gensub;
1541     int           genmax;
1542     CS_HASH_TABLE *namedGlobals;
1543     CS_HASH_TABLE *cfgVariableDB;
1544     double        prvbt, curbt, nxtbt;
1545     double        curp2, nxtim;
1546     int64_t       cyclesRemaining;
1547     EVTBLK        evt;
1548     void          *memalloc_db;
1549     MGLOBAL       *midiGlobals;
1550     CS_HASH_TABLE *envVarDB;
1551     MEMFIL        *memfiles;
1552     PVOCEX_MEMFILE *pvx_memfiles;
1553     int           FFT_max_size;
1554     void          *FFT_table_1;
1555     void          *FFT_table_2;
1556     /* statics from twarp.c should be TSEG* */
1557     void          *tseg, *tpsave, *tplim;
1558     /* Statics from express.c */
1559     MYFLT         *gbloffbas;       /* was static in oload.c */
1560     void         *file_io_thread;
1561     int          file_io_start;
1562     void         *file_io_threadlock;
1563     int          realtime_audio_flag;
1564     void         *event_insert_thread;
1565     int          event_insert_loop;
1566     void         *init_pass_threadlock;
1567     void         *API_lock;
1568     spin_lock_t spoutlock, spinlock;
1569     spin_lock_t memlock, spinlock1;
1570     char          *delayederrormessages;
1571     void          *printerrormessagesflag;
1572     struct sreadStatics__ {
1573       SRTBLK  *bp, *prvibp;           /* current srtblk,  prev w/same int(p1) */
1574       char    *sp, *nxp;              /* string pntrs into srtblk text        */
1575       int     op;                     /* opcode of current event              */
1576       int     warpin;                 /* input format sensor                  */
1577       int     linpos;                 /* line position sensor                 */
1578       int     lincnt;                 /* count of lines/section in scorefile  */
1579       MYFLT   prvp2 /* = -FL(1.0) */;     /* Last event time                  */
1580       MYFLT   clock_base /* = FL(0.0) */;
1581       MYFLT   warp_factor /* = FL(1.0) */;
1582       char    *curmem;
1583       char    *memend;                /* end of cur memblk                    */
1584       S_MACRO   *macros;
1585       int     last_name /* = -1 */;
1586       IN_STACK  *inputs, *str;
1587       int     input_size, input_cnt;
1588       int     pop;                    /* Number of macros to pop              */
1589       int     ingappop /* = 1 */;     /* Are we in a popable gap?             */
1590       int     linepos /* = -1 */;
1591       MARKED_SECTIONS names[30];
1592 #define NAMELEN 40              /* array size of repeat macro names */
1593 #define RPTDEPTH 40             /* size of repeat_n arrays (39 loop levels) */
1594       char    repeat_name_n[RPTDEPTH][NAMELEN];
1595       int     repeat_cnt_n[RPTDEPTH];
1596       int32   repeat_point_n[RPTDEPTH];
1597       int     repeat_inc_n /* = 1 */;
1598       S_MACRO   *repeat_mm_n[RPTDEPTH];
1599       int     repeat_index;
1600      /* Variable for repeat sections */
1601       char    repeat_name[NAMELEN];
1602       int     repeat_cnt;
1603       int32   repeat_point;
1604       int     repeat_inc /* = 1 */;
1605       S_MACRO   *repeat_mm;
1606       int     nocarry;
1607     } sreadStatics;
1608     struct onefileStatics__ {
1609       NAMELST *toremove;
1610       char    *orcname;
1611       char    *sconame;
1612       char    *midname;
1613       int     midiSet;
1614       int     csdlinecount;
1615     } onefileStatics;
1616 #define LBUFSIZ   32768
1617     struct lineventStatics__ {
1618       char    *Linep, *Linebufend;
1619       int     stdmode;
1620       EVTBLK  prve;
1621       char    *Linebuf;
1622       int     linebufsiz;
1623       char *orchestra, *orchestrab;
1624       int   oflag;
1625     } lineventStatics;
1626     struct musmonStatics__ {
1627       int32   srngcnt[MAXCHNLS], orngcnt[MAXCHNLS];
1628       int16   srngflg;
1629       int16   sectno;
1630       int     lplayed;
1631       int     segamps, sormsg;
1632       EVENT   **ep, **epend;      /* pointers for stepping through lplay list */
1633       EVENT   *lsect;
1634     } musmonStatics;
1635     struct libsndStatics__ {
1636       SNDFILE       *outfile;
1637       SNDFILE       *infile;
1638       char          *sfoutname;           /* soundout filename            */
1639       MYFLT         *inbuf;
1640       MYFLT         *outbuf;              /* contin sndio buffers         */
1641       MYFLT         *outbufp;             /* MYFLT pntr                   */
1642       uint32        inbufrem;
1643       uint32        outbufrem;            /* in monosamps                 */
1644                                           /* (see openin, iotranset)      */
1645       unsigned int  inbufsiz,  outbufsiz; /* alloc in sfopenin/out        */
1646       int           isfopen;              /* (real set in sfopenin)       */
1647       int           osfopen;              /* (real set in sfopenout)      */
1648       int           pipdevin, pipdevout;  /* 0: file, 1: pipe, 2: rtaudio */
1649       uint32        nframes               /* = 1UL */;
1650       FILE          *pin, *pout;
1651       int           dither;
1652     } libsndStatics;
1653 
1654     int           warped;               /* rdscor.c */
1655     int           sstrlen;
1656     char          *sstrbuf;
1657     int           enableMsgAttr;        /* csound.c */
1658     int           sampsNeeded;
1659     MYFLT         csoundScoreOffsetSeconds_;
1660     int           inChar_;
1661     int           isGraphable_;
1662     int           delayr_stack_depth;   /* ugens6.c */
1663     void          *first_delayr;
1664     void          *last_delayr;
1665     int32         revlpsiz[6];
1666     int32         revlpsum;
1667     double        rndfrac;              /* aops.c */
1668     MYFLT         *logbase2;
1669     NAMES         *omacros, *smacros;
1670     void          *namedgen;            /* fgens.c */
1671     void          *open_files;          /* fileopen.c */
1672     void          *searchPathCache;
1673     CS_HASH_TABLE *sndmemfiles;
1674     void          *reset_list;
1675     void          *pvFileTable;         /* pvfileio.c */
1676     int           pvNumFiles;
1677     int           pvErrorCode;
1678     /* database for deferred loading of opcode plugin libraries */
1679     //    void          *pluginOpcodeFiles;
1680     int           enableHostImplementedAudioIO;
1681     int           enableHostImplementedMIDIIO;
1682     int           hostRequestedBufferSize;
1683     /* engineStatus is sum of:
1684      *   1 (CS_STATE_PRE):  csoundPreCompile was called
1685      *   2 (CS_STATE_COMP): csoundCompile was called
1686      *   4 (CS_STATE_UTIL): csoundRunUtility was called
1687      *   8 (CS_STATE_CLN):  csoundCleanup needs to be called
1688      *  16 (CS_STATE_JMP):  csoundLongJmp was called
1689      */
1690     char          engineStatus;
1691     /* stdXX_assign_flags  can be {1,2,4,8} */
1692     char          stdin_assign_flg;
1693     char          stdout_assign_flg;
1694     char          orcname_mode;         /* 0: normal, 1: ignore, 2: fail */
1695     int           use_only_orchfile;
1696     void          *csmodule_db;
1697     char          *dl_opcodes_oplibs;
1698     char          *SF_csd_licence;
1699     char          *SF_id_title;
1700     char          *SF_id_copyright;
1701     int           SF_id_scopyright;
1702     char          *SF_id_software;
1703     char          *SF_id_artist;
1704     char          *SF_id_comment;
1705     char          *SF_id_date;
1706     void          *utility_db;
1707     int16         *isintab;             /* ugens3.c */
1708     void          *lprdaddr;            /* ugens5.c */
1709     int           currentLPCSlot;
1710     int           max_lpc_slot;
1711     CS_HASH_TABLE *chn_db;
1712     int           opcodedirWasOK;
1713     int           disable_csd_options;
1714     CsoundRandMTState randState_;
1715     int           performState;
1716     int           ugens4_rand_16;
1717     int           ugens4_rand_15;
1718     void          *schedule_kicked;
1719     MYFLT         *disprep_fftcoefs;
1720     void          *winEPS_globals;
1721     OPARMS        oparms_;
1722     REMOT_BUF     SVrecvbuf;  /* RM: rt_evt input Communications buffer */
1723     void          *remoteGlobals;
1724     /* VL: pvs bus */
1725     int            nchanif, nchanof;
1726     char           *chanif, *chanof;
1727     /* VL: internal yield callback */
1728     int           multiThreadedComplete;
1729     THREADINFO    *multiThreadedThreadInfo;
1730     struct dag_t        *multiThreadedDag;
1731     void          *barrier1;
1732     void          *barrier2;
1733     /* Statics from cs_par_dispatch; */
1734     /* ********These are no longer used******** */
1735     void          *pointer1; //struct global_var_lock_t *global_var_lock_root;
1736     void          *pointer2; //struct global_var_lock_t **global_var_lock_cache;
1737     int           int1; //global_var_lock_count;
1738     /* statics from cs_par_orc_semantic_analysis */
1739     struct instr_semantics_t *instCurr;
1740     struct instr_semantics_t *instRoot;
1741     int           inInstr;
1742     int           dag_changed;
1743     int           dag_num_active;
1744     INSDS         **dag_task_map;
1745     volatile stateWithPadding    *dag_task_status;
1746     watchList     * volatile *dag_task_watch;
1747     watchList     *dag_wlmm;
1748     char          **dag_task_dep;
1749     int           dag_task_max_size;
1750     uint32_t      tempStatus;    /* keeps track of which files are temps */
1751     int           orcLineOffset; /* 1 less than 1st orch line in the CSD */
1752     int           scoLineOffset; /* 1 less than 1st score line in the CSD */
1753     char*         csdname;
1754   /* original CSD name; do not free() */
1755     int           parserUdoflag;
1756     int           parserNamedInstrFlag;
1757     int           tran_nchnlsi;
1758     int           scnt;         /* Count of strings */
1759     int           strsiz;       /* length of current strings space */
1760     FUNC          *sinetable;   /* A useful table */
1761     int           sinelength;   /* Size of table */
1762     MYFLT         *powerof2;    /* pow2 table */
1763     MYFLT         *cpsocfrc;    /* cps conv table */
1764     CORFIL*       expanded_orc; /* output of preprocessor */
1765     CORFIL*       expanded_sco; /* output of preprocessor */
1766     char          *filedir[256];/* for location directory */
1767     void          *message_buffer;
1768     int           jumpset;
1769     int           info_message_request;
1770     int           modules_loaded;
1771     MYFLT         _system_sr;
1772     void*         csdebug_data; /* debugger data */
1773     int (*kperf)(CSOUND *); /* kperf function pointer, to switch between debug
1774                                and nodebug function */
1775     int           score_parser;
1776     CS_HASH_TABLE* symbtab;
1777     int           tseglen;
1778     int           inZero;       /* flag compilation of instr0 */
1779     struct _message_queue **msg_queue;
1780     volatile long msg_queue_wget; /* Writer - Get index */
1781     volatile long msg_queue_wput; /* Writer - Put Index */
1782     volatile long msg_queue_rstart; /* Reader - start index */
1783     volatile long msg_queue_items;
1784     int      aftouch;
1785     void     *directory;
1786     ALLOC_DATA *alloc_queue;
1787     volatile unsigned long alloc_queue_items;
1788     unsigned long alloc_queue_wp;
1789     spin_lock_t alloc_spinlock;
1790     EVTBLK *init_event;
1791     void (*csoundMessageStringCallback)(CSOUND *csound,
1792                                         int attr,
1793                                         const char *str);
1794     char* message_string;
1795     volatile unsigned long message_string_queue_items;
1796     unsigned long message_string_queue_wp;
1797     message_string_queue_t *message_string_queue;
1798     /*struct CSOUND_ **self;*/
1799     /**@}*/
1800 #endif  /* __BUILDING_LIBCSOUND */
1801   };
1802 
1803 /*
1804  * Move the C++ guards to enclose the entire file,
1805  * in order to enable C++ to #include this file.
1806  */
1807 
1808 #define LINKAGE_BUILTIN(name)                                         \
1809 long name##_init(CSOUND *csound, OENTRY **ep)                         \
1810 {   (void) csound; *ep = name; return (long) (sizeof(name));  }
1811 
1812 #define FLINKAGE_BUILTIN(name)                                        \
1813 NGFENS* name##_init(CSOUND *csound)                                   \
1814 {   (void) csound; return name; }
1815 
1816 #ifdef __cplusplus
1817 }
1818 #endif /* __cplusplus */
1819 
1820 #endif  /* CSOUNDCORE_H */
1821