00001 /**********************************************************************/ 00036 /**********************************************************************/ 00037 00038 // RtMidi: Version 1.0.15 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, const std::string portName = std::string( "RtMidi" ) ) = 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 00100 class RtMidiIn : public RtMidi 00101 { 00102 public: 00103 00105 typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData); 00106 00108 00115 RtMidiIn( const std::string clientName = std::string( "RtMidi Input Client"), unsigned int queueSizeLimit = 100 ); 00116 00118 ~RtMidiIn(); 00119 00121 00125 void openPort( unsigned int portNumber = 0, const std::string Portname = std::string( "RtMidi Input" ) ); 00126 00128 00134 void openVirtualPort( const std::string portName = std::string( "RtMidi Input" ) ); 00135 00137 00143 void setCallback( RtMidiCallback callback, void *userData = 0 ); 00144 00146 00150 void cancelCallback(); 00151 00153 void closePort( void ); 00154 00156 unsigned int getPortCount(); 00157 00159 00162 std::string getPortName( unsigned int portNumber = 0 ); 00163 00165 00172 void ignoreTypes( bool midiSysex = true, bool midiTime = true, bool midiSense = true ); 00173 00175 00182 double getMessage( std::vector<unsigned char> *message ); 00183 00184 // A MIDI structure used internally by the class to store incoming 00185 // messages. Each message represents one and only one MIDI message. 00186 struct MidiMessage { 00187 std::vector<unsigned char> bytes; 00188 double timeStamp; 00189 00190 // Default constructor. 00191 MidiMessage() 00192 :bytes(0), timeStamp(0.0) {} 00193 }; 00194 00195 struct MidiQueue { 00196 unsigned int front; 00197 unsigned int back; 00198 unsigned int size; 00199 unsigned int ringSize; 00200 MidiMessage *ring; 00201 00202 // Default constructor. 00203 MidiQueue() 00204 :front(0), back(0), size(0), ringSize(0) {} 00205 }; 00206 00207 // The RtMidiInData structure is used to pass private class data to 00208 // the MIDI input handling function or thread. 00209 struct RtMidiInData { 00210 MidiQueue queue; 00211 MidiMessage message; 00212 unsigned char ignoreFlags; 00213 bool doInput; 00214 bool firstMessage; 00215 void *apiData; 00216 bool usingCallback; 00217 void *userCallback; 00218 void *userData; 00219 bool continueSysex; 00220 00221 // Default constructor. 00222 RtMidiInData() 00223 : ignoreFlags(7), doInput(false), firstMessage(true), 00224 apiData(0), usingCallback(false), userCallback(0), userData(0), 00225 continueSysex(false) {} 00226 }; 00227 00228 private: 00229 00230 void initialize( const std::string& clientName ); 00231 RtMidiInData inputData_; 00232 00233 }; 00234 00235 /**********************************************************************/ 00247 /**********************************************************************/ 00248 00249 class RtMidiOut : public RtMidi 00250 { 00251 public: 00252 00254 00257 RtMidiOut( const std::string clientName = std::string( "RtMidi Output Client" ) ); 00258 00260 ~RtMidiOut(); 00261 00263 00269 void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Output" ) ); 00270 00272 void closePort(); 00273 00275 00283 void openVirtualPort( const std::string portName = std::string( "RtMidi Output" ) ); 00284 00286 unsigned int getPortCount(); 00287 00289 00292 std::string getPortName( unsigned int portNumber = 0 ); 00293 00295 00299 void sendMessage( std::vector<unsigned char> *message ); 00300 00301 private: 00302 00303 void initialize( const std::string& clientName ); 00304 }; 00305 00306 #endif
![]() |
©2003-2011 Gary P. Scavone, McGill University. All Rights Reserved. Maintained by Gary P. Scavone, gary at music.mcgill.ca |