47 #if defined _WIN32 || defined __CYGWIN__
48 #if defined(RTMIDI_EXPORT)
49 #define RTMIDI_DLL_PUBLIC __declspec(dllexport)
51 #define RTMIDI_DLL_PUBLIC
55 #define RTMIDI_DLL_PUBLIC __attribute__( (visibility( "default" )) )
57 #define RTMIDI_DLL_PUBLIC
61 #define RTMIDI_VERSION "4.0.0"
98 : message_(message), type_(type) {}
104 virtual void printMessage(
void )
const throw() { std::cerr <<
'\n' << message_ <<
"\n\n"; }
107 virtual const Type&
getType(
void )
const throw() {
return type_; }
110 virtual const std::string&
getMessage(
void )
const throw() {
return message_; }
113 virtual const char*
what(
void )
const throw() {
return message_.c_str(); }
116 std::string message_;
181 virtual void openPort(
unsigned int portNumber = 0,
const std::string &portName = std::string(
"RtMidi" ) ) = 0;
184 virtual void openVirtualPort(
const std::string &portName = std::string(
"RtMidi" ) ) = 0;
190 virtual std::string
getPortName(
unsigned int portNumber = 0 ) = 0;
195 void setClientName(
const std::string &clientName );
196 void setPortName(
const std::string &portName );
255 typedef void (*RtMidiCallback)(
double timeStamp, std::vector<unsigned char> *message,
void *userData );
276 const std::string& clientName =
"RtMidi Input Client",
277 unsigned int queueSizeLimit = 100 );
291 void openPort(
unsigned int portNumber = 0,
const std::string &portName = std::string(
"RtMidi Input" ) );
303 void openVirtualPort(
const std::string &portName = std::string(
"RtMidi Input" ) );
316 void setCallback( RtMidiCallback callback,
void *userData = 0 );
323 void cancelCallback();
326 void closePort(
void );
333 virtual bool isPortOpen()
const;
339 unsigned int getPortCount();
347 std::string getPortName(
unsigned int portNumber = 0 );
357 void ignoreTypes(
bool midiSysex =
true,
bool midiTime =
true,
bool midiSense =
true );
367 double getMessage( std::vector<unsigned char> *message );
374 virtual void setErrorCallback(
RtMidiErrorCallback errorCallback = NULL,
void *userData = 0 );
377 void openMidiApi(
RtMidi::Api api,
const std::string &clientName,
unsigned int queueSizeLimit );
408 const std::string& clientName =
"RtMidi Output Client" );
423 void openPort(
unsigned int portNumber = 0,
const std::string &portName = std::string(
"RtMidi Output" ) );
426 void closePort(
void );
433 virtual bool isPortOpen()
const;
444 void openVirtualPort(
const std::string &portName = std::string(
"RtMidi Output" ) );
447 unsigned int getPortCount(
void );
455 std::string getPortName(
unsigned int portNumber = 0 );
462 void sendMessage(
const std::vector<unsigned char> *message );
472 void sendMessage(
const unsigned char *message,
size_t size );
479 virtual void setErrorCallback(
RtMidiErrorCallback errorCallback = NULL,
void *userData = 0 );
482 void openMidiApi(
RtMidi::Api api,
const std::string &clientName );
506 virtual void openPort(
unsigned int portNumber,
const std::string &portName ) = 0;
507 virtual void openVirtualPort(
const std::string &portName ) = 0;
508 virtual void closePort(
void ) = 0;
509 virtual void setClientName(
const std::string &clientName ) = 0;
510 virtual void setPortName(
const std::string &portName ) = 0;
512 virtual unsigned int getPortCount(
void ) = 0;
513 virtual std::string getPortName(
unsigned int portNumber ) = 0;
515 inline bool isPortOpen()
const {
return connected_; }
522 virtual void initialize(
const std::string& clientName ) = 0;
526 std::string errorString_;
528 bool firstErrorOccurred_;
529 void *errorCallbackUserData_;
536 MidiInApi(
unsigned int queueSizeLimit );
539 void cancelCallback(
void );
540 virtual void ignoreTypes(
bool midiSysex,
bool midiTime,
bool midiSense );
541 double getMessage( std::vector<unsigned char> *message );
546 std::vector<unsigned char> bytes;
553 : bytes(0), timeStamp(0.0) {}
559 unsigned int ringSize;
564 : front(0), back(0), ringSize(0), ring(0) {}
566 bool pop( std::vector<unsigned char>*,
double* );
567 unsigned int size(
unsigned int *back=0,
unsigned int *front=0 );
575 unsigned char ignoreFlags;
586 : ignoreFlags(7), doInput(
false), firstMessage(
true), apiData(0), usingCallback(
false),
587 userCallback(0), userData(0), continueSysex(
false) {}
600 virtual void sendMessage(
const unsigned char *message,
size_t size ) = 0;
610 inline void RtMidiIn :: openPort(
unsigned int portNumber,
const std::string &portName ) { rtapi_->openPort( portNumber, portName ); }
623 inline void RtMidiOut :: openPort(
unsigned int portNumber,
const std::string &portName ) { rtapi_->openPort( portNumber, portName ); }
void(* RtMidiErrorCallback)(RtMidiError::Type type, const std::string &errorText, void *userData)
RtMidi error callback function prototype.
Definition: RtMidi.h:128
void error(RtMidiError::Type type, std::string errorString)
A basic error reporting function for RtMidi classes.
Exception handling class for RtMidi.
Definition: RtMidi.h:79
virtual const std::string & getMessage(void) const
Returns the thrown error message string.
Definition: RtMidi.h:110
virtual const char * what(void) const
Returns the thrown error message as a c-style string.
Definition: RtMidi.h:113
virtual void printMessage(void) const
Prints thrown error message to stderr.
Definition: RtMidi.h:104
Type
Defined RtMidiError types.
Definition: RtMidi.h:82
@ INVALID_USE
Definition: RtMidi.h:90
@ NO_DEVICES_FOUND
Definition: RtMidi.h:86
@ MEMORY_ERROR
Definition: RtMidi.h:88
@ INVALID_PARAMETER
Definition: RtMidi.h:89
@ WARNING
Definition: RtMidi.h:83
@ INVALID_DEVICE
Definition: RtMidi.h:87
@ DRIVER_ERROR
Definition: RtMidi.h:91
@ UNSPECIFIED
Definition: RtMidi.h:85
@ DEBUG_WARNING
Definition: RtMidi.h:84
@ SYSTEM_ERROR
Definition: RtMidi.h:92
virtual const Type & getType(void) const
Returns the thrown error message type.
Definition: RtMidi.h:107
virtual ~RtMidiError(void)
The destructor.
Definition: RtMidi.h:101
RtMidiError(const std::string &message, Type type=RtMidiError::UNSPECIFIED)
The constructor.
Definition: RtMidi.h:97
A realtime MIDI input class.
Definition: RtMidi.h:251
double getMessage(std::vector< unsigned char > *message)
Fill the user-provided vector with the data bytes for the next available MIDI message in the input qu...
Definition: RtMidi.h:619
void openPort(unsigned int portNumber=0, const std::string &portName=std::string("RtMidi Input"))
Open a MIDI input connection given by enumeration number.
Definition: RtMidi.h:610
void closePort(void)
Close an open MIDI connection (if one exists).
Definition: RtMidi.h:612
unsigned int getPortCount()
Return the number of available MIDI input ports.
Definition: RtMidi.h:616
RtMidi::Api getCurrentApi(void)
Returns the MIDI API specifier for the current instance of RtMidiIn.
Definition: RtMidi.h:609
void setCallback(RtMidiCallback callback, void *userData=0)
Set a callback function to be invoked for incoming MIDI messages.
Definition: RtMidi.h:614
void openVirtualPort(const std::string &portName=std::string("RtMidi Input"))
Create a virtual input port, with optional name, to allow software connections (OS X,...
Definition: RtMidi.h:611
RtMidiIn(RtMidi::Api api=UNSPECIFIED, const std::string &clientName="RtMidi Input Client", unsigned int queueSizeLimit=100)
Default constructor that allows an optional api, client name and queue size.
virtual bool isPortOpen() const
Returns true if a port is open and false if not.
Definition: RtMidi.h:613
void(* RtMidiCallback)(double timeStamp, std::vector< unsigned char > *message, void *userData)
User callback function type definition.
Definition: RtMidi.h:255
virtual void setErrorCallback(RtMidiErrorCallback errorCallback=NULL, void *userData=0)
Set an error callback function to be invoked when an error has occured.
Definition: RtMidi.h:620
void cancelCallback()
Cancel use of the current callback function (if one exists).
Definition: RtMidi.h:615
~RtMidiIn(void)
If a MIDI connection is still open, it will be closed by the destructor.
std::string getPortName(unsigned int portNumber=0)
Return a string identifier for the specified MIDI input port number.
Definition: RtMidi.h:617
void ignoreTypes(bool midiSysex=true, bool midiTime=true, bool midiSense=true)
Specify whether certain MIDI message types should be queued or ignored during input.
Definition: RtMidi.h:618
A realtime MIDI output class.
Definition: RtMidi.h:397
unsigned int getPortCount(void)
Return the number of available MIDI output ports.
Definition: RtMidi.h:627
void sendMessage(const std::vector< unsigned char > *message)
Immediately send a single message out an open MIDI output port.
Definition: RtMidi.h:629
void openPort(unsigned int portNumber=0, const std::string &portName=std::string("RtMidi Output"))
Open a MIDI output connection.
Definition: RtMidi.h:623
RtMidi::Api getCurrentApi(void)
Returns the MIDI API specifier for the current instance of RtMidiOut.
Definition: RtMidi.h:622
void closePort(void)
Close an open MIDI connection (if one exists).
Definition: RtMidi.h:625
RtMidiOut(RtMidi::Api api=UNSPECIFIED, const std::string &clientName="RtMidi Output Client")
Default constructor that allows an optional client name.
void openVirtualPort(const std::string &portName=std::string("RtMidi Output"))
Create a virtual output port, with optional name, to allow software connections (OS X,...
Definition: RtMidi.h:624
virtual bool isPortOpen() const
Returns true if a port is open and false if not.
Definition: RtMidi.h:626
virtual void setErrorCallback(RtMidiErrorCallback errorCallback=NULL, void *userData=0)
Set an error callback function to be invoked when an error has occured.
Definition: RtMidi.h:631
std::string getPortName(unsigned int portNumber=0)
Return a string identifier for the specified MIDI port type and number.
Definition: RtMidi.h:628
~RtMidiOut(void)
The destructor closes any open MIDI connections.
An abstract base class for realtime MIDI input/output.
Definition: RtMidi.h:133
static void getCompiledApi(std::vector< RtMidi::Api > &apis)
A static function to determine the available compiled MIDI APIs.
virtual void openVirtualPort(const std::string &portName=std::string("RtMidi"))=0
Pure virtual openVirtualPort() function.
virtual void closePort(void)=0
Pure virtual closePort() function.
virtual void openPort(unsigned int portNumber=0, const std::string &portName=std::string("RtMidi"))=0
Pure virtual openPort() function.
static std::string getApiDisplayName(RtMidi::Api api)
Return the display name of a specified compiled MIDI API.
virtual bool isPortOpen(void) const =0
Returns true if a port is open and false if not.
static std::string getApiName(RtMidi::Api api)
Return the name of a specified compiled MIDI API.
virtual std::string getPortName(unsigned int portNumber=0)=0
Pure virtual getPortName() function.
static std::string getVersion(void)
A static function to determine the current RtMidi version.
virtual unsigned int getPortCount()=0
Pure virtual getPortCount() function.
static RtMidi::Api getCompiledApiByName(const std::string &name)
Return the compiled MIDI API having the given name.
virtual void setErrorCallback(RtMidiErrorCallback errorCallback=NULL, void *userData=0)=0
Set an error callback function to be invoked when an error has occured.
Api
MIDI API specifier arguments.
Definition: RtMidi.h:136
@ UNIX_JACK
Definition: RtMidi.h:140
@ LINUX_ALSA
Definition: RtMidi.h:139
@ MACOSX_CORE
Definition: RtMidi.h:138
@ UNSPECIFIED
Definition: RtMidi.h:137
@ RTMIDI_DUMMY
Definition: RtMidi.h:142
@ WINDOWS_MM
Definition: RtMidi.h:141
double timeStamp
Time in seconds elapsed since the previous message.
Definition: RtMidi.h:549