csound.hpp

Go to the documentation of this file.
00001 /*
00002     csound.hpp:
00003 
00004     Copyright (C) 2005 Istvan Varga, Michael Gogins
00005 
00006     This file is part of Csound.
00007 
00008     The Csound Library is free software; you can redistribute it
00009     and/or modify it under the terms of the GNU Lesser General Public
00010     License as published by the Free Software Foundation; either
00011     version 2.1 of the License, or (at your option) any later version.
00012 
00013     Csound is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public
00019     License along with Csound; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00021     02111-1307 USA
00022 
00023     As a special exception, if other files instantiate templates or
00024     use macros or inline functions from this file, this file does not
00025     by itself cause the resulting executable or library to be covered
00026     by the GNU Lesser General Public License. This exception does not
00027     however invalidate any other reasons why the library or executable
00028     file might be covered by the GNU Lesser General Public License.
00029 */
00030 
00031 #ifndef __CSOUND_HPP__
00032 #define __CSOUND_HPP__
00033 
00034 #ifdef SWIG
00035 %module csnd
00036 %{
00037 #include "csound.h"
00038   //#include "cs_glue.h"
00039 %}
00040 #else
00041 #include "csound.h"
00042 #ifdef __BUILDING_CSOUND_INTERFACES
00043 //#include "cs_glue.h"
00044 #endif
00045 #endif
00046 
00047 #if defined(__cplusplus)
00048 
00049 
00053 class PUBLIC Csound
00054 {
00055 protected:
00056   CSOUND *csound;
00057 
00058 public:
00059   virtual CSOUND *GetCsound()
00060   {
00061     return csound;
00062   }
00063   // csound.h interface
00064   virtual int PreCompile()
00065   {
00066     return csoundPreCompile(csound);
00067   }
00068   virtual int InitializeCscore(FILE *insco, FILE *outsco)
00069   {
00070     return csoundInitializeCscore(csound, insco, outsco);
00071   }
00072   virtual void *GetHostData()
00073   {
00074     return csoundGetHostData(csound);
00075   }
00076   virtual void SetHostData(void *hostData)
00077   {
00078     csoundSetHostData(csound, hostData);
00079   }
00080   virtual const char *GetEnv(const char *name)
00081   {
00082     return csoundGetEnv(csound, name);
00083   }
00084   // performance
00085   virtual int Compile(int argc, char **argv)
00086   {
00087     return csoundCompile(csound, argc, argv);
00088   }
00089   virtual int Compile(char *csdName)
00090   {
00091     char  *argv[3];
00092     argv[0] = "csound";
00093     argv[1] = csdName;
00094     argv[2] = (char*) 0;
00095     return csoundCompile(csound, 2, &(argv[0]));
00096   }
00097   virtual int Compile(char *orcName, char *scoName)
00098   {
00099     char  *argv[4];
00100     argv[0] = "csound";
00101     argv[1] = orcName;
00102     argv[2] = scoName;
00103     argv[3] = (char*) 0;
00104     return csoundCompile(csound, 3, &(argv[0]));
00105   }
00106   virtual int Compile(char *arg1, char *arg2, char *arg3)
00107   {
00108     char  *argv[5];
00109     argv[0] = "csound";
00110     argv[1] = arg1;
00111     argv[2] = arg2;
00112     argv[3] = arg3;
00113     argv[4] = (char*) 0;
00114     return csoundCompile(csound, 4, &(argv[0]));
00115   }
00116   virtual int Compile(char *arg1, char *arg2, char *arg3, char *arg4)
00117   {
00118     char  *argv[6];
00119     argv[0] = "csound";
00120     argv[1] = arg1;
00121     argv[2] = arg2;
00122     argv[3] = arg3;
00123     argv[4] = arg4;
00124     argv[5] = (char*) 0;
00125     return csoundCompile(csound, 5, &(argv[0]));
00126   }
00127   virtual int Compile(char *arg1, char *arg2, char *arg3,
00128                       char *arg4, char *arg5)
00129   {
00130     char  *argv[7];
00131     argv[0] = "csound";
00132     argv[1] = arg1;
00133     argv[2] = arg2;
00134     argv[3] = arg3;
00135     argv[4] = arg4;
00136     argv[5] = arg5;
00137     argv[6] = (char*) 0;
00138     return csoundCompile(csound, 6, &(argv[0]));
00139   }
00140   virtual int Perform()
00141   {
00142     return csoundPerform(csound);
00143   }
00144   virtual int Perform(int argc, char **argv)
00145   {
00146     int retval = csoundCompile(csound, argc, argv);
00147     if (!retval)
00148       retval = csoundPerform(csound);
00149     csoundCleanup(csound);
00150     return (retval >= 0 ? 0 : retval);
00151   }
00152   virtual int Perform(char *csdName)
00153   {
00154     char  *argv[3];
00155     int   retval;
00156     argv[0] = "csound";
00157     argv[1] = csdName;
00158     argv[2] = (char*) 0;
00159     if (!(retval = csoundCompile(csound, 2, &(argv[0]))))
00160       retval = csoundPerform(csound);
00161     csoundCleanup(csound);
00162     return (retval >= 0 ? 0 : retval);
00163   }
00164   virtual int Perform(char *orcName, char *scoName)
00165   {
00166     char  *argv[4];
00167     int   retval;
00168     argv[0] = "csound";
00169     argv[1] = orcName;
00170     argv[2] = scoName;
00171     argv[3] = (char*) 0;
00172     if (!(retval = csoundCompile(csound, 3, &(argv[0]))))
00173       retval = csoundPerform(csound);
00174     csoundCleanup(csound);
00175     return (retval >= 0 ? 0 : retval);
00176   }
00177   virtual int Perform(char *arg1, char *arg2, char *arg3)
00178   {
00179     char  *argv[5];
00180     int   retval;
00181     argv[0] = "csound";
00182     argv[1] = arg1;
00183     argv[2] = arg2;
00184     argv[3] = arg3;
00185     argv[4] = (char*) 0;
00186     if (!(retval = csoundCompile(csound, 4, &(argv[0]))))
00187       retval = csoundPerform(csound);
00188     csoundCleanup(csound);
00189     return (retval >= 0 ? 0 : retval);
00190   }
00191   virtual int Perform(char *arg1, char *arg2, char *arg3, char *arg4)
00192   {
00193     char  *argv[6];
00194     int   retval;
00195     argv[0] = "csound";
00196     argv[1] = arg1;
00197     argv[2] = arg2;
00198     argv[3] = arg3;
00199     argv[4] = arg4;
00200     argv[5] = (char*) 0;
00201     if (!(retval = csoundCompile(csound, 5, &(argv[0]))))
00202       retval = csoundPerform(csound);
00203     csoundCleanup(csound);
00204     return (retval >= 0 ? 0 : retval);
00205   }
00206   virtual int Perform(char *arg1, char *arg2, char *arg3,
00207                       char *arg4, char *arg5)
00208   {
00209     char  *argv[7];
00210     int   retval;
00211     argv[0] = "csound";
00212     argv[1] = arg1;
00213     argv[2] = arg2;
00214     argv[3] = arg3;
00215     argv[4] = arg4;
00216     argv[5] = arg5;
00217     argv[6] = (char*) 0;
00218     if (!(retval = csoundCompile(csound, 6, &(argv[0]))))
00219       retval = csoundPerform(csound);
00220     csoundCleanup(csound);
00221     return (retval >= 0 ? 0 : retval);
00222   }
00223   virtual int PerformKsmps()
00224   {
00225     return csoundPerformKsmps(csound);
00226   }
00227   virtual int PerformKsmpsAbsolute()
00228   {
00229     return csoundPerformKsmpsAbsolute(csound);
00230   }
00231   virtual int PerformBuffer()
00232   {
00233     return csoundPerformBuffer(csound);
00234   }
00235   virtual void Stop()
00236   {
00237     csoundStop(csound);
00238   }
00239   virtual int Cleanup()
00240   {
00241     return csoundCleanup(csound);
00242   }
00243   virtual void Reset()
00244   {
00245     csoundReset(csound);
00246   }
00247   // attributes
00248   virtual MYFLT GetSr()
00249   {
00250     return csoundGetSr(csound);
00251   }
00252   virtual MYFLT GetKr()
00253   {
00254     return csoundGetKr(csound);
00255   }
00256   virtual int GetKsmps()
00257   {
00258     return csoundGetKsmps(csound);
00259   }
00260   virtual int GetNchnls()
00261   {
00262     return csoundGetNchnls(csound);
00263   }
00264   virtual MYFLT Get0dBFS()
00265   {
00266     return csoundGet0dBFS(csound);
00267   }
00268   virtual int GetStrVarMaxLen()
00269   {
00270     return csoundGetStrVarMaxLen(csound);
00271   }
00272   virtual int GetSampleFormat()
00273   {
00274     return csoundGetSampleFormat(csound);
00275   }
00276   virtual int GetSampleSize()
00277   {
00278     return csoundGetSampleSize(csound);
00279   }
00280   virtual long GetInputBufferSize()
00281   {
00282     return csoundGetInputBufferSize(csound);
00283   }
00284   virtual long GetOutputBufferSize()
00285   {
00286     return csoundGetOutputBufferSize(csound);
00287   }
00288   virtual MYFLT *GetInputBuffer()
00289   {
00290     return csoundGetInputBuffer(csound);
00291   }
00292   virtual MYFLT *GetOutputBuffer()
00293   {
00294     return csoundGetOutputBuffer(csound);
00295   }
00296   virtual MYFLT *GetSpin()
00297   {
00298     return csoundGetSpin(csound);
00299   }
00300   virtual MYFLT *GetSpout()
00301   {
00302     return csoundGetSpout(csound);
00303   }
00304   virtual const char *GetOutputFileName()
00305   {
00306     return csoundGetOutputFileName(csound);
00307   }
00308   virtual void SetHostImplementedAudioIO(int state, int bufSize)
00309   {
00310     csoundSetHostImplementedAudioIO(csound, state, bufSize);
00311   }
00312   virtual double GetScoreTime()
00313   {
00314     return csoundGetScoreTime(csound);
00315   }
00316   // score handling
00317   virtual int IsScorePending()
00318   {
00319     return csoundIsScorePending(csound);
00320   }
00321   virtual void SetScorePending(int pending)
00322   {
00323     csoundSetScorePending(csound, pending);
00324   }
00325   virtual MYFLT GetScoreOffsetSeconds()
00326   {
00327     return csoundGetScoreOffsetSeconds(csound);
00328   }
00329   virtual void SetScoreOffsetSeconds(double time)
00330   {
00331     csoundSetScoreOffsetSeconds(csound, (MYFLT) time);
00332   }
00333   virtual void RewindScore()
00334   {
00335     csoundRewindScore(csound);
00336   }
00337   virtual void SetCscoreCallback(void (*cscoreCallback_)(CSOUND *))
00338   {
00339     csoundSetCscoreCallback(csound, cscoreCallback_);
00340   }
00341   virtual int ScoreSort(FILE *inFile, FILE *outFile)
00342   {
00343     return csoundScoreSort(csound, inFile, outFile);
00344   }
00345   virtual int ScoreExtract(FILE *inFile, FILE *outFile, FILE *extractFile)
00346   {
00347     return csoundScoreExtract(csound, inFile, outFile, extractFile);
00348   }
00349   // messages & text
00350   virtual void Message(const char *format, ...)
00351   {
00352     va_list args;
00353     va_start(args, format);
00354     csoundMessageV(csound, 0, format, args);
00355     va_end(args);
00356   }
00357   virtual void MessageS(int attr, const char *format, ...)
00358   {
00359     va_list args;
00360     va_start(args, format);
00361     csoundMessageV(csound, attr, format, args);
00362     va_end(args);
00363   }
00364   virtual void MessageV(int attr, const char *format, va_list args)
00365   {
00366     csoundMessageV(csound, attr, format, args);
00367   }
00368   virtual void SetMessageCallback(
00369       void (*csoundMessageCallback_)(CSOUND *, int attr,
00370                                      const char *format, va_list valist))
00371   {
00372     csoundSetMessageCallback(csound, csoundMessageCallback_);
00373   }
00374   virtual int GetMessageLevel()
00375   {
00376     return csoundGetMessageLevel(csound);
00377   }
00378   virtual void SetMessageLevel(int messageLevel)
00379   {
00380     csoundSetMessageLevel(csound, messageLevel);
00381   }
00382   virtual void InputMessage(const char *message)
00383   {
00384     csoundInputMessage(csound, message);
00385   }
00386   virtual void KeyPress(char c)
00387   {
00388     csoundKeyPress(csound, c);
00389   }
00390   // control and events
00391   virtual void SetInputValueCallback(
00392       void (*inputValueCallback_)(CSOUND *, const char *, MYFLT *))
00393   {
00394     csoundSetInputValueCallback(csound, inputValueCallback_);
00395   }
00396   virtual void SetOutputValueCallback(
00397       void (*outputValueCallback_)(CSOUND *, const char *, MYFLT))
00398   {
00399     csoundSetOutputValueCallback(csound, outputValueCallback_);
00400   }
00401   virtual int ScoreEvent(char type, const MYFLT *pFields, long numFields)
00402   {
00403     return csoundScoreEvent(csound, type, pFields, numFields);
00404   }
00405   // MIDI
00406   virtual void SetExternalMidiInOpenCallback(
00407       int (*func)(CSOUND *, void **, const char *))
00408   {
00409     csoundSetExternalMidiInOpenCallback(csound, func);
00410   }
00411   virtual void SetExternalMidiReadCallback(
00412       int (*func)(CSOUND *, void *, unsigned char *, int))
00413   {
00414     csoundSetExternalMidiReadCallback(csound, func);
00415   }
00416   virtual void SetExternalMidiInCloseCallback(
00417       int (*func)(CSOUND *, void *))
00418   {
00419     csoundSetExternalMidiInCloseCallback(csound, func);
00420   }
00421   virtual void SetExternalMidiOutOpenCallback(
00422       int (*func)(CSOUND *, void **, const char *))
00423   {
00424     csoundSetExternalMidiOutOpenCallback(csound, func);
00425   }
00426   virtual void SetExternalMidiWriteCallback(
00427       int (*func)(CSOUND *, void *, const unsigned char *, int))
00428   {
00429     csoundSetExternalMidiWriteCallback(csound, func);
00430   }
00431   virtual void SetExternalMidiOutCloseCallback(
00432       int (*func)(CSOUND *, void *))
00433   {
00434     csoundSetExternalMidiOutCloseCallback(csound, func);
00435   }
00436   virtual void SetExternalMidiErrorStringCallback(
00437       const char *(*func)(int))
00438   {
00439     csoundSetExternalMidiErrorStringCallback(csound, func);
00440   }
00441   // function table display
00442   virtual int SetIsGraphable(int isGraphable)
00443   {
00444     return csoundSetIsGraphable(csound, isGraphable);
00445   }
00446   virtual void SetMakeGraphCallback(
00447       void (*makeGraphCallback_)(CSOUND *, WINDAT *windat, const char *name))
00448   {
00449     csoundSetMakeGraphCallback(csound, makeGraphCallback_);
00450   }
00451   virtual void SetDrawGraphCallback(
00452       void (*drawGraphCallback_)(CSOUND *, WINDAT *windat))
00453   {
00454     csoundSetDrawGraphCallback(csound, drawGraphCallback_);
00455   }
00456   virtual void SetKillGraphCallback(
00457       void (*killGraphCallback_)(CSOUND *, WINDAT *windat))
00458   {
00459     csoundSetKillGraphCallback(csound, killGraphCallback_);
00460   }
00461   virtual void SetMakeXYinCallback(
00462       void (*makeXYinCallback_)(CSOUND *, XYINDAT *, MYFLT x, MYFLT y))
00463   {
00464     csoundSetMakeXYinCallback(csound, makeXYinCallback_);
00465   }
00466   virtual void SetReadXYinCallback(
00467       void (*readXYinCallback_)(CSOUND *, XYINDAT *))
00468   {
00469     csoundSetReadXYinCallback(csound, readXYinCallback_);
00470   }
00471   virtual void SetKillXYinCallback(
00472       void (*killXYinCallback_)(CSOUND *, XYINDAT *))
00473   {
00474     csoundSetKillXYinCallback(csound, killXYinCallback_);
00475   }
00476   virtual void SetExitGraphCallback(
00477       int (*exitGraphCallback_)(CSOUND *))
00478   {
00479     csoundSetExitGraphCallback(csound, exitGraphCallback_);
00480   }
00481   // opcodes
00482   virtual int NewOpcodeList(opcodeListEntry* &opcodelist)
00483   {
00484     opcodeListEntry *tmp = (opcodeListEntry*) 0;
00485     int retval;
00486     retval = csoundNewOpcodeList(csound, &tmp);
00487     opcodelist = tmp;
00488     return retval;
00489   }
00490   virtual void DisposeOpcodeList(opcodeListEntry *opcodelist)
00491   {
00492     csoundDisposeOpcodeList(csound, opcodelist);
00493   }
00494   virtual int AppendOpcode(const char *opname, int dsblksiz, int thread,
00495                            const char *outypes, const char *intypes,
00496                            int (*iopadr)(CSOUND *, void *),
00497                            int (*kopadr)(CSOUND *, void *),
00498                            int (*aopadr)(CSOUND *, void *))
00499   {
00500     return csoundAppendOpcode(csound, opname, dsblksiz, thread,
00501                               outypes, intypes, iopadr, kopadr, aopadr);
00502   }
00503   // miscellaneous functions
00504   virtual void SetYieldCallback(int (*yieldCallback_)(CSOUND *))
00505   {
00506     csoundSetYieldCallback(csound, yieldCallback_);
00507   }
00508   // real-time audio play and record
00509   virtual void SetPlayopenCallback(
00510       int (*playopen__)(CSOUND *, const csRtAudioParams *parm))
00511   {
00512     csoundSetPlayopenCallback(csound, playopen__);
00513   }
00514   virtual void SetRtplayCallback(
00515       void (*rtplay__)(CSOUND *, const MYFLT *outBuf, int nbytes))
00516   {
00517     csoundSetRtplayCallback(csound, rtplay__);
00518   }
00519   virtual void SetRecopenCallback(
00520       int (*recopen_)(CSOUND *, const csRtAudioParams *parm))
00521   {
00522     csoundSetRecopenCallback(csound, recopen_);
00523   }
00524   virtual void SetRtrecordCallback(
00525       int (*rtrecord__)(CSOUND *, MYFLT *inBuf, int nbytes))
00526   {
00527     csoundSetRtrecordCallback(csound, rtrecord__);
00528   }
00529   virtual void SetRtcloseCallback(
00530       void (*rtclose__)(CSOUND *))
00531   {
00532     csoundSetRtcloseCallback(csound, rtclose__);
00533   }
00534   // --------
00535   virtual int GetDebug()
00536   {
00537     return csoundGetDebug(csound);
00538   }
00539   virtual void SetDebug(int debug)
00540   {
00541     csoundSetDebug(csound, debug);
00542   }
00543   virtual int TableLength(int table)
00544   {
00545     return csoundTableLength(csound, table);
00546   }
00547   virtual MYFLT TableGet(int table, int index)
00548   {
00549     return csoundTableGet(csound, table, index);
00550   }
00551   virtual void TableSet(int table, int index, double value)
00552   {
00553     csoundTableSet(csound, table, index, (MYFLT) value);
00554   }
00555   virtual int GetTable(MYFLT* &tablePtr, int tableNum)
00556   {
00557     MYFLT *ftable;
00558     int   tmp;
00559     tmp = csoundGetTable(csound, &ftable, tableNum);
00560     tablePtr = ftable;
00561     return tmp;
00562   }
00563   virtual int CreateGlobalVariable(const char *name, size_t nbytes)
00564   {
00565     return csoundCreateGlobalVariable(csound, name, nbytes);
00566   }
00567   virtual void *QueryGlobalVariable(const char *name)
00568   {
00569     return csoundQueryGlobalVariable(csound, name);
00570   }
00571   virtual void *QueryGlobalVariableNoCheck(const char *name)
00572   {
00573     return csoundQueryGlobalVariableNoCheck(csound, name);
00574   }
00575   virtual int DestroyGlobalVariable(const char *name)
00576   {
00577     return csoundDestroyGlobalVariable(csound, name);
00578   }
00579   virtual void **GetRtRecordUserData()
00580   {
00581     return csoundGetRtRecordUserData(csound);
00582   }
00583   virtual void **GetRtPlayUserData()
00584   {
00585     return csoundGetRtPlayUserData(csound);
00586   }
00587   virtual int RegisterSenseEventCallback(void (*func)(CSOUND *, void *),
00588                                          void *userData)
00589   {
00590     return csoundRegisterSenseEventCallback(csound, func, userData);
00591   }
00592   virtual int RunUtility(const char *name, int argc, char **argv)
00593   {
00594     return csoundRunUtility(csound, name, argc, argv);
00595   }
00596   virtual char **ListUtilities()
00597   {
00598     return csoundListUtilities(csound);
00599   }
00600   virtual void DeleteUtilityList(char **lst)
00601   {
00602     csoundDeleteUtilityList(csound, lst);
00603   }
00604   virtual const char *GetUtilityDescription(const char *utilName)
00605   {
00606     return csoundGetUtilityDescription(csound, utilName);
00607   }
00608   virtual int GetChannelPtr(MYFLT* &p, const char *name, int type)
00609   {
00610     MYFLT *tmp;
00611     int   retval;
00612     retval = csoundGetChannelPtr(csound, &tmp, name, type);
00613     p = tmp;
00614     return retval;
00615   }
00616   virtual int ListChannels(CsoundChannelListEntry* &lst)
00617   {
00618     CsoundChannelListEntry  *tmp;
00619     int                     retval;
00620     retval = csoundListChannels(csound, &tmp);
00621     lst = tmp;
00622     return retval;
00623   }
00624   virtual void DeleteChannelList(CsoundChannelListEntry *lst)
00625   {
00626     csoundDeleteChannelList(csound, lst);
00627   }
00628   virtual int SetControlChannelParams(const char *name, int type,
00629                                       double dflt, double min, double max)
00630   {
00631     return csoundSetControlChannelParams(csound, name, type, (MYFLT) dflt,
00632                                          (MYFLT) min, (MYFLT) max);
00633   }
00634   virtual int GetControlChannelParams(const char *name,
00635                                       MYFLT &dflt, MYFLT &min, MYFLT &max)
00636   {
00637     MYFLT tmp1 = (MYFLT) 0, tmp2 = (MYFLT) 0, tmp3 = (MYFLT) 0;
00638     int   retval;
00639     retval = csoundGetControlChannelParams(csound, name, &tmp1, &tmp2, &tmp3);
00640     dflt = tmp1;
00641     min = tmp2;
00642     max = tmp3;
00643     return retval;
00644   }
00645   virtual void SetChannel(const char *name, double value)
00646   {
00647     MYFLT *p;
00648     if (!(csoundGetChannelPtr(csound, &p, name,
00649                               CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL)))
00650       *p = (MYFLT) value;
00651   }
00652   virtual void SetChannel(const char *name, const char *value)
00653   {
00654     MYFLT *p;
00655     if (!(csoundGetChannelPtr(csound, &p, name,
00656                               CSOUND_STRING_CHANNEL | CSOUND_INPUT_CHANNEL))) {
00657       size_t maxLen = (size_t) (csoundGetStrVarMaxLen(csound) - 1);
00658       size_t i = (size_t) 0;
00659       while (value[i]) {
00660         ((char*) p)[i] = value[i];
00661         if (++i >= maxLen)
00662           break;
00663       }
00664       ((char*) p)[i] = '\0';
00665     }
00666   }
00667   virtual MYFLT GetChannel(const char *name)
00668   {
00669     MYFLT *p;
00670     if (!(csoundGetChannelPtr(csound, &p, name,
00671                               CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL)))
00672       return (*p);
00673     return (MYFLT) 0;
00674   }
00675   virtual int ChanIKSet(double value, int n)
00676   {
00677     return csoundChanIKSet(csound, (MYFLT) value, n);
00678   }
00679   virtual int ChanOKGet(MYFLT &value, int n)
00680   {
00681     MYFLT tmp = (MYFLT) 0;
00682     int   retval;
00683     retval = csoundChanOKGet(csound, &tmp, n);
00684     value = tmp;
00685     return retval;
00686   }
00687   virtual int ChanIASet(const MYFLT *value, int n)
00688   {
00689     return csoundChanIASet(csound, value, n);
00690   }
00691   virtual int ChanOAGet(MYFLT *value, int n)
00692   {
00693     return csoundChanOAGet(csound, value, n);
00694   }
00695 
00696 
00697   virtual int PvsinSet(const PVSDATEXT* value, int n)
00698   {
00699     return csoundPvsinSet(csound, value, n);
00700   }
00701 
00702   virtual int PvsoutGet(PVSDATEXT* value, int n)
00703   {
00704     return csoundPvsoutGet(csound, value, n);
00705   }
00706 
00707   // cfgvar.h interface
00708   virtual int CreateConfigurationVariable(const char *name, void *p,
00709                                           int type, int flags,
00710                                           void *min, void *max,
00711                                           const char *shortDesc,
00712                                           const char *longDesc)
00713   {
00714     return csoundCreateConfigurationVariable(csound, name, p, type, flags,
00715                                              min, max, shortDesc, longDesc);
00716   }
00717 #if 0
00718   virtual int CopyGlobalConfigurationVariable(const char *name, void *p)
00719   {
00720     return csoundCopyGlobalConfigurationVariable(csound, name, p);
00721   }
00722   virtual int CopyGlobalConfigurationVariables()
00723   {
00724     return csoundCopyGlobalConfigurationVariables(csound);
00725   }
00726 #endif
00727   virtual int SetConfigurationVariable(const char *name, void *value)
00728   {
00729     return csoundSetConfigurationVariable(csound, name, value);
00730   }
00731   virtual int ParseConfigurationVariable(const char *name, const char *value)
00732   {
00733     return csoundParseConfigurationVariable(csound, name, value);
00734   }
00735   virtual csCfgVariable_t *QueryConfigurationVariable(const char *name)
00736   {
00737     return csoundQueryConfigurationVariable(csound, name);
00738   }
00739   virtual csCfgVariable_t **ListConfigurationVariables()
00740   {
00741     return csoundListConfigurationVariables(csound);
00742   }
00743   virtual int DeleteConfigurationVariable(const char *name)
00744   {
00745     return csoundDeleteConfigurationVariable(csound, name);
00746   }
00747   virtual void SetChannelIOCallback(CsoundChannelIOCallback_t func)
00748   {
00749     csoundSetChannelIOCallback(csound, func);
00750   }
00751   // constructors
00752   // FIXME: should throw exception on failure ?
00753   Csound()
00754   {
00755     csound = csoundCreate((CSOUND*) 0);
00756   }
00757   Csound(void *hostData)
00758   {
00759     csound = csoundCreate(hostData);
00760   }
00761   // destructor
00762   virtual ~Csound()
00763   {
00764     csoundDestroy(csound);
00765   }
00766   // Functions for embedding.
00767 //#ifdef __BUILDING_CSOUND_INTERFACES
00768   virtual void EnableMessageBuffer(int toStdOut)
00769   {
00770     csoundEnableMessageBuffer(csound, toStdOut);
00771   }
00772   virtual const char *GetFirstMessage()
00773   {
00774     return csoundGetFirstMessage(csound);
00775   }
00776   virtual int GetFirstMessageAttr()
00777   {
00778     return csoundGetFirstMessageAttr(csound);
00779   }
00780   virtual void PopFirstMessage()
00781   {
00782     csoundPopFirstMessage(csound);
00783   }
00784   virtual int GetMessageCnt()
00785   {
00786     return csoundGetMessageCnt(csound);
00787   }
00788   virtual void DestroyMessageBuffer()
00789   {
00790     csoundDestroyMessageBuffer(csound);
00791   }
00792 //#endif
00793 };
00794 
00795 // thread locks
00796 
00797 class CsoundThreadLock {
00798 protected:
00799   void  *threadLock;
00800 public:
00801   int Lock(size_t milliseconds)
00802   {
00803     return csoundWaitThreadLock(threadLock, milliseconds);
00804   }
00805   void Lock()
00806   {
00807     csoundWaitThreadLockNoTimeout(threadLock);
00808   }
00809   int TryLock()
00810   {
00811     return csoundWaitThreadLock(threadLock, (size_t) 0);
00812   }
00813   void Unlock()
00814   {
00815     csoundNotifyThreadLock(threadLock);
00816   }
00817   // constructors
00818   // FIXME: should throw exception on failure ?
00819   CsoundThreadLock()
00820   {
00821     threadLock = csoundCreateThreadLock();
00822   }
00823   CsoundThreadLock(int locked)
00824   {
00825     threadLock = csoundCreateThreadLock();
00826     if (locked)
00827       csoundWaitThreadLock(threadLock, (size_t) 0);
00828   }
00829   // destructor
00830   ~CsoundThreadLock()
00831   {
00832     csoundDestroyThreadLock(threadLock);
00833   }
00834 };
00835 
00836 class CsoundMutex {
00837 protected:
00838   void  *mutex_;
00839 public:
00840   void Lock()
00841   {
00842     csoundLockMutex(mutex_);
00843   }
00844   // FIXME: this may be unimplemented on Windows
00845   int TryLock()
00846   {
00847     return csoundLockMutexNoWait(mutex_);
00848   }
00849   void Unlock()
00850   {
00851     csoundUnlockMutex(mutex_);
00852   }
00853   // constructors
00854   // FIXME: should throw exception on failure ?
00855   CsoundMutex()
00856   {
00857     mutex_ = csoundCreateMutex(1);
00858   }
00859   CsoundMutex(int isRecursive)
00860   {
00861     mutex_ = csoundCreateMutex(isRecursive);
00862   }
00863   // destructor
00864   ~CsoundMutex()
00865   {
00866     csoundDestroyMutex(mutex_);
00867   }
00868 };
00869 
00870 // Mersenne Twister (MT19937) pseudo-random number generator
00871 
00872 class CsoundRandMT {
00873 protected:
00874   CsoundRandMTState   mt;
00875 public:
00876   uint32_t Random()
00877   {
00878     return csoundRandMT(&mt);
00879   }
00880   void Seed(uint32_t seedVal)
00881   {
00882     csoundSeedRandMT(&mt, (uint32_t*) 0, seedVal);
00883   }
00884   void Seed(const uint32_t *initKey, int keyLength)
00885   {
00886     csoundSeedRandMT(&mt, initKey, (uint32_t) keyLength);
00887   }
00888   // constructors
00889   CsoundRandMT()
00890   {
00891     csoundSeedRandMT(&mt, (uint32_t*) 0, csoundGetRandomSeedFromTime());
00892   }
00893   CsoundRandMT(uint32_t seedVal)
00894   {
00895     csoundSeedRandMT(&mt, (uint32_t*) 0, seedVal);
00896   }
00897   CsoundRandMT(const uint32_t *initKey, int keyLength)
00898   {
00899     csoundSeedRandMT(&mt, initKey, (uint32_t) keyLength);
00900   }
00901   ~CsoundRandMT()
00902   {
00903   }
00904 };
00905 
00906 // timer (csoundInitialize() should be called before using this)
00907 
00908 class CsoundTimer {
00909 protected:
00910   RTCLOCK rt;
00911 public:
00912   double GetRealTime()
00913   {
00914     return csoundGetRealTime(&rt);
00915   }
00916   double GetCPUTime()
00917   {
00918     return csoundGetCPUTime(&rt);
00919   }
00920   void Reset()
00921   {
00922     csoundInitTimerStruct(&rt);
00923   }
00924   // constructor
00925   CsoundTimer()
00926   {
00927     csoundInitTimerStruct(&rt);
00928   }
00929   ~CsoundTimer()
00930   {
00931   }
00932 };
00933 
00934 #endif  // __cplusplus
00935 
00936 #endif  // __CSOUND_HPP__
00937 

Generated on Tue Apr 14 11:00:49 2009 for Csound and CsoundAC by  doxygen 1.5.8