1 /*
2     csound.hpp:
3 
4     Copyright (C) 2005 Istvan Varga, Michael Gogins
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     As a special exception, if other files instantiate templates or
24     use macros or inline functions from this file, this file does not
25     by itself cause the resulting executable or library to be covered
26     by the GNU Lesser General Public License. This exception does not
27     however invalidate any other reasons why the library or executable
28     file might be covered by the GNU Lesser General Public License.
29 */
30 
31 #ifndef __CSOUND_HPP__
32 #define __CSOUND_HPP__
33 
34 #ifdef SWIG
35 %module csnd6
36 %{
37 #include "csound.h"
38 %}
39 #else
40 #include "csound.h"
41 #if defined(HAVE_PTHREAD_SPIN_LOCK) && !defined(SWIG)
42 #include <pthread.h>
43 #endif
44 #ifdef __BUILDING_CSOUND_INTERFACES
45 #endif
46 #endif
47 
48 #ifdef SWIGPYTHON
49 #define MESSAGE_BUFFER_LENGTH 8192
50 struct PUBLIC pycbdata {
51   PyObject *mfunc,*invalfunc,*outvalfunc;
52   PyObject *midiinopenfunc, *midireadfunc, *midiinclosefunc;
53   PyObject *hostdata;
54   char messageBuffer[MESSAGE_BUFFER_LENGTH];
55   int messageBufferIndex;
56 };
57 #endif
58 
59 #if defined(__cplusplus)
60 
61 #if defined(HAVE_PTHREAD_SPIN_LOCK) && !defined(SWIG)
62 struct Spinlock
63 {
64     pthread_spinlock_t lock_;
SpinlockSpinlock65     Spinlock()
66     {
67         pthread_spin_init(&lock_, PTHREAD_PROCESS_PRIVATE);
68     }
~SpinlockSpinlock69     ~Spinlock()
70     {
71         pthread_spin_destroy(&lock_);
72     }
lockSpinlock73     void lock()
74     {
75         pthread_spin_lock(&lock_);
76     }
unlockSpinlock77     void unlock()
78     {
79         pthread_spin_unlock(&lock_);
80     }
81 };
82 
83 struct Spinlocker
84 {
85     Spinlock &spinlock;
SpinlockerSpinlocker86     Spinlocker(Spinlock &spinlock_) : spinlock(spinlock_)
87     {
88         spinlock.lock();
89     }
~SpinlockerSpinlocker90     ~Spinlocker()
91     {
92         spinlock.unlock();
93     }
94 };
95 #endif
96 
97 
98 /**
99  * C++ interface to the "C" Csound API.
100  */
101 class PUBLIC Csound
102 {
103 protected:
104   CSOUND *csound;
105 public:
106   void *pydata;
107 public:
GetCsound()108   virtual CSOUND *GetCsound()
109   {
110     return csound;
111   }
SetCsound(CSOUND * csound_)112   virtual void SetCsound(CSOUND *csound_)
113   {
114     csound = csound_;
115   }
InitializeCscore(FILE * insco,FILE * outsco)116   virtual int InitializeCscore(FILE *insco, FILE *outsco)
117   {
118     return csoundInitializeCscore(csound, insco, outsco);
119   }
GetVersion()120   virtual int GetVersion()
121   {
122     return csoundGetVersion();
123   }
GetAPIVersion()124   virtual int GetAPIVersion()
125   {
126     return csoundGetAPIVersion();
127   }
GetHostData()128   virtual void *GetHostData()
129   {
130     return csoundGetHostData(csound);
131   }
SetHostData(void * hostData)132   virtual void SetHostData(void *hostData)
133   {
134     csoundSetHostData(csound, hostData);
135   }
GetEnv(const char * name)136   virtual const char *GetEnv(const char *name)
137   {
138     return csoundGetEnv(csound, name);
139   }
SetGlobalEnv(const char * name,const char * value)140   virtual int SetGlobalEnv(const char *name,const char *value)
141   {
142     return csoundSetGlobalEnv(name, value);
143   }
SetOption(const char * option)144   virtual int SetOption(const char *option)
145   {
146    return csoundSetOption(csound, option);
147   }
SetParams(CSOUND_PARAMS * p)148   virtual void SetParams(CSOUND_PARAMS *p){
149    csoundSetParams(csound, p);
150   }
GetParams(CSOUND_PARAMS * p)151   virtual void GetParams(CSOUND_PARAMS *p){
152    csoundGetParams(csound, p);
153   }
SetOutput(const char * name,const char * type,const char * format)154   virtual void SetOutput(const char *name,const char *type,const char *format){
155     csoundSetOutput(csound, name, type, format);
156   }
SetInput(const char * name)157   virtual void SetInput(const char *name){
158     csoundSetInput(csound, name);
159   }
SetMIDIInput(const char * name)160   virtual void SetMIDIInput(const char *name){
161     csoundSetMIDIInput(csound,name);
162   }
SetMIDIFileInput(const char * name)163   virtual void SetMIDIFileInput(const char *name){
164     csoundSetMIDIFileInput(csound,name);
165   }
SetMIDIOutput(const char * name)166   virtual void SetMIDIOutput(const char *name){
167      csoundSetMIDIOutput(csound,name);
168   }
SetMIDIFileOutput(const char * name)169    virtual void SetMIDIFileOutput(const char *name){
170     csoundSetMIDIFileOutput(csound,name);
171   }
ParseOrc(const char * str)172   virtual TREE *ParseOrc(const char *str)
173   {
174     return csoundParseOrc(csound, str);
175   }
CompileTree(TREE * root)176   virtual int CompileTree(TREE *root)
177   {
178     return csoundCompileTree(csound, root);
179   }
DeleteTree(TREE * root)180   virtual void DeleteTree(TREE *root)
181   {
182     csoundDeleteTree(csound, root);
183   }
CompileOrc(const char * str)184   virtual int CompileOrc(const char *str)
185   {
186     return csoundCompileOrc(csound, str);
187   }
EvalCode(const char * str)188   virtual MYFLT EvalCode(const char *str)
189   {
190     return csoundEvalCode(csound, str);
191   }
ReadScore(const char * str)192   virtual int ReadScore(const char *str)
193   {
194     return csoundReadScore(csound, str);
195   }
CompileArgs(int argc,const char ** argv)196   virtual int CompileArgs(int argc,const char **argv)
197   {
198     return csoundCompileArgs(csound, argc, argv);
199   }
Compile(int argc,const char ** argv)200   virtual int Compile(int argc,const char **argv)
201   {
202     return csoundCompile(csound, argc, argv);
203   }
Compile(const char * csdName)204   virtual int Compile(const char *csdName)
205   {
206     const char  *argv[3];
207     argv[0] = (char*)"csound";
208     argv[1] = csdName;
209     argv[2] = (char*) 0;
210     return csoundCompile(csound, 2, &(argv[0]));
211   }
Compile(const char * orcName,const char * scoName)212   virtual int Compile(const char *orcName,const  char *scoName)
213   {
214     const char  *argv[4];
215     argv[0] = (char*)"csound";
216     argv[1] = orcName;
217     argv[2] = scoName;
218     argv[3] = (char*) 0;
219     return csoundCompile(csound, 3, &(argv[0]));
220   }
Compile(const char * arg1,const char * arg2,const char * arg3)221   virtual int Compile(const char *arg1,const  char *arg2,const  char *arg3)
222   {
223     const char  *argv[5];
224     argv[0] = (char*)"csound";
225     argv[1] = arg1;
226     argv[2] = arg2;
227     argv[3] = arg3;
228     argv[4] = (char*) 0;
229     return csoundCompile(csound, 4, &(argv[0]));
230   }
Compile(const char * arg1,const char * arg2,const char * arg3,const char * arg4)231   virtual int Compile(const char *arg1,const  char *arg2,const  char *arg3,const  char *arg4)
232   {
233     const char  *argv[6];
234     argv[0] = (char*)"csound";
235     argv[1] = arg1;
236     argv[2] = arg2;
237     argv[3] = arg3;
238     argv[4] = arg4;
239     argv[5] = (char*) 0;
240     return csoundCompile(csound, 5, &(argv[0]));
241   }
Compile(const char * arg1,const char * arg2,const char * arg3,const char * arg4,const char * arg5)242   virtual int Compile(const char *arg1,const  char *arg2,const char *arg3,
243                       const char *arg4,const  char *arg5)
244   {
245     const char  *argv[7];
246     argv[0] = (char*)"csound";
247     argv[1] = arg1;
248     argv[2] = arg2;
249     argv[3] = arg3;
250     argv[4] = arg4;
251     argv[5] = arg5;
252     argv[6] = (char*) 0;
253     return csoundCompile(csound, 6, &(argv[0]));
254   }
CompileCsd(const char * csd)255   virtual int CompileCsd(const char *csd)
256   {
257     return csoundCompileCsd(csound, csd);
258   }
CompileCsdText(const char * csd_text)259   virtual int CompileCsdText(const char *csd_text)
260   {
261     return csoundCompileCsdText(csound, csd_text);
262   }
Start()263   virtual int Start()
264   {
265     return csoundStart(csound);
266   }
Perform()267   virtual int Perform()
268   {
269     return csoundPerform(csound);
270   }
Perform(int argc,const char ** argv)271   virtual int Perform(int argc, const char **argv)
272   {
273     int result = csoundCompile(csound, argc, argv);
274     if (result == 0) {
275       result = csoundPerform(csound);
276     }
277     csoundCleanup(csound);
278     return (result >= 0 ? 0 : result);
279   }
Perform(const char * csdName)280   virtual int Perform(const char *csdName)
281   {
282     const char  *argv[3];
283     int result;
284     argv[0] = (char*)"csound";
285     argv[1] = csdName;
286     argv[2] = (char*) 0;
287     result = csoundCompile(csound, 2, &(argv[0]));
288     if (result == 0) {
289       result = csoundPerform(csound);
290     }
291     csoundCleanup(csound);
292     return (result >= 0 ? 0 : result);
293   }
Perform(const char * orcName,const char * scoName)294   virtual int Perform(const char *orcName, const char *scoName)
295   {
296     const char  *argv[4];
297     int result;
298     argv[0] = (char*)"csound";
299     argv[1] = orcName;
300     argv[2] = scoName;
301     argv[3] = (char*) 0;
302     result = csoundCompile(csound, 3, &(argv[0]));
303     if (result == 0) {
304       result = csoundPerform(csound);
305     }
306     csoundCleanup(csound);
307     return (result >= 0 ? 0 : result);
308   }
Perform(const char * arg1,const char * arg2,const char * arg3)309   virtual int Perform(const char *arg1, const char *arg2, const char *arg3)
310   {
311     const char  *argv[5];
312     int result;
313     argv[0] = (char*)"csound";
314     argv[1] = arg1;
315     argv[2] = arg2;
316     argv[3] = arg3;
317     argv[4] = (char*) 0;
318     result = csoundCompile(csound, 4, &(argv[0]));
319     if (result == 0) {
320       result = csoundPerform(csound);
321     }
322     csoundCleanup(csound);
323     return (result >= 0 ? 0 : result);
324   }
Perform(const char * arg1,const char * arg2,const char * arg3,const char * arg4)325   virtual int Perform(const char *arg1, const  char *arg2, const  char *arg3, const  char *arg4)
326   {
327     const char  *argv[6];
328     int result;
329     argv[0] = (char*)"csound";
330     argv[1] = arg1;
331     argv[2] = arg2;
332     argv[3] = arg3;
333     argv[4] = arg4;
334     argv[5] = (char*) 0;
335     result = csoundCompile(csound, 5, &(argv[0]));
336     if (result == 0) {
337       result = csoundPerform(csound);
338     }
339     csoundCleanup(csound);
340     return (result >= 0 ? 0 : result);
341   }
Perform(const char * arg1,const char * arg2,const char * arg3,const char * arg4,const char * arg5)342   virtual int Perform(const char *arg1, const  char *arg2, const  char *arg3,
343                       const char *arg4, const  char *arg5)
344   {
345     const char  *argv[7];
346     int result;
347     argv[0] = (char*)"csound";
348     argv[1] = arg1;
349     argv[2] = arg2;
350     argv[3] = arg3;
351     argv[4] = arg4;
352     argv[5] = arg5;
353     argv[6] = (char*) 0;
354     result = csoundCompile(csound, 6, &(argv[0]));
355     if (result == 0) {
356       result = csoundPerform(csound);
357     }
358     csoundCleanup(csound);
359     return (result >= 0 ? 0 : result);
360   }
PerformKsmps()361   virtual int PerformKsmps()
362   {
363     return csoundPerformKsmps(csound);
364   }
PerformBuffer()365   virtual int PerformBuffer()
366   {
367     return csoundPerformBuffer(csound);
368   }
Stop()369   virtual void Stop()
370   {
371     csoundStop(csound);
372   }
Cleanup()373   virtual int Cleanup()
374   {
375     return csoundCleanup(csound);
376   }
Reset()377   virtual void Reset()
378   {
379     csoundReset(csound);
380   }
GetSr()381   virtual MYFLT GetSr()
382   {
383     return csoundGetSr(csound);
384   }
GetKr()385   virtual MYFLT GetKr()
386   {
387     return csoundGetKr(csound);
388   }
GetKsmps()389   virtual int GetKsmps()
390   {
391     return csoundGetKsmps(csound);
392   }
GetNchnls()393   virtual int GetNchnls()
394   {
395     return csoundGetNchnls(csound);
396   }
GetNchnlsInput()397   virtual int GetNchnlsInput()
398   {
399     return csoundGetNchnlsInput(csound);
400   }
Get0dBFS()401   virtual MYFLT Get0dBFS()
402   {
403     return csoundGet0dBFS(csound);
404   }
GetInputBufferSize()405   virtual long GetInputBufferSize()
406   {
407     return csoundGetInputBufferSize(csound);
408   }
GetOutputBufferSize()409   virtual long GetOutputBufferSize()
410   {
411     return csoundGetOutputBufferSize(csound);
412   }
GetInputBuffer()413   virtual MYFLT *GetInputBuffer()
414   {
415     return csoundGetInputBuffer(csound);
416   }
GetOutputBuffer()417   virtual MYFLT *GetOutputBuffer()
418   {
419     return csoundGetOutputBuffer(csound);
420   }
GetSpin()421   virtual MYFLT *GetSpin()
422   {
423     return csoundGetSpin(csound);
424   }
GetSpout()425   virtual MYFLT *GetSpout()
426   {
427     return csoundGetSpout(csound);
428   }
GetOutputName()429   virtual const char *GetOutputName()
430   {
431     return csoundGetOutputName(csound);
432   }
GetCurrentTimeSamples()433   virtual long GetCurrentTimeSamples(){
434     return csoundGetCurrentTimeSamples(csound);
435   }
SetHostImplementedAudioIO(int state,int bufSize)436   virtual void SetHostImplementedAudioIO(int state, int bufSize)
437   {
438     csoundSetHostImplementedAudioIO(csound, state, bufSize);
439   }
SetHostImplementedMIDIIO(int state)440   virtual void SetHostImplementedMIDIIO(int state)
441   {
442     csoundSetHostImplementedMIDIIO(csound, state);
443   }
GetScoreTime()444   virtual double GetScoreTime()
445   {
446     return csoundGetScoreTime(csound);
447   }
IsScorePending()448   virtual int IsScorePending()
449   {
450     return csoundIsScorePending(csound);
451   }
SetScorePending(int pending)452   virtual void SetScorePending(int pending)
453   {
454     csoundSetScorePending(csound, pending);
455   }
GetScoreOffsetSeconds()456   virtual MYFLT GetScoreOffsetSeconds()
457   {
458     return csoundGetScoreOffsetSeconds(csound);
459   }
SetScoreOffsetSeconds(double time)460   virtual void SetScoreOffsetSeconds(double time)
461   {
462     csoundSetScoreOffsetSeconds(csound, (MYFLT) time);
463   }
RewindScore()464   virtual void RewindScore()
465   {
466     csoundRewindScore(csound);
467   }
SetCscoreCallback(void (* cscoreCallback_)(CSOUND *))468   virtual void SetCscoreCallback(void (*cscoreCallback_)(CSOUND *))
469   {
470     csoundSetCscoreCallback(csound, cscoreCallback_);
471   }
ScoreSort(FILE * inFile,FILE * outFile)472   virtual int ScoreSort(FILE *inFile, FILE *outFile)
473   {
474     return csoundScoreSort(csound, inFile, outFile);
475   }
ScoreExtract(FILE * inFile,FILE * outFile,FILE * extractFile)476   virtual int ScoreExtract(FILE *inFile, FILE *outFile, FILE *extractFile)
477   {
478     return csoundScoreExtract(csound, inFile, outFile, extractFile);
479   }
Message(const char * format,...)480   virtual void Message(const char *format, ...)
481   {
482     va_list args;
483     va_start(args, format);
484     csoundMessageV(csound, 0, format, args);
485     va_end(args);
486   }
MessageS(int attr,const char * format,...)487   virtual void MessageS(int attr, const char *format, ...)
488   {
489     va_list args;
490     va_start(args, format);
491     csoundMessageV(csound, attr, format, args);
492     va_end(args);
493   }
MessageV(int attr,const char * format,va_list args)494   virtual void MessageV(int attr, const char *format, va_list args)
495   {
496     csoundMessageV(csound, attr, format, args);
497   }
SetMessageCallback(void (* csoundMessageCallback_)(CSOUND *,int attr,const char * format,va_list valist))498   virtual void SetMessageCallback(
499       void (*csoundMessageCallback_)(CSOUND *, int attr,
500                                      const char *format, va_list valist))
501   {
502     csoundSetMessageCallback(csound, csoundMessageCallback_);
503   }
GetMessageLevel()504   virtual int GetMessageLevel()
505   {
506     return csoundGetMessageLevel(csound);
507   }
SetMessageLevel(int messageLevel)508   virtual void SetMessageLevel(int messageLevel)
509   {
510     csoundSetMessageLevel(csound, messageLevel);
511   }
InputMessage(const char * message)512   virtual void InputMessage(const char *message)
513   {
514     csoundInputMessage(csound, message);
515   }
KeyPressed(char c)516   virtual void KeyPressed(char c)
517   {
518     csoundKeyPress(csound, c);
519   }
ScoreEvent(char type,const MYFLT * pFields,long numFields)520   virtual int ScoreEvent(char type, const MYFLT *pFields, long numFields)
521   {
522     return csoundScoreEvent(csound, type, pFields, numFields);
523   }
ScoreEventAbsolute(char type,const MYFLT * pFields,long numFields,double time_ofs)524   virtual int ScoreEventAbsolute(char type, const MYFLT *pFields,
525                                  long numFields, double time_ofs)
526   {
527     return csoundScoreEventAbsolute(csound, type, pFields, numFields, time_ofs);
528   }
SetExternalMidiInOpenCallback(int (* func)(CSOUND *,void **,const char *))529   virtual void SetExternalMidiInOpenCallback(
530       int (*func)(CSOUND *, void **, const char *))
531   {
532     csoundSetExternalMidiInOpenCallback(csound, func);
533   }
SetExternalMidiReadCallback(int (* func)(CSOUND *,void *,unsigned char *,int))534   virtual void SetExternalMidiReadCallback(
535       int (*func)(CSOUND *, void *, unsigned char *, int))
536   {
537     csoundSetExternalMidiReadCallback(csound, func);
538   }
SetExternalMidiInCloseCallback(int (* func)(CSOUND *,void *))539   virtual void SetExternalMidiInCloseCallback(
540       int (*func)(CSOUND *, void *))
541   {
542     csoundSetExternalMidiInCloseCallback(csound, func);
543   }
SetExternalMidiOutOpenCallback(int (* func)(CSOUND *,void **,const char *))544   virtual void SetExternalMidiOutOpenCallback(
545       int (*func)(CSOUND *, void **, const char *))
546   {
547     csoundSetExternalMidiOutOpenCallback(csound, func);
548   }
SetExternalMidiWriteCallback(int (* func)(CSOUND *,void *,const unsigned char *,int))549   virtual void SetExternalMidiWriteCallback(
550       int (*func)(CSOUND *, void *, const unsigned char *, int))
551   {
552     csoundSetExternalMidiWriteCallback(csound, func);
553   }
SetExternalMidiOutCloseCallback(int (* func)(CSOUND *,void *))554   virtual void SetExternalMidiOutCloseCallback(
555       int (*func)(CSOUND *, void *))
556   {
557     csoundSetExternalMidiOutCloseCallback(csound, func);
558   }
SetExternalMidiErrorStringCallback(const char * (* func)(int))559   virtual void SetExternalMidiErrorStringCallback(
560       const char *(*func)(int))
561   {
562     csoundSetExternalMidiErrorStringCallback(csound, func);
563   }
SetIsGraphable(int isGraphable)564   virtual int SetIsGraphable(int isGraphable)
565   {
566     return csoundSetIsGraphable(csound, isGraphable);
567   }
SetMakeGraphCallback(void (* makeGraphCallback_)(CSOUND *,WINDAT * windat,const char * name))568   virtual void SetMakeGraphCallback(
569       void (*makeGraphCallback_)(CSOUND *, WINDAT *windat, const char *name))
570   {
571     csoundSetMakeGraphCallback(csound, makeGraphCallback_);
572   }
SetDrawGraphCallback(void (* drawGraphCallback_)(CSOUND *,WINDAT * windat))573   virtual void SetDrawGraphCallback(
574       void (*drawGraphCallback_)(CSOUND *, WINDAT *windat))
575   {
576     csoundSetDrawGraphCallback(csound, drawGraphCallback_);
577   }
SetKillGraphCallback(void (* killGraphCallback_)(CSOUND *,WINDAT * windat))578   virtual void SetKillGraphCallback(
579       void (*killGraphCallback_)(CSOUND *, WINDAT *windat))
580   {
581     csoundSetKillGraphCallback(csound, killGraphCallback_);
582   }
SetExitGraphCallback(int (* exitGraphCallback_)(CSOUND *))583   virtual void SetExitGraphCallback(
584       int (*exitGraphCallback_)(CSOUND *))
585   {
586     csoundSetExitGraphCallback(csound, exitGraphCallback_);
587   }
NewOpcodeList(opcodeListEntry * & opcodelist)588   virtual int NewOpcodeList(opcodeListEntry* &opcodelist)
589   {
590     opcodeListEntry *tmp = (opcodeListEntry*) 0;
591     int retval;
592     retval = csoundNewOpcodeList(csound, &tmp);
593     opcodelist = tmp;
594     return retval;
595   }
DisposeOpcodeList(opcodeListEntry * opcodelist)596   virtual void DisposeOpcodeList(opcodeListEntry *opcodelist)
597   {
598     csoundDisposeOpcodeList(csound, opcodelist);
599   }
AppendOpcode(const char * opname,int dsblksiz,int flags,int thread,const char * outypes,const char * intypes,int (* iopadr)(CSOUND *,void *),int (* kopadr)(CSOUND *,void *),int (* aopadr)(CSOUND *,void *))600   virtual int AppendOpcode(const char *opname, int dsblksiz, int flags,
601                            int thread,
602                            const char *outypes, const char *intypes,
603                            int (*iopadr)(CSOUND *, void *),
604                            int (*kopadr)(CSOUND *, void *),
605                            int (*aopadr)(CSOUND *, void *))
606   {
607       return csoundAppendOpcode(csound, opname, dsblksiz, flags, thread,
608                               outypes, intypes, iopadr, kopadr, aopadr);
609   }
SetYieldCallback(int (* yieldCallback_)(CSOUND *))610   virtual void SetYieldCallback(int (*yieldCallback_)(CSOUND *))
611   {
612     csoundSetYieldCallback(csound, yieldCallback_);
613   }
SetPlayopenCallback(int (* playopen__)(CSOUND *,const csRtAudioParams * parm))614   virtual void SetPlayopenCallback(
615       int (*playopen__)(CSOUND *, const csRtAudioParams *parm))
616   {
617     csoundSetPlayopenCallback(csound, playopen__);
618   }
SetRtplayCallback(void (* rtplay__)(CSOUND *,const MYFLT * outBuf,int nbytes))619   virtual void SetRtplayCallback(
620       void (*rtplay__)(CSOUND *, const MYFLT *outBuf, int nbytes))
621   {
622     csoundSetRtplayCallback(csound, rtplay__);
623   }
SetRecopenCallback(int (* recopen_)(CSOUND *,const csRtAudioParams * parm))624   virtual void SetRecopenCallback(
625       int (*recopen_)(CSOUND *, const csRtAudioParams *parm))
626   {
627     csoundSetRecopenCallback(csound, recopen_);
628   }
SetRtrecordCallback(int (* rtrecord__)(CSOUND *,MYFLT * inBuf,int nbytes))629   virtual void SetRtrecordCallback(
630       int (*rtrecord__)(CSOUND *, MYFLT *inBuf, int nbytes))
631   {
632     csoundSetRtrecordCallback(csound, rtrecord__);
633   }
SetRtcloseCallback(void (* rtclose__)(CSOUND *))634   virtual void SetRtcloseCallback(
635       void (*rtclose__)(CSOUND *))
636   {
637     csoundSetRtcloseCallback(csound, rtclose__);
638   }
GetDebug()639   virtual int GetDebug()
640   {
641     return csoundGetDebug(csound);
642   }
SetDebug(int debug)643   virtual void SetDebug(int debug)
644   {
645     csoundSetDebug(csound, debug);
646   }
TableLength(int table)647   virtual int TableLength(int table)
648   {
649     return csoundTableLength(csound, table);
650   }
TableGet(int table,int index)651   virtual MYFLT TableGet(int table, int index)
652   {
653     return csoundTableGet(csound, table, index);
654   }
TableSet(int table,int index,double value)655   virtual void TableSet(int table, int index, double value)
656   {
657     csoundTableSet(csound, table, index, (MYFLT) value);
658   }
GetTable(MYFLT * & tablePtr,int tableNum)659   virtual int GetTable(MYFLT* &tablePtr, int tableNum)
660   {
661     MYFLT *ftable;
662     int   tmp;
663     tmp = csoundGetTable(csound, &ftable, tableNum);
664     tablePtr = ftable;
665     return tmp;
666   }
TableCopyOut(int table,MYFLT * dest)667   virtual void TableCopyOut(int table, MYFLT *dest){
668     csoundTableCopyOut(csound,table,dest);
669   }
TableCopyIn(int table,MYFLT * src)670   virtual void TableCopyIn(int table, MYFLT *src){
671     csoundTableCopyIn(csound,table,src);
672   }
CreateGlobalVariable(const char * name,size_t nbytes)673   virtual int CreateGlobalVariable(const char *name, size_t nbytes)
674   {
675     return csoundCreateGlobalVariable(csound, name, nbytes);
676   }
QueryGlobalVariable(const char * name)677   virtual void *QueryGlobalVariable(const char *name)
678   {
679     return csoundQueryGlobalVariable(csound, name);
680   }
QueryGlobalVariableNoCheck(const char * name)681   virtual void *QueryGlobalVariableNoCheck(const char *name)
682   {
683     return csoundQueryGlobalVariableNoCheck(csound, name);
684   }
DestroyGlobalVariable(const char * name)685   virtual int DestroyGlobalVariable(const char *name)
686   {
687     return csoundDestroyGlobalVariable(csound, name);
688   }
GetRtRecordUserData()689   virtual void **GetRtRecordUserData()
690   {
691     return csoundGetRtRecordUserData(csound);
692   }
GetRtPlayUserData()693   virtual void **GetRtPlayUserData()
694   {
695     return csoundGetRtPlayUserData(csound);
696   }
RegisterSenseEventCallback(void (* func)(CSOUND *,void *),void * userData)697   virtual int RegisterSenseEventCallback(void (*func)(CSOUND *, void *),
698                                          void *userData)
699   {
700     return csoundRegisterSenseEventCallback(csound, func, userData);
701   }
RunUtility(const char * name,int argc,char ** argv)702   virtual int RunUtility(const char *name, int argc, char **argv)
703   {
704     return csoundRunUtility(csound, name, argc, argv);
705   }
ListUtilities()706   virtual char **ListUtilities()
707   {
708     return csoundListUtilities(csound);
709   }
DeleteUtilityList(char ** lst)710   virtual void DeleteUtilityList(char **lst)
711   {
712     csoundDeleteUtilityList(csound, lst);
713   }
GetUtilityDescription(const char * utilName)714   virtual const char *GetUtilityDescription(const char *utilName)
715   {
716     return csoundGetUtilityDescription(csound, utilName);
717   }
GetChannelPtr(MYFLT * & p,const char * name,int type)718   virtual int GetChannelPtr(MYFLT* &p, const char *name, int type)
719   {
720     MYFLT *tmp;
721     int   retval;
722     if(strlen(name) == 0) return CSOUND_ERROR;
723     retval = csoundGetChannelPtr(csound, &tmp, name, type);
724     p = tmp;
725     return retval;
726   }
ListChannels(controlChannelInfo_t * & lst)727   virtual int ListChannels(controlChannelInfo_t* &lst)
728   {
729     controlChannelInfo_t  *tmp;
730     int                     retval;
731     retval = csoundListChannels(csound, &tmp);
732     lst = tmp;
733     return retval;
734   }
DeleteChannelList(controlChannelInfo_t * lst)735   virtual void DeleteChannelList(controlChannelInfo_t *lst)
736   {
737     csoundDeleteChannelList(csound, lst);
738   }
SetControlChannelHints(const char * name,controlChannelHints_t hints)739   virtual int SetControlChannelHints(const char *name,
740                                       controlChannelHints_t hints)
741   {
742     return csoundSetControlChannelHints(csound, name, hints);
743   }
GetControlChannelHints(const char * name,controlChannelHints_t * hints)744   virtual int GetControlChannelHints(const char *name, controlChannelHints_t *hints)
745   {
746     return csoundGetControlChannelHints(csound, name, hints);
747   }
SetChannel(const char * name,double value)748   virtual void SetChannel(const char *name, double value)
749   {
750     csoundSetControlChannel(csound,name,value);
751   }
SetControlChannel(const char * name,double value)752   virtual void SetControlChannel(const char *name, double value)
753   {
754     csoundSetControlChannel(csound,name,value);
755   }
SetChannel(const char * name,char * string)756   virtual void SetChannel(const char *name, char *string)
757   {
758    csoundSetStringChannel(csound,name,string);
759   }
SetStringChannel(const char * name,char * string)760   virtual void SetStringChannel(const char *name, char *string)
761   {
762    csoundSetStringChannel(csound,name,string);
763   }
SetChannel(const char * name,MYFLT * samples)764   virtual void SetChannel(const char *name, MYFLT *samples)
765   {
766    csoundSetAudioChannel(csound,name,samples);
767   }
GetChannel(const char * name,int * err=NULL)768   virtual MYFLT GetChannel(const char *name, int *err = NULL)
769   {
770    return csoundGetControlChannel(csound,name, err);
771   }
GetControlChannel(const char * name,int * err=NULL)772   virtual MYFLT GetControlChannel(const char *name, int *err = NULL)
773   {
774    return csoundGetControlChannel(csound,name, err);
775   }
GetStringChannel(const char * name,char * string)776   virtual void GetStringChannel(const char *name, char *string)
777   {
778     csoundGetStringChannel(csound,name,string);
779   }
GetAudioChannel(const char * name,MYFLT * samples)780   virtual void GetAudioChannel(const char *name, MYFLT *samples)
781   {
782     csoundGetAudioChannel(csound,name,samples);
783   }
PvsinSet(const PVSDATEXT * value,const char * name)784   virtual int PvsinSet(const PVSDATEXT* value, const char *name)
785   {
786     return csoundSetPvsChannel(csound, value, name);
787   }
788 
PvsoutGet(PVSDATEXT * value,const char * name)789   virtual int PvsoutGet(PVSDATEXT* value, const char *name)
790   {
791     return csoundGetPvsChannel(csound, value, name);
792   }
793 
SetInputChannelCallback(channelCallback_t inputChannelCalback)794   virtual void SetInputChannelCallback(channelCallback_t inputChannelCalback){
795     csoundSetInputChannelCallback(csound, inputChannelCalback);
796   }
797 
SetOutputChannelCallback(channelCallback_t outputChannelCalback)798   virtual void SetOutputChannelCallback(channelCallback_t outputChannelCalback){
799     csoundSetOutputChannelCallback(csound, outputChannelCalback);
800   }
801 
802   // cfgvar.h interface
CreateConfigurationVariable(const char * name,void * p,int type,int flags,void * min,void * max,const char * shortDesc,const char * longDesc)803   virtual int CreateConfigurationVariable(const char *name, void *p,
804                                           int type, int flags,
805                                           void *min, void *max,
806                                           const char *shortDesc,
807                                           const char *longDesc)
808   {
809     return csoundCreateConfigurationVariable(csound, name, p, type, flags,
810                                              min, max, shortDesc, longDesc);
811   }
SetConfigurationVariable(const char * name,void * value)812   virtual int SetConfigurationVariable(const char *name, void *value)
813   {
814     return csoundSetConfigurationVariable(csound, name, value);
815   }
ParseConfigurationVariable(const char * name,const char * value)816   virtual int ParseConfigurationVariable(const char *name, const char *value)
817   {
818     return csoundParseConfigurationVariable(csound, name, value);
819   }
QueryConfigurationVariable(const char * name)820   virtual csCfgVariable_t *QueryConfigurationVariable(const char *name)
821   {
822     return csoundQueryConfigurationVariable(csound, name);
823   }
ListConfigurationVariables()824   virtual csCfgVariable_t **ListConfigurationVariables()
825   {
826     return csoundListConfigurationVariables(csound);
827   }
DeleteConfigurationVariable(const char * name)828   virtual int DeleteConfigurationVariable(const char *name)
829   {
830     return csoundDeleteConfigurationVariable(csound, name);
831   }
Csound()832   Csound()
833   {
834     csound = csoundCreate((CSOUND*) 0);
835      #ifdef SWIGPYTHON
836       pydata =(pycbdata *) new pycbdata;
837       memset(pydata, 0, sizeof(pycbdata));
838     ((pycbdata *)pydata)->mfunc = NULL;
839     ((pycbdata *)pydata)->messageBufferIndex = 0;
840     csoundSetHostData(csound, this);
841     #else
842     pydata = NULL;
843     #endif
844 
845   }
Csound(CSOUND * csound_)846   Csound(CSOUND *csound_) : csound(csound_)
847   {
848      #ifdef SWIGPYTHON
849       pydata =(pycbdata *) new pycbdata;
850     ((pycbdata *)pydata)->mfunc = NULL;
851     ((pycbdata *)pydata)->messageBufferIndex = 0;
852     csoundSetHostData(csound, this);
853     #else
854     pydata = NULL;
855     #endif
856 
857   }
Csound(void * hostData)858   Csound(void *hostData)
859   {
860     csound = csoundCreate(hostData);
861     #ifdef SWIGPYTHON
862     pydata =(pycbdata *) new pycbdata;
863     ((pycbdata *)pydata)->mfunc = NULL;
864     ((pycbdata *)pydata)->messageBufferIndex = 0;
865     csoundSetHostData(csound, this);
866     #else
867     pydata = NULL;
868     #endif
869   }
~Csound()870   virtual ~Csound()
871   {
872     csoundDestroy(csound);
873     #ifdef SWIGPYTHON
874     ((pycbdata *)pydata)->mfunc = NULL;
875     delete (pycbdata *)pydata;
876     #endif
877 
878   }
CreateMessageBuffer(int toStdOut)879   virtual void CreateMessageBuffer(int toStdOut)
880   {
881     csoundCreateMessageBuffer(csound, toStdOut);
882   }
GetFirstMessage()883   virtual const char *GetFirstMessage()
884   {
885     return csoundGetFirstMessage(csound);
886   }
GetFirstMessageAttr()887   virtual int GetFirstMessageAttr()
888   {
889     return csoundGetFirstMessageAttr(csound);
890   }
PopFirstMessage()891   virtual void PopFirstMessage()
892   {
893     csoundPopFirstMessage(csound);
894   }
GetMessageCnt()895   virtual int GetMessageCnt()
896   {
897     return csoundGetMessageCnt(csound);
898   }
DestroyMessageBuffer()899   virtual void DestroyMessageBuffer()
900   {
901     csoundDestroyMessageBuffer(csound);
902   }
AddSpinSample(int frame,int channel,MYFLT sample)903   virtual void AddSpinSample(int frame, int channel, MYFLT sample)
904   {
905     csoundAddSpinSample(csound, frame, channel, sample);
906   }
GetSpoutSample(int frame,int channel) const907   virtual MYFLT GetSpoutSample(int frame, int channel) const
908   {
909     return csoundGetSpoutSample(csound, frame, channel);
910   }
GetInputName()911   virtual const char *GetInputName()
912   {
913     return csoundGetInputName(csound);
914   }
915 };
916 
917 class CsoundThreadLock {
918 protected:
919   void  *threadLock;
920 public:
Lock(size_t milliseconds)921   int Lock(size_t milliseconds)
922   {
923     return csoundWaitThreadLock(threadLock, milliseconds);
924   }
Lock()925   void Lock()
926   {
927     csoundWaitThreadLockNoTimeout(threadLock);
928   }
TryLock()929   int TryLock()
930   {
931     return csoundWaitThreadLock(threadLock, (size_t) 0);
932   }
Unlock()933   void Unlock()
934   {
935     csoundNotifyThreadLock(threadLock);
936   }
937   // constructors
938   // FIXME: should throw exception on failure ?
CsoundThreadLock()939   CsoundThreadLock()
940   {
941     threadLock = csoundCreateThreadLock();
942   }
CsoundThreadLock(int locked)943   CsoundThreadLock(int locked)
944   {
945     threadLock = csoundCreateThreadLock();
946     if (locked)
947       csoundWaitThreadLock(threadLock, (size_t) 0);
948   }
949   // destructor
~CsoundThreadLock()950   ~CsoundThreadLock()
951   {
952     csoundDestroyThreadLock(threadLock);
953   }
954 };
955 
956 class CsoundMutex {
957 protected:
958   void  *mutex_;
959 public:
Lock()960   void Lock()
961   {
962     csoundLockMutex(mutex_);
963   }
964   // FIXME: this may be unimplemented on Windows
TryLock()965   int TryLock()
966   {
967     return csoundLockMutexNoWait(mutex_);
968   }
Unlock()969   void Unlock()
970   {
971     csoundUnlockMutex(mutex_);
972   }
CsoundMutex()973   CsoundMutex()
974   {
975     mutex_ = csoundCreateMutex(1);
976   }
CsoundMutex(int isRecursive)977   CsoundMutex(int isRecursive)
978   {
979     mutex_ = csoundCreateMutex(isRecursive);
980   }
~CsoundMutex()981   ~CsoundMutex()
982   {
983     csoundDestroyMutex(mutex_);
984   }
985 };
986 
987 // Mersenne Twister (MT19937) pseudo-random number generator
988 
989 class CsoundRandMT {
990 protected:
991   CsoundRandMTState   mt;
992 public:
Random()993   uint32_t Random()
994   {
995     return csoundRandMT(&mt);
996   }
Seed(uint32_t seedVal)997   void Seed(uint32_t seedVal)
998   {
999     csoundSeedRandMT(&mt, (uint32_t*) 0, seedVal);
1000   }
Seed(const uint32_t * initKey,int keyLength)1001   void Seed(const uint32_t *initKey, int keyLength)
1002   {
1003     csoundSeedRandMT(&mt, initKey, (uint32_t) keyLength);
1004   }
CsoundRandMT()1005   CsoundRandMT()
1006   {
1007     csoundSeedRandMT(&mt, (uint32_t*) 0, csoundGetRandomSeedFromTime());
1008   }
CsoundRandMT(uint32_t seedVal)1009   CsoundRandMT(uint32_t seedVal)
1010   {
1011     csoundSeedRandMT(&mt, (uint32_t*) 0, seedVal);
1012   }
CsoundRandMT(const uint32_t * initKey,int keyLength)1013   CsoundRandMT(const uint32_t *initKey, int keyLength)
1014   {
1015     csoundSeedRandMT(&mt, initKey, (uint32_t) keyLength);
1016   }
~CsoundRandMT()1017   ~CsoundRandMT()
1018   {
1019   }
1020 };
1021 
1022 // timer (csoundInitialize() should be called before using this)
1023 
1024 class CsoundTimer {
1025 protected:
1026   RTCLOCK rt;
1027 public:
GetRealTime()1028   double GetRealTime()
1029   {
1030     return csoundGetRealTime(&rt);
1031   }
GetCPUTime()1032   double GetCPUTime()
1033   {
1034     return csoundGetCPUTime(&rt);
1035   }
Reset()1036   void Reset()
1037   {
1038     csoundInitTimerStruct(&rt);
1039   }
1040   // constructor
CsoundTimer()1041   CsoundTimer()
1042   {
1043     csoundInitTimerStruct(&rt);
1044   }
~CsoundTimer()1045   ~CsoundTimer()
1046   {
1047   }
1048 };
1049 
1050 #endif  // __cplusplus
1051 
1052 #endif  // __CSOUND_HPP__
1053