Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


RtMidi.h

00001 /**********************************************************************/
00036 /**********************************************************************/
00037 
00038 // RtMidi: Version 1.0.7
00039 
00040 #ifndef RTMIDI_H
00041 #define RTMIDI_H
00042 
00043 #include "RtError.h"
00044 #include <string>
00045 
00046 class RtMidi
00047 {
00048  public:
00049 
00051   virtual void openPort( unsigned int portNumber = 0 ) = 0;
00052 
00054   virtual void openVirtualPort( const std::string portName = std::string( "RtMidi" ) ) = 0;
00055 
00057   virtual unsigned int getPortCount() = 0;
00058 
00060   virtual std::string getPortName( unsigned int portNumber = 0 ) = 0;
00061 
00063   virtual void closePort( void ) = 0;
00064 
00065  protected:
00066 
00067   RtMidi();
00068   virtual ~RtMidi() {};
00069 
00070   // A basic error reporting function for internal use in the RtMidi
00071   // subclasses.  The behavior of this function can be modified to
00072   // suit specific needs.
00073   void error( RtError::Type type );
00074 
00075   void *apiData_;
00076   bool connected_;
00077   std::string errorString_;
00078 };
00079 
00080 /**********************************************************************/
00096 /**********************************************************************/
00097 
00098 #include <vector>
00099 #include <queue>
00100 
00101 class RtMidiIn : public RtMidi
00102 {
00103  public:
00104 
00106   typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData);
00107 
00109 
00112   RtMidiIn();
00113 
00115   ~RtMidiIn();
00116 
00118 
00122   void openPort( unsigned int portNumber = 0 );
00123 
00125 
00131   void openVirtualPort( const std::string portName = std::string( "RtMidi Input" ) );
00132 
00134 
00140   void setCallback( RtMidiCallback callback, void *userData = 0 );
00141 
00143 
00147   void cancelCallback();
00148 
00150   void closePort( void );
00151 
00153   unsigned int getPortCount();
00154 
00156 
00159   std::string getPortName( unsigned int portNumber = 0 );
00160 
00162 
00166   void setQueueSizeLimit( unsigned int queueSize );
00167 
00169 
00176   void ignoreTypes( bool midiSysex = true, bool midiTime = true, bool midiSense = true );
00177 
00179 
00186   double getMessage( std::vector<unsigned char> *message );
00187 
00188   // A MIDI structure used internally by the class to store incoming
00189   // messages.  Each message represents one and only one MIDI message.
00190   struct MidiMessage { 
00191     std::vector<unsigned char> bytes; 
00192     double timeStamp;
00193 
00194     // Default constructor.
00195     MidiMessage()
00196       :bytes(3), timeStamp(0.0) {}
00197   };
00198 
00199   // The RtMidiInData structure is used to pass private class data to
00200   // the MIDI input handling function or thread.
00201   struct RtMidiInData {
00202     std::queue<MidiMessage> queue;
00203     unsigned int queueLimit;
00204     unsigned char ignoreFlags;
00205     bool doInput;
00206     bool firstMessage;
00207     void *apiData;
00208     bool usingCallback;
00209     void *userCallback;
00210     void *userData;
00211 
00212     // Default constructor.
00213     RtMidiInData()
00214       : queueLimit(1024), ignoreFlags(7), doInput(false), firstMessage(true),
00215         apiData(0), usingCallback(false), userCallback(0), userData(0) {}
00216   };
00217 
00218  private:
00219 
00220   void initialize( void );
00221   RtMidiInData inputData_;
00222 
00223 };
00224 
00225 /**********************************************************************/
00237 /**********************************************************************/
00238 
00239 class RtMidiOut : public RtMidi
00240 {
00241  public:
00242 
00244 
00247   RtMidiOut();
00248 
00250   ~RtMidiOut();
00251 
00253 
00259   void openPort( unsigned int portNumber = 0 );
00260 
00262   void closePort();
00263 
00265 
00273   void openVirtualPort( const std::string portName = std::string( "RtMidi Output" ) );
00274 
00276   unsigned int getPortCount();
00277 
00279 
00282   std::string getPortName( unsigned int portNumber = 0 );
00283 
00285 
00289   void sendMessage( std::vector<unsigned char> *message );
00290 
00291  private:
00292 
00293   void initialize( void );
00294 };
00295 
00296 #endif

The Synthesis ToolKit in C++ (STK)
©1995-2007 Perry R. Cook and Gary P. Scavone. All Rights Reserved.