Canorus  0.0
RtMidi.h
Go to the documentation of this file.
1 /**********************************************************************/
36 /**********************************************************************/
37 
38 // RtMidi: Version 1.0.9
39 
40 #ifndef RTMIDI_H
41 #define RTMIDI_H
42 
43 #include "RtError.h"
44 #include <string>
45 
46 class RtMidi
47 {
48  public:
49 
51  virtual void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi" ) ) = 0;
52 
54  virtual void openVirtualPort( const std::string portName = std::string( "RtMidi" ) ) = 0;
55 
57  virtual unsigned int getPortCount() = 0;
58 
60  virtual std::string getPortName( unsigned int portNumber = 0 ) = 0;
61 
63  virtual void closePort( void ) = 0;
64 
65  protected:
66 
67  RtMidi();
68  virtual ~RtMidi() {};
69 
70  // A basic error reporting function for internal use in the RtMidi
71  // subclasses. The behavior of this function can be modified to
72  // suit specific needs.
73  void error( RtError::Type type );
74 
75  void *apiData_;
76  bool connected_;
77  std::string errorString_;
78 };
79 
80 /**********************************************************************/
96 /**********************************************************************/
97 
98 #include <vector>
99 #include <queue>
100 
101 class RtMidiIn : public RtMidi
102 {
103  public:
104 
106  typedef void (*RtMidiCallback)( double timeStamp, std::vector<unsigned char> *message, void *userData);
107 
109 
112  RtMidiIn( const std::string clientName = std::string( "RtMidi Input Client") );
113 
116 
118 
122  void openPort( unsigned int portNumber = 0, const std::string Portname = std::string( "RtMidi Input" ) );
123 
125 
131  void openVirtualPort( const std::string portName = std::string( "RtMidi Input" ) );
132 
134 
140  void setCallback( RtMidiCallback callback, void *userData = 0 );
141 
143 
147  void cancelCallback();
148 
150  void closePort( void );
151 
153  unsigned int getPortCount();
154 
156 
159  std::string getPortName( unsigned int portNumber = 0 );
160 
162 
166  void setQueueSizeLimit( unsigned int queueSize );
167 
169 
176  void ignoreTypes( bool midiSysex = true, bool midiTime = true, bool midiSense = true );
177 
179 
186  double getMessage( std::vector<unsigned char> *message );
187 
188  // A MIDI structure used internally by the class to store incoming
189  // messages. Each message represents one and only one MIDI message.
190  struct MidiMessage {
191  std::vector<unsigned char> bytes;
192  double timeStamp;
193 
194  // Default constructor.
196  :bytes(3), timeStamp(0.0) {}
197  };
198 
199  // The RtMidiInData structure is used to pass private class data to
200  // the MIDI input handling function or thread.
201  struct RtMidiInData {
202  std::queue<MidiMessage> queue;
204  unsigned int queueLimit;
205  unsigned char ignoreFlags;
206  bool doInput;
208  void *apiData;
211  void *userData;
213 
214  // Default constructor.
216  : queueLimit(1024), ignoreFlags(7), doInput(false), firstMessage(true),
217  apiData(0), usingCallback(false), userCallback(0), userData(0),
218  continueSysex(false) {}
219  };
220 
221  private:
222 
223  void initialize( const std::string& clientName );
225 
226 };
227 
228 /**********************************************************************/
240 /**********************************************************************/
241 
242 class RtMidiOut : public RtMidi
243 {
244  public:
245 
247 
250  RtMidiOut( const std::string clientName = std::string( "RtMidi Output Client" ) );
251 
254 
256 
262  void openPort( unsigned int portNumber = 0, const std::string portName = std::string( "RtMidi Output" ) );
263 
265  void closePort();
266 
268 
276  void openVirtualPort( const std::string portName = std::string( "RtMidi Output" ) );
277 
279  unsigned int getPortCount();
280 
282 
285  std::string getPortName( unsigned int portNumber = 0 );
286 
288 
292  void sendMessage( std::vector<unsigned char> *message );
293 
294  private:
295 
296  void initialize( const std::string& clientName );
297 };
298 
299 #endif
RtMidiIn::setCallback
void setCallback(RtMidiCallback callback, void *userData=0)
Set a callback function to be invoked for incoming MIDI messages.
Definition: RtMidi.cpp:77
RtMidiIn::RtMidiInData::message
MidiMessage message
Definition: RtMidi.h:203
RtMidiIn::RtMidiInData::queue
std::queue< MidiMessage > queue
Definition: RtMidi.h:202
RtMidi::~RtMidi
virtual ~RtMidi()
Definition: RtMidi.h:68
RtMidi
An abstract base class for realtime MIDI input/output.
Definition: RtMidi.h:47
RtMidi::getPortName
virtual std::string getPortName(unsigned int portNumber=0)=0
Pure virtual getPortName() function.
RtMidiIn::RtMidiCallback
void(* RtMidiCallback)(double timeStamp, std::vector< unsigned char > *message, void *userData)
User callback function type definition.
Definition: RtMidi.h:106
RtMidiOut::~RtMidiOut
~RtMidiOut()
The destructor closes any open MIDI connections.
RtMidiIn::getPortName
std::string getPortName(unsigned int portNumber=0)
Return a string identifier for the specified MIDI input port number.
RtMidiIn::RtMidiInData::continueSysex
bool continueSysex
Definition: RtMidi.h:212
RtMidiIn::setQueueSizeLimit
void setQueueSizeLimit(unsigned int queueSize)
Set the maximum number of MIDI messages to be saved in the queue.
Definition: RtMidi.cpp:109
RtMidiIn::getPortCount
unsigned int getPortCount()
Return the number of available MIDI input ports.
Byte
unsigned char Byte
Definition: miniz.h:401
RtMidiIn::RtMidiInData::apiData
void * apiData
Definition: RtMidi.h:208
RtMidiIn::ignoreTypes
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.cpp:114
RtMidi::RtMidi
RtMidi()
Definition: RtMidi.cpp:47
RtMidiIn::RtMidiIn
RtMidiIn(const std::string clientName=std::string("RtMidi Input Client"))
Default constructor that allows an optional client name.
Definition: RtMidi.cpp:72
RtError::DRIVER_ERROR
@ DRIVER_ERROR
Definition: RtError.h:31
RtMidiOut::openVirtualPort
void openVirtualPort(const std::string portName=std::string("RtMidi Output"))
Create a virtual output port, with optional name, to allow software connections (OS X and ALSA only).
RtMidiIn::getMessage
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.cpp:122
RtMidiOut::closePort
void closePort()
Close an open MIDI connection (if one exists).
RtError::MEMORY_ERROR
@ MEMORY_ERROR
Definition: RtError.h:29
RtMidiIn::RtMidiInData::userCallback
void * userCallback
Definition: RtMidi.h:210
RtMidiIn::closePort
void closePort(void)
Close an open MIDI connection (if one exists).
RtMidiIn::MidiMessage::bytes
std::vector< unsigned char > bytes
Definition: RtMidi.h:191
RtMidi::openVirtualPort
virtual void openVirtualPort(const std::string portName=std::string("RtMidi"))=0
Pure virtual openVirtualPort() function.
RtError::Type
Type
Defined RtError types.
Definition: RtError.h:22
RtMidiIn::MidiMessage::MidiMessage
MidiMessage()
Definition: RtMidi.h:195
RtMidiIn::cancelCallback
void cancelCallback()
Cancel use of the current callback function (if one exists).
Definition: RtMidi.cpp:96
RtMidiIn::MidiMessage
Definition: RtMidi.h:190
RtError::NO_DEVICES_FOUND
@ NO_DEVICES_FOUND
Definition: RtError.h:26
RtMidi::closePort
virtual void closePort(void)=0
Pure virtual closePort() function.
RtMidiOut::getPortCount
unsigned int getPortCount()
Return the number of available MIDI output ports.
RtMidi.h
RtMidiIn::openVirtualPort
void openVirtualPort(const std::string portName=std::string("RtMidi Input"))
Create a virtual input port, with optional name, to allow software connections (OS X and ALSA only).
RtMidi::errorString_
std::string errorString_
Definition: RtMidi.h:77
NULL
#define NULL
Definition: glib.h:121
RtMidiIn::openPort
void openPort(unsigned int portNumber=0, const std::string Portname=std::string("RtMidi Input"))
Open a MIDI input connection.
RtMidiOut::sendMessage
void sendMessage(std::vector< unsigned char > *message)
Immediately send a single message out an open MIDI output port.
RtMidiIn::RtMidiInData::queueLimit
unsigned int queueLimit
Definition: RtMidi.h:204
RtError::INVALID_PARAMETER
@ INVALID_PARAMETER
Definition: RtError.h:30
RtMidiIn
A realtime MIDI input class.
Definition: RtMidi.h:102
RtMidiOut::getPortName
std::string getPortName(unsigned int portNumber=0)
Return a string identifier for the specified MIDI port type and number.
RtMidi::apiData_
void * apiData_
Definition: RtMidi.h:75
RtMidiIn::RtMidiInData::firstMessage
bool firstMessage
Definition: RtMidi.h:207
RtMidiIn::RtMidiInData::doInput
bool doInput
Definition: RtMidi.h:206
RtMidi::openPort
virtual void openPort(unsigned int portNumber=0, const std::string portName=std::string("RtMidi"))=0
Pure virtual openPort() function.
RtMidiIn::inputData_
RtMidiInData inputData_
Definition: RtMidi.h:224
RtError::DEBUG_WARNING
@ DEBUG_WARNING
Definition: RtError.h:24
RtError::WARNING
@ WARNING
Definition: RtError.h:23
RtMidiIn::initialize
void initialize(const std::string &clientName)
RtMidiIn::RtMidiInData::RtMidiInData
RtMidiInData()
Definition: RtMidi.h:215
RtMidiIn::RtMidiInData::userData
void * userData
Definition: RtMidi.h:211
RtError
Exception handling class for RtAudio & RtMidi.
Definition: RtError.h:19
RtMidiIn::RtMidiInData::usingCallback
bool usingCallback
Definition: RtMidi.h:209
RtError.h
RtMidiIn::~RtMidiIn
~RtMidiIn()
If a MIDI connection is still open, it will be closed by the destructor.
RtMidiIn::MidiMessage::timeStamp
double timeStamp
Definition: RtMidi.h:192
RtMidiOut::initialize
void initialize(const std::string &clientName)
RtError::THREAD_ERROR
@ THREAD_ERROR
Definition: RtError.h:33
RtMidiOut::RtMidiOut
RtMidiOut(const std::string clientName=std::string("RtMidi Output Client"))
Default constructor that allows an optional client name.
Definition: RtMidi.cpp:147
RtMidiOut::openPort
void openPort(unsigned int portNumber=0, const std::string portName=std::string("RtMidi Output"))
Open a MIDI output connection.
RtMidiOut
A realtime MIDI output class.
Definition: RtMidi.h:243
RtMidi::error
void error(RtError::Type type)
Definition: RtMidi.cpp:52
RtMidiIn::RtMidiInData
Definition: RtMidi.h:201
RtMidiIn::RtMidiInData::ignoreFlags
unsigned char ignoreFlags
Definition: RtMidi.h:205
RtMidi::getPortCount
virtual unsigned int getPortCount()=0
Pure virtual getPortCount() function.
RtMidi::connected_
bool connected_
Definition: RtMidi.h:76