f@0: /**********************************************************************/ f@0: /*! \class RtMidi f@0: \brief An abstract base class for realtime MIDI input/output. f@0: f@0: This class implements some common functionality for the realtime f@0: MIDI input/output subclasses RtMidiIn and RtMidiOut. f@0: f@0: RtMidi WWW site: http://music.mcgill.ca/~gary/rtmidi/ f@0: f@0: RtMidi: realtime MIDI i/o C++ classes f@0: Copyright (c) 2003-2016 Gary P. Scavone f@0: f@0: Permission is hereby granted, free of charge, to any person f@0: obtaining a copy of this software and associated documentation files f@0: (the "Software"), to deal in the Software without restriction, f@0: including without limitation the rights to use, copy, modify, merge, f@0: publish, distribute, sublicense, and/or sell copies of the Software, f@0: and to permit persons to whom the Software is furnished to do so, f@0: subject to the following conditions: f@0: f@0: The above copyright notice and this permission notice shall be f@0: included in all copies or substantial portions of the Software. f@0: f@0: Any person wishing to distribute modifications to the Software is f@0: asked to send the modifications to the original developer so that f@0: they can be incorporated into the canonical version. This is, f@0: however, not a binding provision of this license. f@0: f@0: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, f@0: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF f@0: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. f@0: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR f@0: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF f@0: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION f@0: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. f@0: */ f@0: /**********************************************************************/ f@0: f@0: /*! f@0: \file RtMidi.h f@0: */ f@0: f@0: #ifndef RTMIDI_H f@0: #define RTMIDI_H f@0: f@0: #define RTMIDI_VERSION "2.1.1" f@0: f@0: #include f@0: #include f@0: #include f@0: #include f@0: f@0: /************************************************************************/ f@0: /*! \class RtMidiError f@0: \brief Exception handling class for RtMidi. f@0: f@0: The RtMidiError class is quite simple but it does allow errors to be f@0: "caught" by RtMidiError::Type. See the RtMidi documentation to know f@0: which methods can throw an RtMidiError. f@0: */ f@0: /************************************************************************/ f@0: f@0: class RtMidiError : public std::exception f@0: { f@0: public: f@0: //! Defined RtMidiError types. f@0: enum Type { f@0: WARNING, /*!< A non-critical error. */ f@0: DEBUG_WARNING, /*!< A non-critical error which might be useful for debugging. */ f@0: UNSPECIFIED, /*!< The default, unspecified error type. */ f@0: NO_DEVICES_FOUND, /*!< No devices found on system. */ f@0: INVALID_DEVICE, /*!< An invalid device ID was specified. */ f@0: MEMORY_ERROR, /*!< An error occured during memory allocation. */ f@0: INVALID_PARAMETER, /*!< An invalid parameter was specified to a function. */ f@0: INVALID_USE, /*!< The function was called incorrectly. */ f@0: DRIVER_ERROR, /*!< A system driver error occured. */ f@0: SYSTEM_ERROR, /*!< A system error occured. */ f@0: THREAD_ERROR /*!< A thread error occured. */ f@0: }; f@0: f@0: //! The constructor. f@0: RtMidiError( const std::string& message, Type type = RtMidiError::UNSPECIFIED ) throw() : message_(message), type_(type) {} f@0: f@0: //! The destructor. f@0: virtual ~RtMidiError( void ) throw() {} f@0: f@0: //! Prints thrown error message to stderr. f@0: virtual void printMessage( void ) const throw() { std::cerr << '\n' << message_ << "\n\n"; } f@0: f@0: //! Returns the thrown error message type. f@0: virtual const Type& getType(void) const throw() { return type_; } f@0: f@0: //! Returns the thrown error message string. f@0: virtual const std::string& getMessage(void) const throw() { return message_; } f@0: f@0: //! Returns the thrown error message as a c-style string. f@0: virtual const char* what( void ) const throw() { return message_.c_str(); } f@0: f@0: protected: f@0: std::string message_; f@0: Type type_; f@0: }; f@0: f@0: //! RtMidi error callback function prototype. f@0: /*! f@0: \param type Type of error. f@0: \param errorText Error description. f@0: f@0: Note that class behaviour is undefined after a critical error (not f@0: a warning) is reported. f@0: */ f@0: typedef void (*RtMidiErrorCallback)( RtMidiError::Type type, const std::string &errorText, void *userData ); f@0: f@0: class MidiApi; f@0: f@0: class RtMidi f@0: { f@0: public: f@0: f@0: //! MIDI API specifier arguments. f@0: enum Api { f@0: UNSPECIFIED, /*!< Search for a working compiled API. */ f@0: MACOSX_CORE, /*!< Macintosh OS-X Core Midi API. */ f@0: LINUX_ALSA, /*!< The Advanced Linux Sound Architecture API. */ f@0: UNIX_JACK, /*!< The JACK Low-Latency MIDI Server API. */ f@0: WINDOWS_MM, /*!< The Microsoft Multimedia MIDI API. */ f@0: RTMIDI_DUMMY /*!< A compilable but non-functional API. */ f@0: }; f@0: f@0: //! A static function to determine the current RtMidi version. f@0: static std::string getVersion( void ) throw(); f@0: f@0: //! A static function to determine the available compiled MIDI APIs. f@0: /*! f@0: The values returned in the std::vector can be compared against f@0: the enumerated list values. Note that there can be more than one f@0: API compiled for certain operating systems. f@0: */ f@0: static void getCompiledApi( std::vector &apis ) throw(); f@0: f@0: //! Pure virtual openPort() function. f@0: virtual void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi" ) ) = 0; f@0: f@0: //! Pure virtual openVirtualPort() function. f@0: virtual void openVirtualPort( const std::string portName = std::string( "RtMidi" ) ) = 0; f@0: f@0: //! Pure virtual getPortCount() function. f@0: virtual unsigned int getPortCount() = 0; f@0: f@0: //! Pure virtual getPortName() function. f@0: virtual std::string getPortName( unsigned int portNumber = 0 ) = 0; f@0: f@0: //! Pure virtual closePort() function. f@0: virtual void closePort( void ) = 0; f@0: f@0: //! Returns true if a port is open and false if not. f@0: virtual bool isPortOpen( void ) const = 0; f@0: f@0: //! Set an error callback function to be invoked when an error has occured. f@0: /*! f@0: The callback function will be called whenever an error has occured. It is best f@0: to set the error callback function before opening a port. f@0: */ f@0: virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 ) = 0; f@0: f@0: protected: f@0: f@0: RtMidi(); f@0: virtual ~RtMidi(); f@0: f@0: MidiApi *rtapi_; f@0: }; f@0: f@0: /**********************************************************************/ f@0: /*! \class RtMidiIn f@0: \brief A realtime MIDI input class. f@0: f@0: This class provides a common, platform-independent API for f@0: realtime MIDI input. It allows access to a single MIDI input f@0: port. Incoming MIDI messages are either saved to a queue for f@0: retrieval using the getMessage() function or immediately passed to f@0: a user-specified callback function. Create multiple instances of f@0: this class to connect to more than one MIDI device at the same f@0: time. With the OS-X, Linux ALSA, and JACK MIDI APIs, it is also f@0: possible to open a virtual input port to which other MIDI software f@0: clients can connect. f@0: f@0: by Gary P. Scavone, 2003-2014. f@0: */ f@0: /**********************************************************************/ f@0: f@0: // **************************************************************** // f@0: // f@0: // RtMidiIn and RtMidiOut class declarations. f@0: // f@0: // RtMidiIn / RtMidiOut are "controllers" used to select an available f@0: // MIDI input or output interface. They present common APIs for the f@0: // user to call but all functionality is implemented by the classes f@0: // MidiInApi, MidiOutApi and their subclasses. RtMidiIn and RtMidiOut f@0: // each create an instance of a MidiInApi or MidiOutApi subclass based f@0: // on the user's API choice. If no choice is made, they attempt to f@0: // make a "logical" API selection. f@0: // f@0: // **************************************************************** // f@0: f@0: class RtMidiIn : public RtMidi f@0: { f@0: public: f@0: f@0: //! User callback function type definition. f@0: typedef void (*RtMidiCallback)( double timeStamp, std::vector *message, void *userData); f@0: f@0: //! Default constructor that allows an optional api, client name and queue size. f@0: /*! f@0: An exception will be thrown if a MIDI system initialization f@0: error occurs. The queue size defines the maximum number of f@0: messages that can be held in the MIDI queue (when not using a f@0: callback function). If the queue size limit is reached, f@0: incoming messages will be ignored. f@0: f@0: If no API argument is specified and multiple API support has been f@0: compiled, the default order of use is ALSA, JACK (Linux) and CORE, f@0: JACK (OS-X). f@0: f@0: \param api An optional API id can be specified. f@0: \param clientName An optional client name can be specified. This f@0: will be used to group the ports that are created f@0: by the application. f@0: \param queueSizeLimit An optional size of the MIDI input queue can be specified. f@0: */ f@0: RtMidiIn( RtMidi::Api api=UNSPECIFIED, f@0: const std::string clientName = std::string( "RtMidi Input Client"), f@0: unsigned int queueSizeLimit = 100 ); f@0: f@0: //! If a MIDI connection is still open, it will be closed by the destructor. f@0: ~RtMidiIn ( void ) throw(); f@0: f@0: //! Returns the MIDI API specifier for the current instance of RtMidiIn. f@0: RtMidi::Api getCurrentApi( void ) throw(); f@0: f@0: //! Open a MIDI input connection given by enumeration number. f@0: /*! f@0: \param portNumber An optional port number greater than 0 can be specified. f@0: Otherwise, the default or first port found is opened. f@0: \param portName An optional name for the application port that is used to connect to portId can be specified. f@0: */ f@0: void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Input" ) ); f@0: f@0: //! Create a virtual input port, with optional name, to allow software connections (OS X, JACK and ALSA only). f@0: /*! f@0: This function creates a virtual MIDI input port to which other f@0: software applications can connect. This type of functionality f@0: is currently only supported by the Macintosh OS-X, any JACK, f@0: and Linux ALSA APIs (the function returns an error for the other APIs). f@0: f@0: \param portName An optional name for the application port that is f@0: used to connect to portId can be specified. f@0: */ f@0: void openVirtualPort( const std::string portName = std::string( "RtMidi Input" ) ); f@0: f@0: //! Set a callback function to be invoked for incoming MIDI messages. f@0: /*! f@0: The callback function will be called whenever an incoming MIDI f@0: message is received. While not absolutely necessary, it is best f@0: to set the callback function before opening a MIDI port to avoid f@0: leaving some messages in the queue. f@0: f@0: \param callback A callback function must be given. f@0: \param userData Optionally, a pointer to additional data can be f@0: passed to the callback function whenever it is called. f@0: */ f@0: void setCallback( RtMidiCallback callback, void *userData = 0 ); f@0: f@0: //! Cancel use of the current callback function (if one exists). f@0: /*! f@0: Subsequent incoming MIDI messages will be written to the queue f@0: and can be retrieved with the \e getMessage function. f@0: */ f@0: void cancelCallback(); f@0: f@0: //! Close an open MIDI connection (if one exists). f@0: void closePort( void ); f@0: f@0: //! Returns true if a port is open and false if not. f@0: virtual bool isPortOpen() const; f@0: f@0: //! Return the number of available MIDI input ports. f@0: /*! f@0: \return This function returns the number of MIDI ports of the selected API. f@0: */ f@0: unsigned int getPortCount(); f@0: f@0: //! Return a string identifier for the specified MIDI input port number. f@0: /*! f@0: \return The name of the port with the given Id is returned. f@0: \retval An empty string is returned if an invalid port specifier is provided. f@0: */ f@0: std::string getPortName( unsigned int portNumber = 0 ); f@0: f@0: //! Specify whether certain MIDI message types should be queued or ignored during input. f@0: /*! f@0: By default, MIDI timing and active sensing messages are ignored f@0: during message input because of their relative high data rates. f@0: MIDI sysex messages are ignored by default as well. Variable f@0: values of "true" imply that the respective message type will be f@0: ignored. f@0: */ f@0: void ignoreTypes( bool midiSysex = true, bool midiTime = true, bool midiSense = true ); f@0: f@0: //! 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: /*! f@0: This function returns immediately whether a new message is f@0: available or not. A valid message is indicated by a non-zero f@0: vector size. An exception is thrown if an error occurs during f@0: message retrieval or an input connection was not previously f@0: established. f@0: */ f@0: double getMessage( std::vector *message ); f@0: f@0: //! Set an error callback function to be invoked when an error has occured. f@0: /*! f@0: The callback function will be called whenever an error has occured. It is best f@0: to set the error callback function before opening a port. f@0: */ f@0: virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 ); f@0: f@0: protected: f@0: void openMidiApi( RtMidi::Api api, const std::string clientName, unsigned int queueSizeLimit ); f@0: f@0: }; f@0: f@0: /**********************************************************************/ f@0: /*! \class RtMidiOut f@0: \brief A realtime MIDI output class. f@0: f@0: This class provides a common, platform-independent API for MIDI f@0: output. It allows one to probe available MIDI output ports, to f@0: connect to one such port, and to send MIDI bytes immediately over f@0: the connection. Create multiple instances of this class to f@0: connect to more than one MIDI device at the same time. With the f@0: OS-X, Linux ALSA and JACK MIDI APIs, it is also possible to open a f@0: virtual port to which other MIDI software clients can connect. f@0: f@0: by Gary P. Scavone, 2003-2014. f@0: */ f@0: /**********************************************************************/ f@0: f@0: class RtMidiOut : public RtMidi f@0: { f@0: public: f@0: f@0: //! Default constructor that allows an optional client name. f@0: /*! f@0: An exception will be thrown if a MIDI system initialization error occurs. f@0: f@0: If no API argument is specified and multiple API support has been f@0: compiled, the default order of use is ALSA, JACK (Linux) and CORE, f@0: JACK (OS-X). f@0: */ f@0: RtMidiOut( RtMidi::Api api=UNSPECIFIED, f@0: const std::string clientName = std::string( "RtMidi Output Client") ); f@0: f@0: //! The destructor closes any open MIDI connections. f@0: ~RtMidiOut( void ) throw(); f@0: f@0: //! Returns the MIDI API specifier for the current instance of RtMidiOut. f@0: RtMidi::Api getCurrentApi( void ) throw(); f@0: f@0: //! Open a MIDI output connection. f@0: /*! f@0: An optional port number greater than 0 can be specified. f@0: Otherwise, the default or first port found is opened. An f@0: exception is thrown if an error occurs while attempting to make f@0: the port connection. f@0: */ f@0: void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Output" ) ); f@0: f@0: //! Close an open MIDI connection (if one exists). f@0: void closePort( void ); f@0: f@0: //! Returns true if a port is open and false if not. f@0: virtual bool isPortOpen() const; f@0: f@0: //! Create a virtual output port, with optional name, to allow software connections (OS X, JACK and ALSA only). f@0: /*! f@0: This function creates a virtual MIDI output port to which other f@0: software applications can connect. This type of functionality f@0: is currently only supported by the Macintosh OS-X, Linux ALSA f@0: and JACK APIs (the function does nothing with the other APIs). f@0: An exception is thrown if an error occurs while attempting to f@0: create the virtual port. f@0: */ f@0: void openVirtualPort( const std::string portName = std::string( "RtMidi Output" ) ); f@0: f@0: //! Return the number of available MIDI output ports. f@0: unsigned int getPortCount( void ); f@0: f@0: //! Return a string identifier for the specified MIDI port type and number. f@0: /*! f@0: An empty string is returned if an invalid port specifier is provided. f@0: */ f@0: std::string getPortName( unsigned int portNumber = 0 ); f@0: f@0: //! Immediately send a single message out an open MIDI output port. f@0: /*! f@0: An exception is thrown if an error occurs during output or an f@0: output connection was not previously established. f@0: */ f@0: void sendMessage( std::vector *message ); f@0: f@0: //! Set an error callback function to be invoked when an error has occured. f@0: /*! f@0: The callback function will be called whenever an error has occured. It is best f@0: to set the error callback function before opening a port. f@0: */ f@0: virtual void setErrorCallback( RtMidiErrorCallback errorCallback = NULL, void *userData = 0 ); f@0: f@0: protected: f@0: void openMidiApi( RtMidi::Api api, const std::string clientName ); f@0: }; f@0: f@0: f@0: // **************************************************************** // f@0: // f@0: // MidiInApi / MidiOutApi class declarations. f@0: // f@0: // Subclasses of MidiInApi and MidiOutApi contain all API- and f@0: // OS-specific code necessary to fully implement the RtMidi API. f@0: // f@0: // Note that MidiInApi and MidiOutApi are abstract base classes and f@0: // cannot be explicitly instantiated. RtMidiIn and RtMidiOut will f@0: // create instances of a MidiInApi or MidiOutApi subclass. f@0: // f@0: // **************************************************************** // f@0: f@0: class MidiApi f@0: { f@0: public: f@0: f@0: MidiApi(); f@0: virtual ~MidiApi(); f@0: virtual RtMidi::Api getCurrentApi( void ) = 0; f@0: virtual void openPort( unsigned int portNumber, const std::string portName ) = 0; f@0: virtual void openVirtualPort( const std::string portName ) = 0; f@0: virtual void closePort( void ) = 0; f@0: f@0: virtual unsigned int getPortCount( void ) = 0; f@0: virtual std::string getPortName( unsigned int portNumber ) = 0; f@0: f@0: inline bool isPortOpen() const { return connected_; } f@0: void setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ); f@0: f@0: //! A basic error reporting function for RtMidi classes. f@0: void error( RtMidiError::Type type, std::string errorString ); f@0: f@0: protected: f@0: virtual void initialize( const std::string& clientName ) = 0; f@0: f@0: void *apiData_; f@0: bool connected_; f@0: std::string errorString_; f@0: RtMidiErrorCallback errorCallback_; f@0: bool firstErrorOccurred_; f@0: void *errorCallbackUserData_; f@0: }; f@0: f@0: class MidiInApi : public MidiApi f@0: { f@0: public: f@0: f@0: MidiInApi( unsigned int queueSizeLimit ); f@0: virtual ~MidiInApi( void ); f@0: void setCallback( RtMidiIn::RtMidiCallback callback, void *userData ); f@0: void cancelCallback( void ); f@0: virtual void ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ); f@0: double getMessage( std::vector *message ); f@0: f@0: // A MIDI structure used internally by the class to store incoming f@0: // messages. Each message represents one and only one MIDI message. f@0: struct MidiMessage { f@0: std::vector bytes; f@0: double timeStamp; f@0: f@0: // Default constructor. f@0: MidiMessage() f@0: :bytes(0), timeStamp(0.0) {} f@0: }; f@0: f@0: struct MidiQueue { f@0: unsigned int front; f@0: unsigned int back; f@0: unsigned int size; f@0: unsigned int ringSize; f@0: MidiMessage *ring; f@0: f@0: // Default constructor. f@0: MidiQueue() f@0: :front(0), back(0), size(0), ringSize(0) {} f@0: }; f@0: f@0: // The RtMidiInData structure is used to pass private class data to f@0: // the MIDI input handling function or thread. f@0: struct RtMidiInData { f@0: MidiQueue queue; f@0: MidiMessage message; f@0: unsigned char ignoreFlags; f@0: bool doInput; f@0: bool firstMessage; f@0: void *apiData; f@0: bool usingCallback; f@0: RtMidiIn::RtMidiCallback userCallback; f@0: void *userData; f@0: bool continueSysex; f@0: f@0: // Default constructor. f@0: RtMidiInData() f@0: : ignoreFlags(7), doInput(false), firstMessage(true), f@0: apiData(0), usingCallback(false), userCallback(0), userData(0), f@0: continueSysex(false) {} f@0: }; f@0: f@0: protected: f@0: RtMidiInData inputData_; f@0: }; f@0: f@0: class MidiOutApi : public MidiApi f@0: { f@0: public: f@0: f@0: MidiOutApi( void ); f@0: virtual ~MidiOutApi( void ); f@0: virtual void sendMessage( std::vector *message ) = 0; f@0: }; f@0: f@0: // **************************************************************** // f@0: // f@0: // Inline RtMidiIn and RtMidiOut definitions. f@0: // f@0: // **************************************************************** // f@0: f@0: inline RtMidi::Api RtMidiIn :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); } f@0: inline void RtMidiIn :: openPort( unsigned int portNumber, const std::string portName ) { rtapi_->openPort( portNumber, portName ); } f@0: inline void RtMidiIn :: openVirtualPort( const std::string portName ) { rtapi_->openVirtualPort( portName ); } f@0: inline void RtMidiIn :: closePort( void ) { rtapi_->closePort(); } f@0: inline bool RtMidiIn :: isPortOpen() const { return rtapi_->isPortOpen(); } f@0: inline void RtMidiIn :: setCallback( RtMidiCallback callback, void *userData ) { ((MidiInApi *)rtapi_)->setCallback( callback, userData ); } f@0: inline void RtMidiIn :: cancelCallback( void ) { ((MidiInApi *)rtapi_)->cancelCallback(); } f@0: inline unsigned int RtMidiIn :: getPortCount( void ) { return rtapi_->getPortCount(); } f@0: inline std::string RtMidiIn :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); } f@0: inline void RtMidiIn :: ignoreTypes( bool midiSysex, bool midiTime, bool midiSense ) { ((MidiInApi *)rtapi_)->ignoreTypes( midiSysex, midiTime, midiSense ); } f@0: inline double RtMidiIn :: getMessage( std::vector *message ) { return ((MidiInApi *)rtapi_)->getMessage( message ); } f@0: inline void RtMidiIn :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); } f@0: f@0: inline RtMidi::Api RtMidiOut :: getCurrentApi( void ) throw() { return rtapi_->getCurrentApi(); } f@0: inline void RtMidiOut :: openPort( unsigned int portNumber, const std::string portName ) { rtapi_->openPort( portNumber, portName ); } f@0: inline void RtMidiOut :: openVirtualPort( const std::string portName ) { rtapi_->openVirtualPort( portName ); } f@0: inline void RtMidiOut :: closePort( void ) { rtapi_->closePort(); } f@0: inline bool RtMidiOut :: isPortOpen() const { return rtapi_->isPortOpen(); } f@0: inline unsigned int RtMidiOut :: getPortCount( void ) { return rtapi_->getPortCount(); } f@0: inline std::string RtMidiOut :: getPortName( unsigned int portNumber ) { return rtapi_->getPortName( portNumber ); } f@0: inline void RtMidiOut :: sendMessage( std::vector *message ) { ((MidiOutApi *)rtapi_)->sendMessage( message ); } f@0: inline void RtMidiOut :: setErrorCallback( RtMidiErrorCallback errorCallback, void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); } f@0: f@0: // **************************************************************** // f@0: // f@0: // MidiInApi and MidiOutApi subclass prototypes. f@0: // f@0: // **************************************************************** // f@0: f@0: #if !defined(__LINUX_ALSA__) && !defined(__UNIX_JACK__) && !defined(__MACOSX_CORE__) && !defined(__WINDOWS_MM__) f@0: #define __RTMIDI_DUMMY__ f@0: #endif f@0: f@0: #if defined(__MACOSX_CORE__) f@0: f@0: class MidiInCore: public MidiInApi f@0: { f@0: public: f@0: MidiInCore( const std::string clientName, unsigned int queueSizeLimit ); f@0: ~MidiInCore( void ); f@0: RtMidi::Api getCurrentApi( void ) { return RtMidi::MACOSX_CORE; }; f@0: void openPort( unsigned int portNumber, const std::string portName ); f@0: void openVirtualPort( const std::string portName ); f@0: void closePort( void ); f@0: unsigned int getPortCount( void ); f@0: std::string getPortName( unsigned int portNumber ); f@0: f@0: protected: f@0: void initialize( const std::string& clientName ); f@0: }; f@0: f@0: class MidiOutCore: public MidiOutApi f@0: { f@0: public: f@0: MidiOutCore( const std::string clientName ); f@0: ~MidiOutCore( void ); f@0: RtMidi::Api getCurrentApi( void ) { return RtMidi::MACOSX_CORE; }; f@0: void openPort( unsigned int portNumber, const std::string portName ); f@0: void openVirtualPort( const std::string portName ); f@0: void closePort( void ); f@0: unsigned int getPortCount( void ); f@0: std::string getPortName( unsigned int portNumber ); f@0: void sendMessage( std::vector *message ); f@0: f@0: protected: f@0: void initialize( const std::string& clientName ); f@0: }; f@0: f@0: #endif f@0: f@0: #if defined(__UNIX_JACK__) f@0: f@0: class MidiInJack: public MidiInApi f@0: { f@0: public: f@0: MidiInJack( const std::string clientName, unsigned int queueSizeLimit ); f@0: ~MidiInJack( void ); f@0: RtMidi::Api getCurrentApi( void ) { return RtMidi::UNIX_JACK; }; f@0: void openPort( unsigned int portNumber, const std::string portName ); f@0: void openVirtualPort( const std::string portName ); f@0: void closePort( void ); f@0: unsigned int getPortCount( void ); f@0: std::string getPortName( unsigned int portNumber ); f@0: f@0: protected: f@0: std::string clientName; f@0: f@0: void connect( void ); f@0: void initialize( const std::string& clientName ); f@0: }; f@0: f@0: class MidiOutJack: public MidiOutApi f@0: { f@0: public: f@0: MidiOutJack( const std::string clientName ); f@0: ~MidiOutJack( void ); f@0: RtMidi::Api getCurrentApi( void ) { return RtMidi::UNIX_JACK; }; f@0: void openPort( unsigned int portNumber, const std::string portName ); f@0: void openVirtualPort( const std::string portName ); f@0: void closePort( void ); f@0: unsigned int getPortCount( void ); f@0: std::string getPortName( unsigned int portNumber ); f@0: void sendMessage( std::vector *message ); f@0: f@0: protected: f@0: std::string clientName; f@0: f@0: void connect( void ); f@0: void initialize( const std::string& clientName ); f@0: }; f@0: f@0: #endif f@0: f@0: #if defined(__LINUX_ALSA__) f@0: f@0: class MidiInAlsa: public MidiInApi f@0: { f@0: public: f@0: MidiInAlsa( const std::string clientName, unsigned int queueSizeLimit ); f@0: ~MidiInAlsa( void ); f@0: RtMidi::Api getCurrentApi( void ) { return RtMidi::LINUX_ALSA; }; f@0: void openPort( unsigned int portNumber, const std::string portName ); f@0: void openVirtualPort( const std::string portName ); f@0: void closePort( void ); f@0: unsigned int getPortCount( void ); f@0: std::string getPortName( unsigned int portNumber ); f@0: f@0: protected: f@0: void initialize( const std::string& clientName ); f@0: }; f@0: f@0: class MidiOutAlsa: public MidiOutApi f@0: { f@0: public: f@0: MidiOutAlsa( const std::string clientName ); f@0: ~MidiOutAlsa( void ); f@0: RtMidi::Api getCurrentApi( void ) { return RtMidi::LINUX_ALSA; }; f@0: void openPort( unsigned int portNumber, const std::string portName ); f@0: void openVirtualPort( const std::string portName ); f@0: void closePort( void ); f@0: unsigned int getPortCount( void ); f@0: std::string getPortName( unsigned int portNumber ); f@0: void sendMessage( std::vector *message ); f@0: f@0: protected: f@0: void initialize( const std::string& clientName ); f@0: }; f@0: f@0: #endif f@0: f@0: #if defined(__WINDOWS_MM__) f@0: f@0: class MidiInWinMM: public MidiInApi f@0: { f@0: public: f@0: MidiInWinMM( const std::string clientName, unsigned int queueSizeLimit ); f@0: ~MidiInWinMM( void ); f@0: RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_MM; }; f@0: void openPort( unsigned int portNumber, const std::string portName ); f@0: void openVirtualPort( const std::string portName ); f@0: void closePort( void ); f@0: unsigned int getPortCount( void ); f@0: std::string getPortName( unsigned int portNumber ); f@0: f@0: protected: f@0: void initialize( const std::string& clientName ); f@0: }; f@0: f@0: class MidiOutWinMM: public MidiOutApi f@0: { f@0: public: f@0: MidiOutWinMM( const std::string clientName ); f@0: ~MidiOutWinMM( void ); f@0: RtMidi::Api getCurrentApi( void ) { return RtMidi::WINDOWS_MM; }; f@0: void openPort( unsigned int portNumber, const std::string portName ); f@0: void openVirtualPort( const std::string portName ); f@0: void closePort( void ); f@0: unsigned int getPortCount( void ); f@0: std::string getPortName( unsigned int portNumber ); f@0: void sendMessage( std::vector *message ); f@0: f@0: protected: f@0: void initialize( const std::string& clientName ); f@0: }; f@0: f@0: #endif f@0: f@0: #if defined(__RTMIDI_DUMMY__) f@0: f@0: class MidiInDummy: public MidiInApi f@0: { f@0: public: f@0: MidiInDummy( const std::string /*clientName*/, unsigned int queueSizeLimit ) : MidiInApi( queueSizeLimit ) { errorString_ = "MidiInDummy: This class provides no functionality."; error( RtMidiError::WARNING, errorString_ ); } f@0: RtMidi::Api getCurrentApi( void ) { return RtMidi::RTMIDI_DUMMY; } f@0: void openPort( unsigned int /*portNumber*/, const std::string /*portName*/ ) {} f@0: void openVirtualPort( const std::string /*portName*/ ) {} f@0: void closePort( void ) {} f@0: unsigned int getPortCount( void ) { return 0; } f@0: std::string getPortName( unsigned int portNumber ) { return ""; } f@0: f@0: protected: f@0: void initialize( const std::string& /*clientName*/ ) {} f@0: }; f@0: f@0: class MidiOutDummy: public MidiOutApi f@0: { f@0: public: f@0: MidiOutDummy( const std::string /*clientName*/ ) { errorString_ = "MidiOutDummy: This class provides no functionality."; error( RtMidiError::WARNING, errorString_ ); } f@0: RtMidi::Api getCurrentApi( void ) { return RtMidi::RTMIDI_DUMMY; } f@0: void openPort( unsigned int /*portNumber*/, const std::string /*portName*/ ) {} f@0: void openVirtualPort( const std::string /*portName*/ ) {} f@0: void closePort( void ) {} f@0: unsigned int getPortCount( void ) { return 0; } f@0: std::string getPortName( unsigned int /*portNumber*/ ) { return ""; } f@0: void sendMessage( std::vector * /*message*/ ) {} f@0: f@0: protected: f@0: void initialize( const std::string& /*clientName*/ ) {} f@0: }; f@0: f@0: #endif f@0: f@0: #endif