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_MAJOR 6
62#define RTMIDI_VERSION_MINOR 0
63#define RTMIDI_VERSION_PATCH 0
64#define RTMIDI_VERSION_BETA 0
66#define RTMIDI_TOSTRING2(n) #n
67#define RTMIDI_TOSTRING(n) RTMIDI_TOSTRING2(n)
69#if RTMIDI_VERSION_BETA > 0
70 #define RTMIDI_VERSION RTMIDI_TOSTRING(RTMIDI_VERSION_MAJOR) \
71 "." RTMIDI_TOSTRING(RTMIDI_VERSION_MINOR) \
72 "." RTMIDI_TOSTRING(RTMIDI_VERSION_PATCH) \
73 "beta" RTMIDI_TOSTRING(RTMIDI_VERSION_BETA)
75 #define RTMIDI_VERSION RTMIDI_TOSTRING(RTMIDI_VERSION_MAJOR) \
76 "." RTMIDI_TOSTRING(RTMIDI_VERSION_MINOR) \
77 "." RTMIDI_TOSTRING(RTMIDI_VERSION_PATCH)
116 : message_(message), type_(type) {}
122 virtual void printMessage(
void )
const throw() { std::cerr <<
'\n' << message_ <<
"\n\n"; }
125 virtual const Type&
getType(
void )
const throw() {
return type_; }
128 virtual const std::string&
getMessage(
void )
const throw() {
return message_; }
131 virtual const char*
what(
void )
const throw() {
return message_.c_str(); }
134 std::string message_;
204 virtual void openPort(
unsigned int portNumber = 0,
const std::string &portName = std::string(
"RtMidi" ) ) = 0;
207 virtual void openVirtualPort(
const std::string &portName = std::string(
"RtMidi" ) ) = 0;
213 virtual std::string
getPortName(
unsigned int portNumber = 0 ) = 0;
218 void setClientName(
const std::string &clientName );
219 void setPortName(
const std::string &portName );
279 typedef void (*RtMidiCallback)(
double timeStamp, std::vector<unsigned char> *message,
void *userData );
300 const std::string& clientName =
"RtMidi Input Client",
301 unsigned int queueSizeLimit = 100 );
317 void openPort(
unsigned int portNumber = 0,
const std::string &portName = std::string(
"RtMidi Input" ) );
329 void openVirtualPort(
const std::string &portName = std::string(
"RtMidi Input" ) );
342 void setCallback( RtMidiCallback callback,
void *userData = 0 );
349 void cancelCallback();
352 void closePort(
void );
359 virtual bool isPortOpen()
const;
365 unsigned int getPortCount();
373 std::string getPortName(
unsigned int portNumber = 0 );
383 void ignoreTypes(
bool midiSysex =
true,
bool midiTime =
true,
bool midiSense =
true );
393 double getMessage( std::vector<unsigned char> *message );
400 virtual void setErrorCallback(
RtMidiErrorCallback errorCallback = NULL,
void *userData = 0 );
413 virtual void setBufferSize(
unsigned int size,
unsigned int count );
416 void openMidiApi(
RtMidi::Api api,
const std::string &clientName,
unsigned int queueSizeLimit );
445 const std::string& clientName =
"RtMidi Output Client" );
462 void openPort(
unsigned int portNumber = 0,
const std::string &portName = std::string(
"RtMidi Output" ) );
465 void closePort(
void );
472 virtual bool isPortOpen()
const;
483 void openVirtualPort(
const std::string &portName = std::string(
"RtMidi Output" ) );
486 unsigned int getPortCount(
void );
494 std::string getPortName(
unsigned int portNumber = 0 );
501 void sendMessage(
const std::vector<unsigned char> *message );
511 void sendMessage(
const unsigned char *message,
size_t size );
518 virtual void setErrorCallback(
RtMidiErrorCallback errorCallback = NULL,
void *userData = 0 );
521 void openMidiApi(
RtMidi::Api api,
const std::string &clientName );
545 virtual void openPort(
unsigned int portNumber,
const std::string &portName ) = 0;
546 virtual void openVirtualPort(
const std::string &portName ) = 0;
547 virtual void closePort(
void ) = 0;
548 virtual void setClientName(
const std::string &clientName ) = 0;
549 virtual void setPortName(
const std::string &portName ) = 0;
551 virtual unsigned int getPortCount(
void ) = 0;
552 virtual std::string getPortName(
unsigned int portNumber ) = 0;
554 inline bool isPortOpen()
const {
return connected_; }
561 virtual void initialize(
const std::string& clientName ) = 0;
565 std::string errorString_;
567 bool firstErrorOccurred_;
568 void *errorCallbackUserData_;
576 MidiInApi(
unsigned int queueSizeLimit );
579 void cancelCallback(
void );
580 virtual void ignoreTypes(
bool midiSysex,
bool midiTime,
bool midiSense );
581 virtual double getMessage( std::vector<unsigned char> *message );
582 virtual void setBufferSize(
unsigned int size,
unsigned int count );
587 std::vector<unsigned char> bytes;
594 : bytes(0), timeStamp(0.0) {}
600 unsigned int ringSize;
605 : front(0), back(0), ringSize(0), ring(0) {}
607 bool pop( std::vector<unsigned char>*,
double* );
608 unsigned int size(
unsigned int *back=0,
unsigned int *front=0 );
616 unsigned char ignoreFlags;
624 unsigned int bufferSize;
625 unsigned int bufferCount;
629 : ignoreFlags(7), doInput(
false), firstMessage(
true), apiData(0), usingCallback(
false),
630 userCallback(0), userData(0), continueSysex(
false), bufferSize(1024), bufferCount(4) {}
643 virtual void sendMessage(
const unsigned char *message,
size_t size ) = 0;
652inline RtMidi::Api RtMidiIn :: getCurrentApi(
void )
throw() {
return rtapi_->getCurrentApi(); }
653inline void RtMidiIn :: openPort(
unsigned int portNumber,
const std::string &portName ) { rtapi_->openPort( portNumber, portName ); }
654inline void RtMidiIn :: openVirtualPort(
const std::string &portName ) { rtapi_->openVirtualPort( portName ); }
655inline void RtMidiIn :: closePort(
void ) { rtapi_->closePort(); }
656inline bool RtMidiIn :: isPortOpen()
const {
return rtapi_->isPortOpen(); }
657inline void RtMidiIn :: setCallback( RtMidiCallback callback,
void *userData ) {
static_cast<MidiInApi *
>(rtapi_)->setCallback( callback, userData ); }
658inline void RtMidiIn :: cancelCallback(
void ) {
static_cast<MidiInApi *
>(rtapi_)->cancelCallback(); }
659inline unsigned int RtMidiIn :: getPortCount(
void ) {
return rtapi_->getPortCount(); }
660inline std::string RtMidiIn :: getPortName(
unsigned int portNumber ) {
return rtapi_->getPortName( portNumber ); }
661inline void RtMidiIn :: ignoreTypes(
bool midiSysex,
bool midiTime,
bool midiSense ) {
static_cast<MidiInApi *
>(rtapi_)->ignoreTypes( midiSysex, midiTime, midiSense ); }
662inline double RtMidiIn :: getMessage( std::vector<unsigned char> *message ) {
return static_cast<MidiInApi *
>(rtapi_)->getMessage( message ); }
663inline void RtMidiIn :: setErrorCallback(
RtMidiErrorCallback errorCallback,
void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); }
664inline void RtMidiIn :: setBufferSize(
unsigned int size,
unsigned int count ) {
static_cast<MidiInApi *
>(rtapi_)->setBufferSize(size, count); }
666inline RtMidi::Api RtMidiOut :: getCurrentApi(
void )
throw() {
return rtapi_->getCurrentApi(); }
667inline void RtMidiOut :: openPort(
unsigned int portNumber,
const std::string &portName ) { rtapi_->openPort( portNumber, portName ); }
668inline void RtMidiOut :: openVirtualPort(
const std::string &portName ) { rtapi_->openVirtualPort( portName ); }
669inline void RtMidiOut :: closePort(
void ) { rtapi_->closePort(); }
670inline bool RtMidiOut :: isPortOpen()
const {
return rtapi_->isPortOpen(); }
671inline unsigned int RtMidiOut :: getPortCount(
void ) {
return rtapi_->getPortCount(); }
672inline std::string RtMidiOut :: getPortName(
unsigned int portNumber ) {
return rtapi_->getPortName( portNumber ); }
673inline void RtMidiOut :: sendMessage(
const std::vector<unsigned char> *message ) {
static_cast<MidiOutApi *
>(rtapi_)->sendMessage( &message->at(0), message->size() ); }
674inline void RtMidiOut :: sendMessage(
const unsigned char *message,
size_t size ) {
static_cast<MidiOutApi *
>(rtapi_)->sendMessage( message, size ); }
675inline void RtMidiOut :: setErrorCallback(
RtMidiErrorCallback errorCallback,
void *userData ) { rtapi_->setErrorCallback(errorCallback, userData); }
void(* RtMidiErrorCallback)(RtMidiError::Type type, const std::string &errorText, void *userData)
RtMidi error callback function prototype.
Definition RtMidi.h:146
void error(RtMidiError::Type type, std::string errorString)
A basic error reporting function for RtMidi classes.
Exception handling class for RtMidi.
Definition RtMidi.h:97
virtual const std::string & getMessage(void) const
Returns the thrown error message string.
Definition RtMidi.h:128
virtual const Type & getType(void) const
Returns the thrown error message type.
Definition RtMidi.h:125
virtual void printMessage(void) const
Prints thrown error message to stderr.
Definition RtMidi.h:122
Type
Defined RtMidiError types.
Definition RtMidi.h:100
@ INVALID_USE
Definition RtMidi.h:108
@ NO_DEVICES_FOUND
Definition RtMidi.h:104
@ MEMORY_ERROR
Definition RtMidi.h:106
@ INVALID_PARAMETER
Definition RtMidi.h:107
@ WARNING
Definition RtMidi.h:101
@ INVALID_DEVICE
Definition RtMidi.h:105
@ DRIVER_ERROR
Definition RtMidi.h:109
@ UNSPECIFIED
Definition RtMidi.h:103
@ DEBUG_WARNING
Definition RtMidi.h:102
@ SYSTEM_ERROR
Definition RtMidi.h:110
virtual ~RtMidiError(void)
The destructor.
Definition RtMidi.h:119
virtual const char * what(void) const
Returns the thrown error message as a c-style string.
Definition RtMidi.h:131
RtMidiError(const std::string &message, Type type=RtMidiError::UNSPECIFIED)
The constructor.
Definition RtMidi.h:115
A realtime MIDI input class.
Definition RtMidi.h:276
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.
void(* RtMidiCallback)(double timeStamp, std::vector< unsigned char > *message, void *userData)
User callback function type definition.
Definition RtMidi.h:279
~RtMidiIn(void)
If a MIDI connection is still open, it will be closed by the destructor.
A realtime MIDI output class.
Definition RtMidi.h:434
RtMidiOut(RtMidi::Api api=UNSPECIFIED, const std::string &clientName="RtMidi Output Client")
Default constructor that allows an optional client name.
~RtMidiOut(void)
The destructor closes any open MIDI connections.
An abstract base class for realtime MIDI input/output.
Definition RtMidi.h:151
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 occurred.
Api
MIDI API specifier arguments.
Definition RtMidi.h:156
@ UNIX_JACK
Definition RtMidi.h:160
@ LINUX_ALSA
Definition RtMidi.h:159
@ WEB_MIDI_API
Definition RtMidi.h:163
@ MACOSX_CORE
Definition RtMidi.h:158
@ UNSPECIFIED
Definition RtMidi.h:157
@ RTMIDI_DUMMY
Definition RtMidi.h:162
@ WINDOWS_MM
Definition RtMidi.h:161
@ ANDROID_AMIDI
Definition RtMidi.h:165
@ WINDOWS_UWP
Definition RtMidi.h:164
double timeStamp
Time in seconds elapsed since the previous message.
Definition RtMidi.h:590