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 "5.0.0"
99 : message_(message), type_(type) {}
105 virtual void printMessage(
void )
const throw() { std::cerr <<
'\n' << message_ <<
"\n\n"; }
108 virtual const Type&
getType(
void )
const throw() {
return type_; }
111 virtual const std::string&
getMessage(
void )
const throw() {
return message_; }
114 virtual const char*
what(
void )
const throw() {
return message_.c_str(); }
117 std::string message_;
185 virtual void openPort(
unsigned int portNumber = 0,
const std::string &portName = std::string(
"RtMidi" ) ) = 0;
188 virtual void openVirtualPort(
const std::string &portName = std::string(
"RtMidi" ) ) = 0;
194 virtual std::string
getPortName(
unsigned int portNumber = 0 ) = 0;
199 void setClientName(
const std::string &clientName );
200 void setPortName(
const std::string &portName );
260 typedef void (*RtMidiCallback)(
double timeStamp, std::vector<unsigned char> *message,
void *userData );
281 const std::string& clientName =
"RtMidi Input Client",
282 unsigned int queueSizeLimit = 100 );
298 void openPort(
unsigned int portNumber = 0,
const std::string &portName = std::string(
"RtMidi Input" ) );
310 void openVirtualPort(
const std::string &portName = std::string(
"RtMidi Input" ) );
323 void setCallback( RtMidiCallback callback,
void *userData = 0 );
330 void cancelCallback();
333 void closePort(
void );
340 virtual bool isPortOpen()
const;
346 unsigned int getPortCount();
354 std::string getPortName(
unsigned int portNumber = 0 );
364 void ignoreTypes(
bool midiSysex =
true,
bool midiTime =
true,
bool midiSense =
true );
374 double getMessage( std::vector<unsigned char> *message );
381 virtual void setErrorCallback(
RtMidiErrorCallback errorCallback = NULL,
void *userData = 0 );
394 virtual void setBufferSize(
unsigned int size,
unsigned int count );
397 void openMidiApi(
RtMidi::Api api,
const std::string &clientName,
unsigned int queueSizeLimit );
426 const std::string& clientName =
"RtMidi Output Client" );
443 void openPort(
unsigned int portNumber = 0,
const std::string &portName = std::string(
"RtMidi Output" ) );
446 void closePort(
void );
453 virtual bool isPortOpen()
const;
464 void openVirtualPort(
const std::string &portName = std::string(
"RtMidi Output" ) );
467 unsigned int getPortCount(
void );
475 std::string getPortName(
unsigned int portNumber = 0 );
482 void sendMessage(
const std::vector<unsigned char> *message );
492 void sendMessage(
const unsigned char *message,
size_t size );
499 virtual void setErrorCallback(
RtMidiErrorCallback errorCallback = NULL,
void *userData = 0 );
502 void openMidiApi(
RtMidi::Api api,
const std::string &clientName );
526 virtual void openPort(
unsigned int portNumber,
const std::string &portName ) = 0;
527 virtual void openVirtualPort(
const std::string &portName ) = 0;
528 virtual void closePort(
void ) = 0;
529 virtual void setClientName(
const std::string &clientName ) = 0;
530 virtual void setPortName(
const std::string &portName ) = 0;
532 virtual unsigned int getPortCount(
void ) = 0;
533 virtual std::string getPortName(
unsigned int portNumber ) = 0;
535 inline bool isPortOpen()
const {
return connected_; }
542 virtual void initialize(
const std::string& clientName ) = 0;
546 std::string errorString_;
548 bool firstErrorOccurred_;
549 void *errorCallbackUserData_;
557 MidiInApi(
unsigned int queueSizeLimit );
560 void cancelCallback(
void );
561 virtual void ignoreTypes(
bool midiSysex,
bool midiTime,
bool midiSense );
562 double getMessage( std::vector<unsigned char> *message );
563 virtual void setBufferSize(
unsigned int size,
unsigned int count );
568 std::vector<unsigned char> bytes;
575 : bytes(0), timeStamp(0.0) {}
581 unsigned int ringSize;
586 : front(0), back(0), ringSize(0), ring(0) {}
588 bool pop( std::vector<unsigned char>*,
double* );
589 unsigned int size(
unsigned int *back=0,
unsigned int *front=0 );
597 unsigned char ignoreFlags;
605 unsigned int bufferSize;
606 unsigned int bufferCount;
610 : ignoreFlags(7), doInput(
false), firstMessage(
true), apiData(0), usingCallback(
false),
611 userCallback(0), userData(0), continueSysex(
false), bufferSize(1024), bufferCount(4) {}
624 virtual void sendMessage(
const unsigned char *message,
size_t size ) = 0;
634inline void RtMidiIn :: openPort(
unsigned int portNumber,
const std::string &portName ) { rtapi_->openPort( portNumber, portName ); }
648inline 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:129
void error(RtMidiError::Type type, std::string errorString)
A basic error reporting function for RtMidi classes.
Exception handling class for RtMidi.
Definition: RtMidi.h:80
virtual const std::string & getMessage(void) const
Returns the thrown error message string.
Definition: RtMidi.h:111
virtual const Type & getType(void) const
Returns the thrown error message type.
Definition: RtMidi.h:108
virtual void printMessage(void) const
Prints thrown error message to stderr.
Definition: RtMidi.h:105
Type
Defined RtMidiError types.
Definition: RtMidi.h:83
@ INVALID_USE
Definition: RtMidi.h:91
@ NO_DEVICES_FOUND
Definition: RtMidi.h:87
@ MEMORY_ERROR
Definition: RtMidi.h:89
@ INVALID_PARAMETER
Definition: RtMidi.h:90
@ WARNING
Definition: RtMidi.h:84
@ INVALID_DEVICE
Definition: RtMidi.h:88
@ DRIVER_ERROR
Definition: RtMidi.h:92
@ UNSPECIFIED
Definition: RtMidi.h:86
@ DEBUG_WARNING
Definition: RtMidi.h:85
@ SYSTEM_ERROR
Definition: RtMidi.h:93
virtual ~RtMidiError(void)
The destructor.
Definition: RtMidi.h:102
virtual const char * what(void) const
Returns the thrown error message as a c-style string.
Definition: RtMidi.h:114
RtMidiError(const std::string &message, Type type=RtMidiError::UNSPECIFIED)
The constructor.
Definition: RtMidi.h:98
A realtime MIDI input class.
Definition: RtMidi.h:257
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:643
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:634
void closePort(void)
Close an open MIDI connection (if one exists).
Definition: RtMidi.h:636
unsigned int getPortCount()
Return the number of available MIDI input ports.
Definition: RtMidi.h:640
RtMidi::Api getCurrentApi(void)
Returns the MIDI API specifier for the current instance of RtMidiIn.
Definition: RtMidi.h:633
void setCallback(RtMidiCallback callback, void *userData=0)
Set a callback function to be invoked for incoming MIDI messages.
Definition: RtMidi.h:638
virtual void setBufferSize(unsigned int size, unsigned int count)
Set maximum expected incoming message size.
Definition: RtMidi.h:645
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:635
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:637
void(* RtMidiCallback)(double timeStamp, std::vector< unsigned char > *message, void *userData)
User callback function type definition.
Definition: RtMidi.h:260
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:644
void cancelCallback()
Cancel use of the current callback function (if one exists).
Definition: RtMidi.h:639
~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:641
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:642
A realtime MIDI output class.
Definition: RtMidi.h:415
unsigned int getPortCount(void)
Return the number of available MIDI output ports.
Definition: RtMidi.h:652
void sendMessage(const std::vector< unsigned char > *message)
Immediately send a single message out an open MIDI output port.
Definition: RtMidi.h:654
void openPort(unsigned int portNumber=0, const std::string &portName=std::string("RtMidi Output"))
Open a MIDI output connection.
Definition: RtMidi.h:648
RtMidi::Api getCurrentApi(void)
Returns the MIDI API specifier for the current instance of RtMidiOut.
Definition: RtMidi.h:647
void closePort(void)
Close an open MIDI connection (if one exists).
Definition: RtMidi.h:650
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:649
virtual bool isPortOpen() const
Returns true if a port is open and false if not.
Definition: RtMidi.h:651
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:656
std::string getPortName(unsigned int portNumber=0)
Return a string identifier for the specified MIDI port type and number.
Definition: RtMidi.h:653
~RtMidiOut(void)
The destructor closes any open MIDI connections.
An abstract base class for realtime MIDI input/output.
Definition: RtMidi.h:134
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:139
@ UNIX_JACK
Definition: RtMidi.h:143
@ LINUX_ALSA
Definition: RtMidi.h:142
@ WEB_MIDI_API
Definition: RtMidi.h:146
@ MACOSX_CORE
Definition: RtMidi.h:141
@ UNSPECIFIED
Definition: RtMidi.h:140
@ RTMIDI_DUMMY
Definition: RtMidi.h:145
@ WINDOWS_MM
Definition: RtMidi.h:144
double timeStamp
Time in seconds elapsed since the previous message.
Definition: RtMidi.h:571