Canorus  0.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RtMidi.h
Go to the documentation of this file.
1 /**********************************************************************/
36 /**********************************************************************/
37 
38 // RtMidi: Version 1.0.7
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 ) = 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();
113 
115  ~RtMidiIn();
116 
118 
122  void openPort( unsigned int portNumber = 0 );
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;
203  unsigned int queueLimit;
204  unsigned char ignoreFlags;
205  bool doInput;
207  void *apiData;
210  void *userData;
211 
212  // Default constructor.
214  : queueLimit(1024), ignoreFlags(7), doInput(false), firstMessage(true),
215  apiData(0), usingCallback(false), userCallback(0), userData(0) {}
216  };
217 
218  private:
219 
220  void initialize( void );
222 
223 };
224 
225 /**********************************************************************/
237 /**********************************************************************/
238 
239 class RtMidiOut : public RtMidi
240 {
241  public:
242 
244 
247  RtMidiOut();
248 
250  ~RtMidiOut();
251 
253 
259  void openPort( unsigned int portNumber = 0 );
260 
262  void closePort();
263 
265 
273  void openVirtualPort( const std::string portName = std::string( "RtMidi Output" ) );
274 
276  unsigned int getPortCount();
277 
279 
282  std::string getPortName( unsigned int portNumber = 0 );
283 
285 
289  void sendMessage( std::vector<unsigned char> *message );
290 
291  private:
292 
293  void initialize( void );
294 };
295 
296 #endif
~RtMidiIn()
If a MIDI connection is still open, it will be closed by the destructor.
Definition: RtMidi.h:201
std::vector< unsigned char > bytes
Definition: RtMidi.h:191
std::string getPortName(unsigned int portNumber=0)
Return a string identifier for the specified MIDI port type and number.
RtMidi()
Definition: RtMidi.cpp:47
void(* RtMidiCallback)(double timeStamp, std::vector< unsigned char > *message, void *userData)
User callback function type definition.
Definition: RtMidi.h:106
void closePort()
Close an open MIDI connection (if one exists).
A realtime MIDI input class.
Definition: RtMidi.h:101
virtual unsigned int getPortCount()=0
Pure virtual getPortCount() function.
virtual void openVirtualPort(const std::string portName=std::string("RtMidi"))=0
Pure virtual openVirtualPort() function.
void setQueueSizeLimit(unsigned int queueSize)
Set the maximum number of MIDI messages to be saved in the queue.
Definition: RtMidi.cpp:109
void * userCallback
Definition: RtMidi.h:209
unsigned int queueLimit
Definition: RtMidi.h:203
An abstract base class for realtime MIDI input/output.
Definition: RtMidi.h:46
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
virtual void closePort(void)=0
Pure virtual closePort() function.
void closePort(void)
Close an open MIDI connection (if one exists).
virtual std::string getPortName(unsigned int portNumber=0)=0
Pure virtual getPortName() function.
void openPort(unsigned int portNumber=0)
Open a MIDI output connection.
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)...
void sendMessage(std::vector< unsigned char > *message)
Immediately send a single message out an open MIDI output port.
double timeStamp
Definition: RtMidi.h:192
void initialize(void)
void setCallback(RtMidiCallback callback, void *userData=0)
Set a callback function to be invoked for incoming MIDI messages.
Definition: RtMidi.cpp:77
RtMidiIn()
Default constructor.
Definition: RtMidi.cpp:72
void * userData
Definition: RtMidi.h:210
bool usingCallback
Definition: RtMidi.h:208
bool doInput
Definition: RtMidi.h:205
bool connected_
Definition: RtMidi.h:76
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)...
void * apiData_
Definition: RtMidi.h:75
void error(RtError::Type type)
Definition: RtMidi.cpp:52
unsigned int getPortCount()
Return the number of available MIDI output ports.
MidiMessage()
Definition: RtMidi.h:195
virtual ~RtMidi()
Definition: RtMidi.h:68
void initialize(void)
unsigned char ignoreFlags
Definition: RtMidi.h:204
unsigned int getPortCount()
Return the number of available MIDI input ports.
bool firstMessage
Definition: RtMidi.h:206
void cancelCallback()
Cancel use of the current callback function (if one exists).
Definition: RtMidi.cpp:96
void * apiData
Definition: RtMidi.h:207
void openPort(unsigned int portNumber=0)
Open a MIDI input connection.
RtMidiOut()
Default constructor.
Definition: RtMidi.cpp:147
std::string getPortName(unsigned int portNumber=0)
Return a string identifier for the specified MIDI input port number.
RtMidiInData()
Definition: RtMidi.h:213
std::string errorString_
Definition: RtMidi.h:77
~RtMidiOut()
The destructor closes any open MIDI connections.
RtMidiInData inputData_
Definition: RtMidi.h:221
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
Definition: RtMidi.h:190
Type
Defined RtError types.
Definition: RtError.h:22
virtual void openPort(unsigned int portNumber=0)=0
Pure virtual openPort() function.
A realtime MIDI output class.
Definition: RtMidi.h:239
std::queue< MidiMessage > queue
Definition: RtMidi.h:202