comparison data/midi/rtmidi/RtMidi.h @ 565:3086876472dc

* rtmidi & activity updates
author Chris Cannam
date Tue, 24 Feb 2009 17:25:55 +0000
parents ecce042cc374
children b0533d195c83
comparison
equal deleted inserted replaced
564:ecef2f1bec18 565:3086876472dc
6 MIDI input/output subclasses RtMidiIn and RtMidiOut. 6 MIDI input/output subclasses RtMidiIn and RtMidiOut.
7 7
8 RtMidi WWW site: http://music.mcgill.ca/~gary/rtmidi/ 8 RtMidi WWW site: http://music.mcgill.ca/~gary/rtmidi/
9 9
10 RtMidi: realtime MIDI i/o C++ classes 10 RtMidi: realtime MIDI i/o C++ classes
11 Copyright (c) 2003-2007 Gary P. Scavone 11 Copyright (c) 2003-2009 Gary P. Scavone
12 12
13 Permission is hereby granted, free of charge, to any person 13 Permission is hereby granted, free of charge, to any person
14 obtaining a copy of this software and associated documentation files 14 obtaining a copy of this software and associated documentation files
15 (the "Software"), to deal in the Software without restriction, 15 (the "Software"), to deal in the Software without restriction,
16 including without limitation the rights to use, copy, modify, merge, 16 including without limitation the rights to use, copy, modify, merge,
33 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 33 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 */ 35 */
36 /**********************************************************************/ 36 /**********************************************************************/
37 37
38 // RtMidi: Version 1.0.7 38 // RtMidi: Version 1.0.8
39 39
40 #ifndef RTMIDI_H 40 #ifndef RTMIDI_H
41 #define RTMIDI_H 41 #define RTMIDI_H
42 42
43 #include "RtError.h" 43 #include "RtError.h"
46 class RtMidi 46 class RtMidi
47 { 47 {
48 public: 48 public:
49 49
50 //! Pure virtual openPort() function. 50 //! Pure virtual openPort() function.
51 virtual void openPort( unsigned int portNumber = 0 ) = 0; 51 virtual void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi" ) ) = 0;
52 52
53 //! Pure virtual openVirtualPort() function. 53 //! Pure virtual openVirtualPort() function.
54 virtual void openVirtualPort( const std::string portName = std::string( "RtMidi" ) ) = 0; 54 virtual void openVirtualPort( const std::string portName = std::string( "RtMidi" ) ) = 0;
55 55
56 //! Pure virtual getPortCount() function. 56 //! Pure virtual getPortCount() function.
89 this class to connect to more than one MIDI device at the same 89 this class to connect to more than one MIDI device at the same
90 time. With the OS-X and Linux ALSA MIDI APIs, it is also possible 90 time. With the OS-X and Linux ALSA MIDI APIs, it is also possible
91 to open a virtual input port to which other MIDI software clients 91 to open a virtual input port to which other MIDI software clients
92 can connect. 92 can connect.
93 93
94 by Gary P. Scavone, 2003-2004. 94 by Gary P. Scavone, 2003-2008.
95 */ 95 */
96 /**********************************************************************/ 96 /**********************************************************************/
97 97
98 #include <vector> 98 #include <vector>
99 #include <queue> 99 #include <queue>
103 public: 103 public:
104 104
105 //! User callback function type definition. 105 //! User callback function type definition.
106 typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData); 106 typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData);
107 107
108 //! Default constructor. 108 //! Default constructor that allows an optional client name.
109 /*! 109 /*!
110 An exception will be thrown if a MIDI system initialization error occurs. 110 An exception will be thrown if a MIDI system initialization error occurs.
111 */ 111 */
112 RtMidiIn(std::string inputName = std::string("RtMidi Input Client")); 112 RtMidiIn( const std::string clientName = std::string( "RtMidi Input Client") );
113 113
114 //! If a MIDI connection is still open, it will be closed by the destructor. 114 //! If a MIDI connection is still open, it will be closed by the destructor.
115 ~RtMidiIn(); 115 ~RtMidiIn();
116 116
117 //! Open a MIDI input connection. 117 //! Open a MIDI input connection.
118 /*! 118 /*!
119 An optional port number greater than 0 can be specified. 119 An optional port number greater than 0 can be specified.
120 Otherwise, the default or first port found is opened. 120 Otherwise, the default or first port found is opened.
121 */ 121 */
122 void openPort( unsigned int portNumber = 0 ); 122 void openPort( unsigned int portNumber = 0, const std::string Portname = std::string( "RtMidi Input" ) );
123 123
124 //! Create a virtual input port, with optional name, to allow software connections (OS X and ALSA only). 124 //! Create a virtual input port, with optional name, to allow software connections (OS X and ALSA only).
125 /*! 125 /*!
126 This function creates a virtual MIDI input port to which other 126 This function creates a virtual MIDI input port to which other
127 software applications can connect. This type of functionality 127 software applications can connect. This type of functionality
198 198
199 // The RtMidiInData structure is used to pass private class data to 199 // The RtMidiInData structure is used to pass private class data to
200 // the MIDI input handling function or thread. 200 // the MIDI input handling function or thread.
201 struct RtMidiInData { 201 struct RtMidiInData {
202 std::queue<MidiMessage> queue; 202 std::queue<MidiMessage> queue;
203 MidiMessage message;
203 unsigned int queueLimit; 204 unsigned int queueLimit;
204 unsigned char ignoreFlags; 205 unsigned char ignoreFlags;
205 bool doInput; 206 bool doInput;
206 bool firstMessage; 207 bool firstMessage;
207 void *apiData; 208 void *apiData;
208 bool usingCallback; 209 bool usingCallback;
209 void *userCallback; 210 void *userCallback;
210 void *userData; 211 void *userData;
212 bool continueSysex;
211 213
212 // Default constructor. 214 // Default constructor.
213 RtMidiInData() 215 RtMidiInData()
214 : queueLimit(1024), ignoreFlags(7), doInput(false), firstMessage(true), 216 : queueLimit(1024), ignoreFlags(7), doInput(false), firstMessage(true),
215 apiData(0), usingCallback(false), userCallback(0), userData(0) {} 217 apiData(0), usingCallback(false), userCallback(0), userData(0),
218 continueSysex(false) {}
216 }; 219 };
217 220
218 private: 221 private:
219 222
220 void initialize(std::string name); 223 void initialize( const std::string& clientName );
221 RtMidiInData inputData_; 224 RtMidiInData inputData_;
222 225
223 }; 226 };
224 227
225 /**********************************************************************/ 228 /**********************************************************************/
230 output. It allows one to probe available MIDI output ports, to 233 output. It allows one to probe available MIDI output ports, to
231 connect to one such port, and to send MIDI bytes immediately over 234 connect to one such port, and to send MIDI bytes immediately over
232 the connection. Create multiple instances of this class to 235 the connection. Create multiple instances of this class to
233 connect to more than one MIDI device at the same time. 236 connect to more than one MIDI device at the same time.
234 237
235 by Gary P. Scavone, 2003-2004. 238 by Gary P. Scavone, 2003-2008.
236 */ 239 */
237 /**********************************************************************/ 240 /**********************************************************************/
238 241
239 class RtMidiOut : public RtMidi 242 class RtMidiOut : public RtMidi
240 { 243 {
241 public: 244 public:
242 245
243 //! Default constructor. 246 //! Default constructor that allows an optional client name.
244 /*! 247 /*!
245 An exception will be thrown if a MIDI system initialization error occurs. 248 An exception will be thrown if a MIDI system initialization error occurs.
246 */ 249 */
247 RtMidiOut(std::string outputName = "RtMidi Output Client"); 250 RtMidiOut( const std::string clientName = std::string( "RtMidi Output Client" ) );
248 251
249 //! The destructor closes any open MIDI connections. 252 //! The destructor closes any open MIDI connections.
250 ~RtMidiOut(); 253 ~RtMidiOut();
251 254
252 //! Open a MIDI output connection. 255 //! Open a MIDI output connection.
254 An optional port number greater than 0 can be specified. 257 An optional port number greater than 0 can be specified.
255 Otherwise, the default or first port found is opened. An 258 Otherwise, the default or first port found is opened. An
256 exception is thrown if an error occurs while attempting to make 259 exception is thrown if an error occurs while attempting to make
257 the port connection. 260 the port connection.
258 */ 261 */
259 void openPort( unsigned int portNumber = 0 ); 262 void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Output" ) );
260 263
261 //! Close an open MIDI connection (if one exists). 264 //! Close an open MIDI connection (if one exists).
262 void closePort(); 265 void closePort();
263 266
264 //! Create a virtual output port, with optional name, to allow software connections (OS X and ALSA only). 267 //! Create a virtual output port, with optional name, to allow software connections (OS X and ALSA only).
288 */ 291 */
289 void sendMessage( std::vector<unsigned char> *message ); 292 void sendMessage( std::vector<unsigned char> *message );
290 293
291 private: 294 private:
292 295
293 void initialize(std::string name); 296 void initialize( const std::string& clientName );
294 }; 297 };
295 298
296 #endif 299 #endif