cs_glue.hpp

Go to the documentation of this file.
00001 /*
00002     cs_glue.hpp:
00003 
00004     Copyright (C) 2005, 2006 Istvan Varga
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 
00024 #ifndef CSOUND_CS_GLUE_HPP
00025 #define CSOUND_CS_GLUE_HPP
00026 
00035 void PUBLIC sigcpy(MYFLT *dest, MYFLT *src, int size);
00036 
00037 class PUBLIC CsoundOpcodeList {
00038  private:
00039     opcodeListEntry *lst;
00040     int             cnt;
00041  public:
00045     int Count();
00050     const char *Name(int ndx);
00055     const char *OutTypes(int ndx);
00060     const char *InTypes(int ndx);
00065     void Clear();
00066     // --------
00067     CsoundOpcodeList(CSOUND *csound);
00068     CsoundOpcodeList(Csound *csound);
00069     ~CsoundOpcodeList();
00070 };
00071 
00080 class PUBLIC CsoundChannelList {
00081  private:
00082     CsoundChannelListEntry  *lst;
00083     int                     cnt;
00084     CSOUND                  *csound;
00085     void ResetVariables();
00086     int GetChannelMetaData(int ndx, MYFLT &dflt, MYFLT &min, MYFLT &max);
00087  public:
00091     int Count();
00096     const char *Name(int ndx);
00101     int Type(int ndx);
00106     int IsControlChannel(int ndx);
00111     int IsAudioChannel(int ndx);
00116     int IsStringChannel(int ndx);
00121     int IsInputChannel(int ndx);
00126     int IsOutputChannel(int ndx);
00132     int SubType(int ndx);
00138     double DefaultValue(int ndx);
00144     double MinValue(int ndx);
00150     double MaxValue(int ndx);
00155     void Clear();
00156     // --------
00157     CsoundChannelList(CSOUND *csound);
00158     CsoundChannelList(Csound *csound);
00159     ~CsoundChannelList();
00160 };
00161 
00171 class PUBLIC CsoundUtilityList {
00172  private:
00173     char  **lst;
00174     int   cnt;
00175  public:
00179     int Count();
00184     const char *Name(int ndx);
00189     void Clear();
00190     // --------
00191     CsoundUtilityList(CSOUND *csound);
00192     CsoundUtilityList(Csound *csound);
00193     ~CsoundUtilityList();
00194 };
00195 
00209 class PUBLIC CsoundMYFLTArray {
00210  private:
00211     MYFLT *p;
00212     void  *pp;
00213  public:
00217     MYFLT **GetPtr()
00218     {
00219       return (&p);
00220     }
00226     MYFLT *GetPtr(int ndx)
00227     {
00228       if (p)
00229         return &(p[ndx]);
00230       return (MYFLT*) 0;
00231     }
00236     void SetPtr(MYFLT *ptr)
00237     {
00238       p = ptr;
00239     }
00245     void SetValue(int ndx, double value)
00246     {
00247       p[ndx] = (MYFLT) value;
00248     }
00254     void SetValues(int ndx, double v0, double v1)
00255     {
00256       p[ndx]     = (MYFLT) v0;  p[ndx + 1] = (MYFLT) v1;
00257     }
00263     void SetValues(int ndx, double v0, double v1, double v2)
00264     {
00265       p[ndx]     = (MYFLT) v0;  p[ndx + 1] = (MYFLT) v1;
00266       p[ndx + 2] = (MYFLT) v2;
00267     }
00273     void SetValues(int ndx, double v0, double v1, double v2, double v3)
00274     {
00275       p[ndx]     = (MYFLT) v0;  p[ndx + 1] = (MYFLT) v1;
00276       p[ndx + 2] = (MYFLT) v2;  p[ndx + 3] = (MYFLT) v3;
00277     }
00283     void SetValues(int ndx,
00284                    double v0, double v1, double v2, double v3, double v4)
00285     {
00286       p[ndx]     = (MYFLT) v0;  p[ndx + 1] = (MYFLT) v1;
00287       p[ndx + 2] = (MYFLT) v2;  p[ndx + 3] = (MYFLT) v3;
00288       p[ndx + 4] = (MYFLT) v4;
00289     }
00295     void SetValues(int ndx,
00296                    double v0, double v1, double v2, double v3, double v4,
00297                    double v5)
00298     {
00299       p[ndx]     = (MYFLT) v0;  p[ndx + 1] = (MYFLT) v1;
00300       p[ndx + 2] = (MYFLT) v2;  p[ndx + 3] = (MYFLT) v3;
00301       p[ndx + 4] = (MYFLT) v4;  p[ndx + 5] = (MYFLT) v5;
00302     }
00308     void SetValues(int ndx,
00309                    double v0, double v1, double v2, double v3, double v4,
00310                    double v5, double v6)
00311     {
00312       p[ndx]     = (MYFLT) v0;  p[ndx + 1] = (MYFLT) v1;
00313       p[ndx + 2] = (MYFLT) v2;  p[ndx + 3] = (MYFLT) v3;
00314       p[ndx + 4] = (MYFLT) v4;  p[ndx + 5] = (MYFLT) v5;
00315       p[ndx + 6] = (MYFLT) v6;
00316     }
00322     void SetValues(int ndx,
00323                    double v0, double v1, double v2, double v3, double v4,
00324                    double v5, double v6, double v7)
00325     {
00326       p[ndx]     = (MYFLT) v0;  p[ndx + 1] = (MYFLT) v1;
00327       p[ndx + 2] = (MYFLT) v2;  p[ndx + 3] = (MYFLT) v3;
00328       p[ndx + 4] = (MYFLT) v4;  p[ndx + 5] = (MYFLT) v5;
00329       p[ndx + 6] = (MYFLT) v6;  p[ndx + 7] = (MYFLT) v7;
00330     }
00336     void SetValues(int ndx,
00337                    double v0, double v1, double v2, double v3, double v4,
00338                    double v5, double v6, double v7, double v8)
00339     {
00340       p[ndx]     = (MYFLT) v0;  p[ndx + 1] = (MYFLT) v1;
00341       p[ndx + 2] = (MYFLT) v2;  p[ndx + 3] = (MYFLT) v3;
00342       p[ndx + 4] = (MYFLT) v4;  p[ndx + 5] = (MYFLT) v5;
00343       p[ndx + 6] = (MYFLT) v6;  p[ndx + 7] = (MYFLT) v7;
00344       p[ndx + 8] = (MYFLT) v8;
00345     }
00351     void SetValues(int ndx,
00352                    double v0, double v1, double v2, double v3, double v4,
00353                    double v5, double v6, double v7, double v8, double v9)
00354     {
00355       p[ndx]     = (MYFLT) v0;  p[ndx + 1] = (MYFLT) v1;
00356       p[ndx + 2] = (MYFLT) v2;  p[ndx + 3] = (MYFLT) v3;
00357       p[ndx + 4] = (MYFLT) v4;  p[ndx + 5] = (MYFLT) v5;
00358       p[ndx + 6] = (MYFLT) v6;  p[ndx + 7] = (MYFLT) v7;
00359       p[ndx + 8] = (MYFLT) v8;  p[ndx + 9] = (MYFLT) v9;
00360     }
00366     double GetValue(int ndx)
00367     {
00368       return (double) p[ndx];
00369     }
00374     void SetValues(int ndx, int n, const MYFLT *src)
00375     {
00376       for (int i = 0; i < n; i++)
00377         p[ndx + i] = src[i];
00378     }
00383     void GetValues(MYFLT *dst, int ndx, int n)
00384     {
00385       for (int i = 0; i < n; i++)
00386         dst[i] = p[ndx + i];
00387     }
00393     void SetStringValue(const char *s, int maxLen);
00398     const char *GetStringValue();
00403     void Clear();
00404     // --------
00405     CsoundMYFLTArray();
00406     CsoundMYFLTArray(int n);
00407     ~CsoundMYFLTArray();
00408 };
00409 
00415 class PUBLIC CsoundArgVList {
00416  private:
00417     char  **ArgV_;
00418     int   cnt;
00419     void destroy_argv();
00420  public:
00425     int argc();
00429     char **argv();
00434     const char *argv(int ndx);
00440     void Insert(int ndx, const char *s);
00445     void Append(const char *s);
00449     void Clear();
00450     // --------
00451     CsoundArgVList();
00452     ~CsoundArgVList();
00453 };
00454 
00459 class CsoundMidiInputBuffer;
00460 class CsoundMidiOutputBuffer;
00461 
00462 class PUBLIC CsoundCallbackWrapper {
00463  private:
00464     CSOUND  *csound_;
00465  public:
00466     virtual void MessageCallback(int attr, char *msg)
00467     {
00468       (void) attr;
00469       (void) msg;
00470     }
00471     virtual double InputValueCallback(const char *chnName)
00472     {
00473       (void) chnName;
00474       return 0.0;
00475     }
00476     virtual void OutputValueCallback(const char *chnName, double value)
00477     {
00478       (void) chnName;
00479       (void) value;
00480     }
00481     virtual int YieldCallback()
00482     {
00483       return 1;
00484     }
00485     virtual void MidiInputCallback(CsoundMidiInputBuffer *p)
00486     {
00487       (void) p;
00488     }
00489     virtual void MidiOutputCallback(CsoundMidiOutputBuffer *p)
00490     {
00491       (void) p;
00492     }
00493     virtual double ControlChannelInputCallback(const char *chnName)
00494     {
00495       (void) chnName;
00496       return 0.0;
00497     }
00498     virtual void ControlChannelOutputCallback(const char *chnName, double value)
00499     {
00500       (void) chnName;
00501       (void) value;
00502     }
00503     virtual const char *StringChannelInputCallback(const char *chnName)
00504     {
00505       (void) chnName;
00506       return "";
00507     }
00508     virtual void StringChannelOutputCallback(const char *chnName,
00509                                              const char *value)
00510     {
00511       (void) chnName;
00512       (void) value;
00513     }
00514 #if 0
00515     virtual void AudioChannelInputCallback(const char *chnName, MYFLT *buf)
00516     {
00517       int   ksmps = csoundGetKsmps(csound_);
00518       (void) chnName;
00519       for (int i = 0; i < ksmps; i++)
00520         buf[i] = (MYFLT) 0.0;
00521     }
00522     virtual void AudioChannelOutputCallback(const char *chnName, MYFLT *buf)
00523     {
00524       (void) chnName;
00525       (void) buf;
00526     }
00527 #endif
00528     void SetMessageCallback();
00529     void SetInputValueCallback();
00530     void SetOutputValueCallback();
00531     void SetYieldCallback();
00532     void SetMidiInputCallback(CsoundArgVList *argv);
00533     void SetMidiOutputCallback(CsoundArgVList *argv);
00534     void SetChannelIOCallbacks();
00535     CSOUND *GetCsound()
00536     {
00537       return csound_;
00538     }
00539     // for converting SWIG char* type to a Python string
00540     static const char *CharPtrToString(const char *s)
00541     {
00542       return s;
00543     }
00544     // --------
00545     CsoundCallbackWrapper(Csound *csound);
00546     CsoundCallbackWrapper(CSOUND *csound);
00547     virtual ~CsoundCallbackWrapper()
00548     {
00549     }
00550  private:
00551     static int midiInOpenCallback(CSOUND *, void **, const char *);
00552     static int midiInReadCallback(CSOUND *, void *, unsigned char *, int);
00553     static int midiInCloseCallback(CSOUND *, void *);
00554     static int midiOutOpenCallback(CSOUND *, void **, const char *);
00555     static int midiOutWriteCallback(CSOUND *, void *,
00556                                     const unsigned char *, int);
00557     static int midiOutCloseCallback(CSOUND *, void *);
00558 };
00559 
00560 // ---------------------------- MIDI INPUT ----------------------------
00561 
00562 class PUBLIC CsoundMidiInputBuffer {
00563  private:
00564     unsigned char   *buf;
00565     void            *mutex_;
00566     int             bufReadPos;
00567     int             bufWritePos;
00568     int             bufBytes;
00569     int             bufSize;
00570  public:
00571     CsoundMidiInputBuffer(unsigned char *buf, int bufSize);
00572     ~CsoundMidiInputBuffer();
00577     void SendMessage(int msg);
00582     void SendMessage(int status, int channel, int data1, int data2);
00587     void SendNoteOn(int channel, int key, int velocity);
00592     void SendNoteOff(int channel, int key, int velocity);
00597     void SendNoteOff(int channel, int key);
00602     void SendPolyphonicPressure(int channel, int key, int value);
00607     void SendControlChange(int channel, int ctl, int value);
00611     void SendProgramChange(int channel, int pgm);
00615     void SendChannelPressure(int channel, int value);
00619     void SendPitchBend(int channel, int value);
00620     // -----------------------------------------------------------------
00621     friend class CsoundCallbackWrapper;
00622  protected:
00627     int GetMidiData(unsigned char *buf, int nBytes);
00628 };
00629 
00635 class PUBLIC CsoundMidiInputStream : public CsoundMidiInputBuffer {
00636  private:
00637     unsigned char   buf_[4096];
00638     CSOUND          *csound;
00639  public:
00640     CsoundMidiInputStream(CSOUND *csound);
00641     CsoundMidiInputStream(Csound *csound);
00642     ~CsoundMidiInputStream()
00643     {
00644     }
00651     void EnableMidiInput(CsoundArgVList *argv);
00652  private:
00653     static int midiInOpenCallback(CSOUND *, void **, const char *);
00654     static int midiInReadCallback(CSOUND *, void *, unsigned char *, int);
00655     static int midiInCloseCallback(CSOUND *, void *);
00656 };
00657 
00658 // ---------------------------- MIDI OUTPUT ---------------------------
00659 
00660 class PUBLIC CsoundMidiOutputBuffer {
00661  private:
00662     unsigned char   *buf;
00663     void            *mutex_;
00664     int             bufReadPos;
00665     int             bufWritePos;
00666     int             bufBytes;
00667     int             bufSize;
00668  public:
00669     CsoundMidiOutputBuffer(unsigned char *buf, int bufSize);
00670     ~CsoundMidiOutputBuffer();
00678     int PopMessage();
00684     int GetStatus();
00690     int GetChannel();
00696     int GetData1();
00702     int GetData2();
00703     // -----------------------------------------------------------------
00704     friend class CsoundCallbackWrapper;
00705  protected:
00710     int SendMidiData(const unsigned char *buf, int nBytes);
00711 };
00712 
00718 class PUBLIC CsoundMidiOutputStream : public CsoundMidiOutputBuffer {
00719  private:
00720     unsigned char   buf_[4096];
00721     CSOUND          *csound;
00722  public:
00723     CsoundMidiOutputStream(CSOUND *csound);
00724     CsoundMidiOutputStream(Csound *csound);
00725     ~CsoundMidiOutputStream()
00726     {
00727     }
00734     void EnableMidiOutput(CsoundArgVList *argv);
00735  private:
00736     static int midiOutOpenCallback(CSOUND *, void **, const char *);
00737     static int midiOutWriteCallback(CSOUND *, void *,
00738                                     const unsigned char *, int);
00739     static int midiOutCloseCallback(CSOUND *, void *);
00740 };
00741 
00742 #endif  // CSOUND_CS_GLUE_HPP
00743 

Generated on Sun Nov 9 00:04:52 2008 for Csound and CsoundAC by  doxygen 1.5.6