annotate CollidoscopeApp/include/RtMidi.h @ 18:f1ff1a81be20 tip

Changed licenses names. Fixed one comment and usage text in CollidoscopeApp.cpp.
author Fiore Martin <f.martin@qmul.ac.uk>
date Thu, 25 Aug 2016 12:07:50 +0200
parents 02467299402e
children
rev   line source
f@0 1 /**********************************************************************/
f@0 2 /*! \class RtMidi
f@0 3 \brief An abstract base class for realtime MIDI input/output.
f@0 4
f@0 5 This class implements some common functionality for the realtime
f@0 6 MIDI input/output subclasses RtMidiIn and RtMidiOut.
f@0 7
f@0 8 RtMidi WWW site: http://music.mcgill.ca/~gary/rtmidi/
f@0 9
f@0 10 RtMidi: realtime MIDI i/o C++ classes
f@0 11 Copyright (c) 2003-2016 Gary P. Scavone
f@0 12
f@0 13 Permission is hereby granted, free of charge, to any person
f@0 14 obtaining a copy of this software and associated documentation files
f@0 15 (the "Software"), to deal in the Software without restriction,
f@0 16 including without limitation the rights to use, copy, modify, merge,
f@0 17 publish, distribute, sublicense, and/or sell copies of the Software,
f@0 18 and to permit persons to whom the Software is furnished to do so,
f@0 19 subject to the following conditions:
f@0 20
f@0 21 The above copyright notice and this permission notice shall be
f@0 22 included in all copies or substantial portions of the Software.
f@0 23
f@0 24 Any person wishing to distribute modifications to the Software is
f@0 25 asked to send the modifications to the original developer so that
f@0 26 they can be incorporated into the canonical version. This is,
f@0 27 however, not a binding provision of this license.
f@0 28
f@0 29 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
f@0 30 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
f@0 31 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
f@0 32 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
f@0 33 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
f@0 34 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
f@0 35 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
f@0 36 */
f@0 37 /**********************************************************************/
f@0 38
f@0 39 /*!
f@0 40 \file RtMidi.h
f@0 41 */
f@0 42
f@0 43 #ifndef RTMIDI_H
f@0 44 #define RTMIDI_H
f@0 45
f@0 46 #define RTMIDI_VERSION "2.1.1"
f@0 47
f@0 48 #include <exception>
f@0 49 #include <iostream>
f@0 50 #include <string>
f@0 51 #include <vector>
f@0 52
f@0 53 /************************************************************************/
f@0 54 /*! \class RtMidiError
f@0 55 \brief Exception handling class for RtMidi.
f@0 56
f@0 57 The RtMidiError class is quite simple but it does allow errors to be
f@0 58 "caught" by RtMidiError::Type. See the RtMidi documentation to know
f@0 59 which methods can throw an RtMidiError.
f@0 60 */
f@0 61 /************************************************************************/
f@0 62
f@0 63 class RtMidiError : public std::exception
f@0 64 {
f@0 65 public:
f@0 66 //! Defined RtMidiError types.
f@0 67 enum Type {
f@0 68 WARNING, /*!< A non-critical error. */
f@0 69 DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */
f@0 70 UNSPECIFIED, /*!< The default, unspecified error type. */
f@0 71 NO_DEVICES_FOUND, /*!< No devices found on system. */
f@0 72 INVALID_DEVICE, /*!< An invalid device ID was specified. */
f@0 73 MEMORY_ERROR, /*!< An error occured during memory allocation. */
f@0 74 INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */
f@0 75 INVALID_USE, /*!< The function was called incorrectly. */
f@0 76 DRIVER_ERROR, /*!< A system driver error occured. */
f@0 77 SYSTEM_ERROR, /*!< A system error occured. */
f@0 78 THREAD_ERROR /*!< A thread error occured. */
f@0 79 };
f@0 80
f@0 81 //! The constructor.
f@0 82 RtMidiError( const std::string& message, Type type = RtMidiError::UNSPECIFIED ) throw() : message_(message), type_(type) {}
f@0 83
f@0 84 //! The destructor.
f@0 85 virtual ~RtMidiError( void ) throw() {}
f@0 86
f@0 87 //! Prints thrown error message to stderr.
f@0 88 virtual void printMessage( void ) const throw() { std::cerr << '\n' << message_ << "\n\n"; }
f@0 89
f@0 90 //! Returns the thrown error message type.
f@0 91 virtual const Type& getType(void) const throw() { return type_; }
f@0 92
f@0 93 //! Returns the thrown error message string.
f@0 94 virtual const std::string& getMessage(void) const throw() { return message_; }
f@0 95
f@0 96 //! Returns the thrown error message as a c-style string.
f@0 97 virtual const char* what( void ) const throw() { return message_.c_str(); }
f@0 98
f@0 99 protected:
f@0 100 std::string message_;
f@0 101 Type type_;
f@0 102 };
f@0 103
f@0 104 //! RtMidi error callback function prototype.
f@0 105 /*!
f@0 106 \param type Type of error.
f@0 107 \param errorText Error description.
f@0 108
f@0 109 Note that class behaviour is undefined after a critical error (not
f@0 110 a warning) is reported.
f@0 111 */
f@0 112 typedef void (*RtMidiErrorCallback)( RtMidiError::Type type, const std::string &errorText, void *userData );
f@0 113
f@0 114 class MidiApi;
f@0 115
f@0 116 class RtMidi
f@0 117 {
f@0 118 public:
f@0 119
f@0 120 //! MIDI API specifier arguments.
f@0 121 enum Api {
f@0 122 UNSPECIFIED, /*!< Search for a working compiled API. */
f@0 123 MACOSX_CORE, /*!< Macintosh OS-X Core Midi API. */
f@0 124 LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */
f@0 125 UNIX_JACK, /*!< The JACK Low-Latency MIDI Server API. */
f@0 126 WINDOWS_MM, /*!< The Microsoft Multimedia MIDI API. */
f@0 127 RTMIDI_DUMMY /*!< A compilable but non-functional API. */
f@0 128 };
f@0 129
f@0 130 //! A static function to determine the current RtMidi version.
f@0 131 static std::string getVersion( void ) throw();
f@0 132
f@0 133 //! A static function to determine the available compiled MIDI APIs.
f@0 134 /*!
f@0 135 The values returned in the std::vector can be compared against
f@0 136 the enumerated list values. Note that there can be more than one
f@0 137 API compiled for certain operating systems.
f@0 138 */
f@0 139 static void getCompiledApi( std::vector<RtMidi::Api> &apis ) throw();
f@0 140
f@0 141 //! Pure virtual openPort() function.
f@0 142 virtual void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi" ) ) = 0;
f@0 143
f@0 144 //! Pure virtual openVirtualPort() function.
f@0 145 virtual void openVirtualPort( const std::string portName = std::string( "RtMidi" ) ) = 0;
f@0 146
f@0 147 //! Pure virtual getPortCount() function.
f@0 148 virtual unsigned int getPortCount() = 0;
f@0 149
f@0 150 //! Pure virtual getPortName() function.
f@0 151 virtual std::string getPortName( unsigned int portNumber = 0 ) = 0;
f@0 152
f@0 153 //! Pure virtual closePort() function.
f@0 154 virtual void closePort( void ) = 0;
f@0 155
f@0 156 //! Returns true if a port is open and false if not.
f@0 157 virtual bool isPortOpen( void ) const = 0;
f@0 158
f@0 159 //! Set an error callback function to be invoked when an error has occured.
f@0 160 /*!
f@0 161 The callback function will be called whenever an error has occured. It is best
f@0 162 to set the error callback function before opening a port.
f@0 163 */
f@0 164 virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 ) = 0;
f@0 165
f@0 166 protected:
f@0 167
f@0 168 RtMidi();
f@0 169 virtual ~RtMidi();
f@0 170
f@0 171 MidiApi *rtapi_;
f@0 172 };
f@0 173
f@0 174 /**********************************************************************/
f@0 175 /*! \class RtMidiIn
f@0 176 \brief A realtime MIDI input class.
f@0 177
f@0 178 This class provides a common, platform-independent API for
f@0 179 realtime MIDI input. It allows access to a single MIDI input
f@0 180 port. Incoming MIDI messages are either saved to a queue for
f@0 181 retrieval using the getMessage() function or immediately passed to
f@0 182 a user-specified callback function. Create multiple instances of
f@0 183 this class to connect to more than one MIDI device at the same
f@0 184 time. With the OS-X, Linux ALSA, and JACK MIDI APIs, it is also
f@0 185 possible to open a virtual input port to which other MIDI software
f@0 186 clients can connect.
f@0 187
f@0 188 by Gary P. Scavone, 2003-2014.
f@0 189 */
f@0 190 /**********************************************************************/
f@0 191
f@0 192 // **************************************************************** //
f@0 193 //
f@0 194 // RtMidiIn and RtMidiOut class declarations.
f@0 195 //
f@0 196 // RtMidiIn / RtMidiOut are "controllers" used to select an available
f@0 197 // MIDI input or output interface. They present common APIs for the
f@0 198 // user to call but all functionality is implemented by the classes
f@0 199 // MidiInApi, MidiOutApi and their subclasses. RtMidiIn and RtMidiOut
f@0 200 // each create an instance of a MidiInApi or MidiOutApi subclass based
f@0 201 // on the user's API choice. If no choice is made, they attempt to
f@0 202 // make a "logical" API selection.
f@0 203 //
f@0 204 // **************************************************************** //
f@0 205
f@0 206 class RtMidiIn : public RtMidi
f@0 207 {
f@0 208 public:
f@0 209
f@0 210 //! User callback function type definition.
f@0 211 typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData);
f@0 212
f@0 213 //! Default constructor that allows an optional api, client name and queue size.
f@0 214 /*!
f@0 215 An exception will be thrown if a MIDI system initialization
f@0 216 error occurs. The queue size defines the maximum number of
f@0 217 messages that can be held in the MIDI queue (when not using a
f@0 218 callback function). If the queue size limit is reached,
f@0 219 incoming messages will be ignored.
f@0 220
f@0 221 If no API argument is specified and multiple API support has been
f@0 222 compiled, the default order of use is ALSA, JACK (Linux) and CORE,
f@0 223 JACK (OS-X).
f@0 224
f@0 225 \param api An optional API id can be specified.
f@0 226 \param clientName An optional client name can be specified. This
f@0 227 will be used to group the ports that are created
f@0 228 by the application.
f@0 229 \param queueSizeLimit An optional size of the MIDI input queue can be specified.
f@0 230 */
f@0 231 RtMidiIn( RtMidi::Api api=UNSPECIFIED,
f@0 232 const std::string clientName = std::string( "RtMidi Input Client"),
f@0 233 unsigned int queueSizeLimit = 100 );
f@0 234
f@0 235 //! If a MIDI connection is still open, it will be closed by the destructor.
f@0 236 ~RtMidiIn ( void ) throw();
f@0 237
f@0 238 //! Returns the MIDI API specifier for the current instance of RtMidiIn.
f@0 239 RtMidi::Api getCurrentApi( void ) throw();
f@0 240
f@0 241 //! Open a MIDI input connection given by enumeration number.
f@0 242 /*!
f@0 243 \param portNumber An optional port number greater than 0 can be specified.
f@0 244 Otherwise, the default or first port found is opened.
f@0 245 \param portName An optional name for the application port that is used to connect to portId can be specified.
f@0 246 */
f@0 247 void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Input" ) );
f@0 248
f@0 249 //! Create a virtual input port, with optional name, to allow software connections (OS X, JACK and ALSA only).
f@0 250 /*!
f@0 251 This function creates a virtual MIDI input port to which other
f@0 252 software applications can connect. This type of functionality
f@0 253 is currently only supported by the Macintosh OS-X, any JACK,
f@0 254 and Linux ALSA APIs (the function returns an error for the other APIs).
f@0 255
f@0 256 \param portName An optional name for the application port that is
f@0 257 used to connect to portId can be specified.
f@0 258 */
f@0 259 void openVirtualPort( const std::string portName = std::string( "RtMidi Input" ) );
f@0 260
f@0 261 //! Set a callback function to be invoked for incoming MIDI messages.
f@0 262 /*!
f@0 263 The callback function will be called whenever an incoming MIDI
f@0 264 message is received. While not absolutely necessary, it is best
f@0 265 to set the callback function before opening a MIDI port to avoid
f@0 266 leaving some messages in the queue.
f@0 267
f@0 268 \param callback A callback function must be given.
f@0 269 \param userData Optionally, a pointer to additional data can be
f@0 270 passed to the callback function whenever it is called.
f@0 271 */
f@0 272 void setCallback( RtMidiCallback callback, void *userData = 0 );
f@0 273
f@0 274 //! Cancel use of the current callback function (if one exists).
f@0 275 /*!
f@0 276 Subsequent incoming MIDI messages will be written to the queue
f@0 277 and can be retrieved with the \e getMessage function.
f@0 278 */
f@0 279 void cancelCallback();
f@0 280
f@0 281 //! Close an open MIDI connection (if one exists).
f@0 282 void closePort( void );
f@0 283
f@0 284 //! Returns true if a port is open and false if not.
f@0 285 virtual bool isPortOpen() const;
f@0 286
f@0 287 //! Return the number of available MIDI input ports.
f@0 288 /*!
f@0 289 \return This function returns the number of MIDI ports of the selected API.
f@0 290 */
f@0 291 unsigned int getPortCount();
f@0 292
f@0 293 //! Return a string identifier for the specified MIDI input port number.
f@0 294 /*!
f@0 295 \return The name of the port with the given Id is returned.
f@0 296 \retval An empty string is returned if an invalid port specifier is provided.
f@0 297 */
f@0 298 std::string getPortName( unsigned int portNumber = 0 );
f@0 299
f@0 300 //! Specify whether certain MIDI message types should be queued or ignored during input.
f@0 301 /*!
f@0 302 By default, MIDI timing and active sensing messages are ignored
f@0 303 during message input because of their relative high data rates.
f@0 304 MIDI sysex messages are ignored by default as well. Variable
f@0 305 values of "true" imply that the respective message type will be
f@0 306 ignored.
f@0 307 */
f@0 308 void ignoreTypes( bool midiSysex = true, bool midiTime = true, bool midiSense = true );
f@0 309
f@0 310 //! Fill the user-provided vector with the data bytes for the next available MIDI message in the input queue and return the event delta-time in seconds.
f@0 311 /*!
f@0 312 This function returns immediately whether a new message is
f@0 313 available or not. A valid message is indicated by a non-zero
f@0 314 vector size. An exception is thrown if an error occurs during
f@0 315 message retrieval or an input connection was not previously
f@0 316 established.
f@0 317 */
f@0 318 double getMessage( std::vector<unsigned char> *message );
f@0 319
f@0 320 //! Set an error callback function to be invoked when an error has occured.
f@0 321 /*!
f@0 322 The callback function will be called whenever an error has occured. It is best
f@0 323 to set the error callback function before opening a port.
f@0 324 */
f@0 325 virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 );
f@0 326
f@0 327 protected:
f@0 328 void openMidiApi( RtMidi::Api api, const std::string clientName, unsigned int queueSizeLimit );
f@0 329
f@0 330 };
f@0 331
f@0 332 /**********************************************************************/
f@0 333 /*! \class RtMidiOut
f@0 334 \brief A realtime MIDI output class.
f@0 335
f@0 336 This class provides a common, platform-independent API for MIDI
f@0 337 output. It allows one to probe available MIDI output ports, to
f@0 338 connect to one such port, and to send MIDI bytes immediately over
f@0 339 the connection. Create multiple instances of this class to
f@0 340 connect to more than one MIDI device at the same time. With the
f@0 341 OS-X, Linux ALSA and JACK MIDI APIs, it is also possible to open a
f@0 342 virtual port to which other MIDI software clients can connect.
f@0 343
f@0 344 by Gary P. Scavone, 2003-2014.
f@0 345 */
f@0 346 /**********************************************************************/
f@0 347
f@0 348 class RtMidiOut : public RtMidi
f@0 349 {
f@0 350 public:
f@0 351
f@0 352 //! Default constructor that allows an optional client name.
f@0 353 /*!
f@0 354 An exception will be thrown if a MIDI system initialization error occurs.
f@0 355
f@0 356 If no API argument is specified and multiple API support has been
f@0 357 compiled, the default order of use is ALSA, JACK (Linux) and CORE,
f@0 358 JACK (OS-X).
f@0 359 */
f@0 360 RtMidiOut( RtMidi::Api api=UNSPECIFIED,
f@0 361 const std::string clientName = std::string( "RtMidi Output Client") );
f@0 362
f@0 363 //! The destructor closes any open MIDI connections.
f@0 364 ~RtMidiOut( void ) throw();
f@0 365
f@0 366 //! Returns the MIDI API specifier for the current instance of RtMidiOut.
f@0 367 RtMidi::Api getCurrentApi( void ) throw();
f@0 368
f@0 369 //! Open a MIDI output connection.
f@0 370 /*!
f@0 371 An optional port number greater than 0 can be specified.
f@0 372 Otherwise, the default or first port found is opened. An
f@0 373 exception is thrown if an error occurs while attempting to make
f@0 374 the port connection.
f@0 375 */
f@0 376 void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Output" ) );
f@0 377
f@0 378 //! Close an open MIDI connection (if one exists).
f@0 379 void closePort( void );
f@0 380
f@0 381 //! Returns true if a port is open and false if not.
f@0 382 virtual bool isPortOpen() const;
f@0 383
f@0 384 //! Create a virtual output port, with optional name, to allow software connections (OS X, JACK and ALSA only).
f@0 385 /*!
f@0 386 This function creates a virtual MIDI output port to which other
f@0 387 software applications can connect. This type of functionality
f@0 388 is currently only supported by the Macintosh OS-X, Linux ALSA
f@0 389 and JACK APIs (the function does nothing with the other APIs).
f@0 390 An exception is thrown if an error occurs while attempting to
f@0 391 create the virtual port.
f@0 392 */
f@0 393 void openVirtualPort( const std::string portName = std::string( "RtMidi Output" ) );
f@0 394
f@0 395 //! Return the number of available MIDI output ports.
f@0 396 unsigned int getPortCount( void );
f@0 397
f@0 398 //! Return a string identifier for the specified MIDI port type and number.
f@0 399 /*!
f@0 400 An empty string is returned if an invalid port specifier is provided.
f@0 401 */
f@0 402 std::string getPortName( unsigned int portNumber = 0 );
f@0 403
f@0 404 //! Immediately send a single message out an open MIDI output port.
f@0 405 /*!
f@0 406 An exception is thrown if an error occurs during output or an
f@0 407 output connection was not previously established.
f@0 408 */
f@0 409 void sendMessage( std::vector<unsigned char> *message );
f@0 410
f@0 411 //! Set an error callback function to be invoked when an error has occured.
f@0 412 /*!
f@0 413 The callback function will be called whenever an error has occured. It is best
f@0 414 to set the error callback function before opening a port.
f@0 415 */
f@0 416 virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 );
f@0 417
f@0 418 protected:
f@0 419 void openMidiApi( RtMidi::Api api, const std::string clientName );
f@0 420 };
f@0 421
f@0 422
f@0 423 // **************************************************************** //
f@0 424 //
f@0 425 // MidiInApi / MidiOutApi class declarations.
f@0 426 //
f@0 427 // Subclasses of MidiInApi and MidiOutApi contain all API- and
f@0 428 // OS-specific code necessary to fully implement the RtMidi API.
f@0 429 //
f@0 430 // Note that MidiInApi and MidiOutApi are abstract base classes and
f@0 431 // cannot be explicitly instantiated. RtMidiIn and RtMidiOut will
f@0 432 // create instances of a MidiInApi or MidiOutApi subclass.
f@0 433 //
f@0 434 // **************************************************************** //
f@0 435
f@0 436 class MidiApi
f@0 437 {
f@0 438 public:
f@0 439
f@0 440 MidiApi();
f@0 441 virtual ~MidiApi();
f@0 442 virtual RtMidi::Api getCurrentApi( void ) = 0;
f@0 443 virtual void openPort( unsigned int portNumber, const std::string portName ) = 0;
f@0 444 virtual void openVirtualPort( const std::string portName ) = 0;
f@0 445 virtual void closePort( void ) = 0;
f@0 446
f@0 447 virtual unsigned int getPortCount( void ) = 0;
f@0 448 virtual std::string getPortName( unsigned int portNumber ) = 0;
f@0 449
f@0 450 inline bool isPortOpen() const { return connected_; }
f@0 451 void setErrorCallback( RtMidiErrorCallback errorCallback, void *userData );
f@0 452
f@0 453 //! A basic error reporting function for RtMidi classes.
f@0 454 void error( RtMidiError::Type type, std::string errorString );
f@0 455
f@0 456 protected:
f@0 457 virtual void initialize( const std::string& clientName ) = 0;
f@0 458
f@0 459 void *apiData_;
f@0 460 bool connected_;
f@0 461 std::string errorString_;
f@0 462 RtMidiErrorCallback errorCallback_;
f@0 463 bool firstErrorOccurred_;
f@0 464 void *errorCallbackUserData_;
f@0 465 };
f@0 466
f@0 467 class MidiInApi : public MidiApi
f@0 468 {
f@0 469 public:
f@0 470
f@0 471 MidiInApi( unsigned int queueSizeLimit );
f@0 472 virtual ~MidiInApi( void );
f@0 473 void setCallback( RtMidiIn::RtMidiCallback callback, void *userData );
f@0 474 void cancelCallback( void );
f@0 475 virtual void ignoreTypes( bool midiSysex, bool midiTime, bool midiSense );
f@0 476 double getMessage( std::vector<unsigned char> *message );
f@0 477
f@0 478 // A MIDI structure used internally by the class to store incoming
f@0 479 // messages. Each message represents one and only one MIDI message.
f@0 480 struct MidiMessage {
f@0 481 std::vector<unsigned char> bytes;
f@0 482 double timeStamp;
f@0 483
f@0 484 // Default constructor.
f@0 485 MidiMessage()
f@0 486 :bytes(0), timeStamp(0.0) {}
f@0 487 };
f@0 488
f@0 489 struct MidiQueue {
f@0 490 unsigned int front;
f@0 491 unsigned int back;
f@0 492 unsigned int size;
f@0 493 unsigned int ringSize;
f@0 494 MidiMessage *ring;
f@0 495
f@0 496 // Default constructor.
f@0 497 MidiQueue()
f@0 498 :front(0), back(0), size(0), ringSize(0) {}
f@0 499 };
f@0 500
f@0 501 // The RtMidiInData structure is used to pass private class data to
f@0 502 // the MIDI input handling function or thread.
f@0 503 struct RtMidiInData {
f@0 504 MidiQueue queue;
f@0 505 MidiMessage message;
f@0 506 unsigned char ignoreFlags;
f@0 507 bool doInput;
f@0 508 bool firstMessage;
f@0 509 void *apiData;
f@0 510 bool usingCallback;
f@0 511 RtMidiIn::RtMidiCallback userCallback;
f@0 512 void *userData;
f@0 513 bool continueSysex;
f@0 514
f@0 515 // Default constructor.
f@0 516 RtMidiInData()
f@0 517 : ignoreFlags(7), doInput(false), firstMessage(true),
f@0 518 apiData(0), usingCallback(false), userCallback(0), userData(0),
f@0 519 continueSysex(false) {}
f@0 520 };
f@0 521
f@0 522 protected:
f@0 523 RtMidiInData inputData_;
f@0 524 };
f@0 525
f@0 526 class MidiOutApi : public MidiApi
f@0 527 {
f@0 528 public:
f@0 529
f@0 530 MidiOutApi( void );
f@0 531 virtual ~MidiOutApi( void );
f@0 532 virtual void sendMessage( std::vector<unsigned char> *message ) = 0;
f@0 533 };
f@0 534
f@0 535 // **************************************************************** //
f@0 536 //
f@0 537 // Inline RtMidiIn and RtMidiOut definitions.
f@0 538 //
f@0 539 // **************************************************************** //
f@0 540
f@0 541 inline RtMidi::Api RtMidiIn :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
f@0 542 inline void RtMidiIn :: openPort( unsigned int portNumber, const std::string portName ) { rtapi_->openPort( portNumber, portName ); }
f@0 543 inline void RtMidiIn :: openVirtualPort( const std::string portName ) { rtapi_->openVirtualPort( portName ); }
f@0 544 inline void RtMidiIn :: closePort( void ) { rtapi_->closePort(); }
f@0 545 inline bool RtMidiIn :: isPortOpen() const { return rtapi_->isPortOpen(); }
f@0 546 inline void RtMidiIn :: setCallback( RtMidiCallback callback, void *userData ) { ((MidiInApi *)rtapi_)->setCallback( callback, userData ); }
f@0 547 inline void RtMidiIn :: cancelCallback( void ) { ((MidiInApi *)rtapi_)->cancelCallback(); }
f@0 548 inline unsigned int RtMidiIn :: getPortCount( void ) { return rtapi_->getPortCount(); }
f@0 549 inline std::string RtMidiIn :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); }
f@0 550 inline void RtMidiIn :: ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ) { ((MidiInApi *)rtapi_)->ignoreTypes( midiSysex, midiTime, midiSense ); }
f@0 551 inline double RtMidiIn :: getMessage( std::vector<unsigned char> *message ) { return ((MidiInApi *)rtapi_)->getMessage( message ); }
f@0 552 inline void RtMidiIn :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); }
f@0 553
f@0 554 inline RtMidi::Api RtMidiOut :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); }
f@0 555 inline void RtMidiOut :: openPort( unsigned int portNumber, const std::string portName ) { rtapi_->openPort( portNumber, portName ); }
f@0 556 inline void RtMidiOut :: openVirtualPort( const std::string portName ) { rtapi_->openVirtualPort( portName ); }
f@0 557 inline void RtMidiOut :: closePort( void ) { rtapi_->closePort(); }
f@0 558 inline bool RtMidiOut :: isPortOpen() const { return rtapi_->isPortOpen(); }
f@0 559 inline unsigned int RtMidiOut :: getPortCount( void ) { return rtapi_->getPortCount(); }
f@0 560 inline std::string RtMidiOut :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); }
f@0 561 inline void RtMidiOut :: sendMessage( std::vector<unsigned char> *message ) { ((MidiOutApi *)rtapi_)->sendMessage( message ); }
f@0 562 inline void RtMidiOut :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); }
f@0 563
f@0 564 // **************************************************************** //
f@0 565 //
f@0 566 // MidiInApi and MidiOutApi subclass prototypes.
f@0 567 //
f@0 568 // **************************************************************** //
f@0 569
f@0 570 #if !defined(__LINUX_ALSA__) && !defined(__UNIX_JACK__) && !defined(__MACOSX_CORE__) && !defined(__WINDOWS_MM__)
f@0 571 #define __RTMIDI_DUMMY__
f@0 572 #endif
f@0 573
f@0 574 #if defined(__MACOSX_CORE__)
f@0 575
f@0 576 class MidiInCore: public MidiInApi
f@0 577 {
f@0 578 public:
f@0 579 MidiInCore( const std::string clientName, unsigned int queueSizeLimit );
f@0 580 ~MidiInCore( void );
f@0 581 RtMidi::Api getCurrentApi( void ) { return RtMidi::MACOSX_CORE; };
f@0 582 void openPort( unsigned int portNumber, const std::string portName );
f@0 583 void openVirtualPort( const std::string portName );
f@0 584 void closePort( void );
f@0 585 unsigned int getPortCount( void );
f@0 586 std::string getPortName( unsigned int portNumber );
f@0 587
f@0 588 protected:
f@0 589 void initialize( const std::string& clientName );
f@0 590 };
f@0 591
f@0 592 class MidiOutCore: public MidiOutApi
f@0 593 {
f@0 594 public:
f@0 595 MidiOutCore( const std::string clientName );
f@0 596 ~MidiOutCore( void );
f@0 597 RtMidi::Api getCurrentApi( void ) { return RtMidi::MACOSX_CORE; };
f@0 598 void openPort( unsigned int portNumber, const std::string portName );
f@0 599 void openVirtualPort( const std::string portName );
f@0 600 void closePort( void );
f@0 601 unsigned int getPortCount( void );
f@0 602 std::string getPortName( unsigned int portNumber );
f@0 603 void sendMessage( std::vector<unsigned char> *message );
f@0 604
f@0 605 protected:
f@0 606 void initialize( const std::string& clientName );
f@0 607 };
f@0 608
f@0 609 #endif
f@0 610
f@0 611 #if defined(__UNIX_JACK__)
f@0 612
f@0 613 class MidiInJack: public MidiInApi
f@0 614 {
f@0 615 public:
f@0 616 MidiInJack( const std::string clientName, unsigned int queueSizeLimit );
f@0 617 ~MidiInJack( void );
f@0 618 RtMidi::Api getCurrentApi( void ) { return RtMidi::UNIX_JACK; };
f@0 619 void openPort( unsigned int portNumber, const std::string portName );
f@0 620 void openVirtualPort( const std::string portName );
f@0 621 void closePort( void );
f@0 622 unsigned int getPortCount( void );
f@0 623 std::string getPortName( unsigned int portNumber );
f@0 624
f@0 625 protected:
f@0 626 std::string clientName;
f@0 627
f@0 628 void connect( void );
f@0 629 void initialize( const std::string& clientName );
f@0 630 };
f@0 631
f@0 632 class MidiOutJack: public MidiOutApi
f@0 633 {
f@0 634 public:
f@0 635 MidiOutJack( const std::string clientName );
f@0 636 ~MidiOutJack( void );
f@0 637 RtMidi::Api getCurrentApi( void ) { return RtMidi::UNIX_JACK; };
f@0 638 void openPort( unsigned int portNumber, const std::string portName );
f@0 639 void openVirtualPort( const std::string portName );
f@0 640 void closePort( void );
f@0 641 unsigned int getPortCount( void );
f@0 642 std::string getPortName( unsigned int portNumber );
f@0 643 void sendMessage( std::vector<unsigned char> *message );
f@0 644
f@0 645 protected:
f@0 646 std::string clientName;
f@0 647
f@0 648 void connect( void );
f@0 649 void initialize( const std::string& clientName );
f@0 650 };
f@0 651
f@0 652 #endif
f@0 653
f@0 654 #if defined(__LINUX_ALSA__)
f@0 655
f@0 656 class MidiInAlsa: public MidiInApi
f@0 657 {
f@0 658 public:
f@0 659 MidiInAlsa( const std::string clientName, unsigned int queueSizeLimit );
f@0 660 ~MidiInAlsa( void );
f@0 661 RtMidi::Api getCurrentApi( void ) { return RtMidi::LINUX_ALSA; };
f@0 662 void openPort( unsigned int portNumber, const std::string portName );
f@0 663 void openVirtualPort( const std::string portName );
f@0 664 void closePort( void );
f@0 665 unsigned int getPortCount( void );
f@0 666 std::string getPortName( unsigned int portNumber );
f@0 667
f@0 668 protected:
f@0 669 void initialize( const std::string& clientName );
f@0 670 };
f@0 671
f@0 672 class MidiOutAlsa: public MidiOutApi
f@0 673 {
f@0 674 public:
f@0 675 MidiOutAlsa( const std::string clientName );
f@0 676 ~MidiOutAlsa( void );
f@0 677 RtMidi::Api getCurrentApi( void ) { return RtMidi::LINUX_ALSA; };
f@0 678 void openPort( unsigned int portNumber, const std::string portName );
f@0 679 void openVirtualPort( const std::string portName );
f@0 680 void closePort( void );
f@0 681 unsigned int getPortCount( void );
f@0 682 std::string getPortName( unsigned int portNumber );
f@0 683 void sendMessage( std::vector<unsigned char> *message );
f@0 684
f@0 685 protected:
f@0 686 void initialize( const std::string& clientName );
f@0 687 };
f@0 688
f@0 689 #endif
f@0 690
f@0 691 #if defined(__WINDOWS_MM__)
f@0 692
f@0 693 class MidiInWinMM: public MidiInApi
f@0 694 {
f@0 695 public:
f@0 696 MidiInWinMM( const std::string clientName, unsigned int queueSizeLimit );
f@0 697 ~MidiInWinMM( void );
f@0 698 RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_MM; };
f@0 699 void openPort( unsigned int portNumber, const std::string portName );
f@0 700 void openVirtualPort( const std::string portName );
f@0 701 void closePort( void );
f@0 702 unsigned int getPortCount( void );
f@0 703 std::string getPortName( unsigned int portNumber );
f@0 704
f@0 705 protected:
f@0 706 void initialize( const std::string& clientName );
f@0 707 };
f@0 708
f@0 709 class MidiOutWinMM: public MidiOutApi
f@0 710 {
f@0 711 public:
f@0 712 MidiOutWinMM( const std::string clientName );
f@0 713 ~MidiOutWinMM( void );
f@0 714 RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_MM; };
f@0 715 void openPort( unsigned int portNumber, const std::string portName );
f@0 716 void openVirtualPort( const std::string portName );
f@0 717 void closePort( void );
f@0 718 unsigned int getPortCount( void );
f@0 719 std::string getPortName( unsigned int portNumber );
f@0 720 void sendMessage( std::vector<unsigned char> *message );
f@0 721
f@0 722 protected:
f@0 723 void initialize( const std::string& clientName );
f@0 724 };
f@0 725
f@0 726 #endif
f@0 727
f@0 728 #if defined(__RTMIDI_DUMMY__)
f@0 729
f@0 730 class MidiInDummy: public MidiInApi
f@0 731 {
f@0 732 public:
f@0 733 MidiInDummy( const std::string /*clientName*/, unsigned int queueSizeLimit ) : MidiInApi( queueSizeLimit ) { errorString_ = "MidiInDummy: This class provides no functionality."; error( RtMidiError::WARNING, errorString_ ); }
f@0 734 RtMidi::Api getCurrentApi( void ) { return RtMidi::RTMIDI_DUMMY; }
f@0 735 void openPort( unsigned int /*portNumber*/, const std::string /*portName*/ ) {}
f@0 736 void openVirtualPort( const std::string /*portName*/ ) {}
f@0 737 void closePort( void ) {}
f@0 738 unsigned int getPortCount( void ) { return 0; }
f@0 739 std::string getPortName( unsigned int portNumber ) { return ""; }
f@0 740
f@0 741 protected:
f@0 742 void initialize( const std::string& /*clientName*/ ) {}
f@0 743 };
f@0 744
f@0 745 class MidiOutDummy: public MidiOutApi
f@0 746 {
f@0 747 public:
f@0 748 MidiOutDummy( const std::string /*clientName*/ ) { errorString_ = "MidiOutDummy: This class provides no functionality."; error( RtMidiError::WARNING, errorString_ ); }
f@0 749 RtMidi::Api getCurrentApi( void ) { return RtMidi::RTMIDI_DUMMY; }
f@0 750 void openPort( unsigned int /*portNumber*/, const std::string /*portName*/ ) {}
f@0 751 void openVirtualPort( const std::string /*portName*/ ) {}
f@0 752 void closePort( void ) {}
f@0 753 unsigned int getPortCount( void ) { return 0; }
f@0 754 std::string getPortName( unsigned int /*portNumber*/ ) { return ""; }
f@0 755 void sendMessage( std::vector<unsigned char> * /*message*/ ) {}
f@0 756
f@0 757 protected:
f@0 758 void initialize( const std::string& /*clientName*/ ) {}
f@0 759 };
f@0 760
f@0 761 #endif
f@0 762
f@0 763 #endif