A realtime MIDI input class. Mehr ...
#include <RtMidi.h>
Klassen | |
struct | MidiMessage |
struct | RtMidiInData |
Öffentliche Typen | |
typedef void(* | RtMidiCallback )(double timeStamp, std::vector< unsigned char > *message, void *userData) |
User callback function type definition. | |
Öffentliche Methoden | |
RtMidiIn () | |
Default constructor. | |
~RtMidiIn () | |
If a MIDI connection is still open, it will be closed by the destructor. | |
void | openPort (unsigned int portNumber=0) |
Open a MIDI input connection. | |
void | openVirtualPort () |
Create a virtual input port to allow software connections (OS X and ALSA only). | |
void | setCallback (RtMidiCallback callback, void *userData=0) |
Set a callback function to be invoked for incoming MIDI messages. | |
void | cancelCallback () |
Cancel use of the current callback function (if one exists). | |
void | closePort (void) |
Close an open MIDI connection (if one exists). | |
unsigned int | getPortCount () |
Return the number of available MIDI input ports. | |
std::string | getPortName (unsigned int portNumber=0) |
Return a string identifier for the specified MIDI input port number. | |
void | setQueueSizeLimit (unsigned int queueSize) |
Set the maximum number of MIDI messages to be saved in the queue. | |
void | ignoreTypes (bool midiSysex=true, bool midiTime=true, bool midiSense=true) |
Specify whether certain MIDI message types should be queued or ignored during input. | |
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 queue and return the event delta-time in seconds. | |
Private Methoden | |
void | initialize (void) |
Private Attribute | |
RtMidiInData | inputData_ |
A realtime MIDI input class.
This class provides a common, platform-independent API for realtime MIDI input. It allows access to a single MIDI input port. Incoming MIDI messages are either saved to a queue for retrieval using the getMessage() function or immediately passed to a user-specified callback function. Create multiple instances of this class to connect to more than one MIDI device at the same time. With the OS-X and Linux ALSA MIDI APIs, it is also possible to open a virtual input port to which other MIDI software clients can connect.
by Gary P. Scavone, 2003-2004.
typedef void(* RtMidiIn::RtMidiCallback)(double timeStamp, std::vector< unsigned char > *message, void *userData) |
RtMidiIn::RtMidiIn | ( | ) |
Default constructor.
An exception will be thrown if a MIDI system initialization error occurs.
Definiert in Zeile 71 der Datei RtMidi.cpp.
Benutzt initialize().
: RtMidi() { this->initialize(); }
RtMidiIn::~RtMidiIn | ( | ) |
If a MIDI connection is still open, it will be closed by the destructor.
void RtMidiIn::cancelCallback | ( | ) |
Cancel use of the current callback function (if one exists).
Subsequent incoming MIDI messages will be written to the queue and can be retrieved with the getMessage function.
Definiert in Zeile 96 der Datei RtMidi.cpp.
Benutzt RtMidi::error(), RtMidi::errorString_, inputData_, RtMidiIn::RtMidiInData::userCallback, RtMidiIn::RtMidiInData::userData, RtMidiIn::RtMidiInData::usingCallback und RtError::WARNING.
{ if ( !inputData_.usingCallback ) { errorString_ = "RtMidiIn::cancelCallback: no callback function was set!"; error( RtError::WARNING ); return; } inputData_.userCallback = 0; inputData_.userData = 0; inputData_.usingCallback = false; }
void RtMidiIn::closePort | ( | void | ) | [virtual] |
Close an open MIDI connection (if one exists).
Implementiert RtMidi.
double RtMidiIn::getMessage | ( | std::vector< unsigned char > * | message | ) |
Fill the user-provided vector with the data bytes for the next available MIDI message in the input queue and return the event delta-time in seconds.
This function returns immediately whether a new message is available or not. A valid message is indicated by a non-zero vector size. An exception is thrown if an error occurs during message retrieval or an input connection was not previously established.
Definiert in Zeile 126 der Datei RtMidi.cpp.
Benutzt RtMidi::error(), RtMidi::errorString_, inputData_, RtMidiIn::RtMidiInData::queue, RtMidiIn::RtMidiInData::usingCallback und RtError::WARNING.
{ //message->clear(); if ( inputData_.usingCallback ) { errorString_ = "RtMidiIn::getNextMessage: a user callback is currently set for this port."; error( RtError::WARNING ); return 0.0; } if ( inputData_.queue.size() == 0 ) return 0.0; // Copy queued message to the vector pointer argument and then "pop" it. std::vector<unsigned char> *bytes = &(inputData_.queue.front().bytes); message->assign( bytes->begin(), bytes->end() ); double deltaTime = inputData_.queue.front().timeStamp; inputData_.queue.pop(); return deltaTime; }
unsigned int RtMidiIn::getPortCount | ( | ) | [virtual] |
Return the number of available MIDI input ports.
Implementiert RtMidi.
Wird benutzt von MutInputDeviceShape::ShowDeviceDialog().
std::string RtMidiIn::getPortName | ( | unsigned int | portNumber = 0 | ) | [virtual] |
Return a string identifier for the specified MIDI input port number.
An exception is thrown if an invalid port specifier is provided.
Implementiert RtMidi.
Wird benutzt von InMidiPort::SetDevId() und MutInputDeviceShape::ShowDeviceDialog().
void RtMidiIn::ignoreTypes | ( | bool | midiSysex = true , |
bool | midiTime = true , |
||
bool | midiSense = true |
||
) |
Specify whether certain MIDI message types should be queued or ignored during input.
By default, MIDI timing and active sensing messages are ignored during message input because of their relative high data rates. MIDI sysex messages are ignored by default as well. Variable values of "true" imply that the respective message type will be ignored.
Definiert in Zeile 115 der Datei RtMidi.cpp.
Benutzt RtMidiIn::RtMidiInData::ignoreFlags und inputData_.
{ inputData_.ignoreFlags = 0; if ( midiSysex ) inputData_.ignoreFlags = 0x01; if ( midiTime ) inputData_.ignoreFlags |= 0x02; if ( midiSense ) inputData_.ignoreFlags |= 0x04; }
void RtMidiIn::initialize | ( | void | ) | [private] |
Wird benutzt von RtMidiIn().
void RtMidiIn::openPort | ( | unsigned int | portNumber = 0 | ) | [virtual] |
Open a MIDI input connection.
An optional port number greater than 0 can be specified. Otherwise, the default or first port found is opened.
Implementiert RtMidi.
void RtMidiIn::openVirtualPort | ( | ) | [virtual] |
Create a virtual input port to allow software connections (OS X and ALSA only).
This function creates a virtual MIDI input port to which other software applications can connect. This type of functionality is currently only supported by the Macintosh OS-X and Linux ALSA APIs (the function does nothing for the other APIs).
Implementiert RtMidi.
void RtMidiIn::setCallback | ( | RtMidiCallback | callback, |
void * | userData = 0 |
||
) |
Set a callback function to be invoked for incoming MIDI messages.
The callback function will be called whenever an incoming MIDI message is received. While not absolutely necessary, it is best to set the callback function before opening a MIDI port to avoid leaving some messages in the queue.
Definiert in Zeile 76 der Datei RtMidi.cpp.
Benutzt RtMidi::error(), RtMidi::errorString_, inputData_, RtMidiIn::RtMidiInData::userCallback, RtMidiIn::RtMidiInData::userData, RtMidiIn::RtMidiInData::usingCallback und RtError::WARNING.
{ if ( inputData_.usingCallback ) { errorString_ = "RtMidiIn::setCallback: a callback function is already set!"; error( RtError::WARNING ); return; } if ( !callback ) { errorString_ = "RtMidiIn::setCallback: callback function value is invalid!"; error( RtError::WARNING ); return; } inputData_.userCallback = (void *) callback; inputData_.userData = userData; inputData_.usingCallback = true; }
void RtMidiIn::setQueueSizeLimit | ( | unsigned int | queueSize | ) |
Set the maximum number of MIDI messages to be saved in the queue.
If the queue size limit is reached, incoming messages will be ignored. The default limit is 1024.
Definiert in Zeile 110 der Datei RtMidi.cpp.
Benutzt inputData_ und RtMidiIn::RtMidiInData::queueLimit.
{ inputData_.queueLimit = queueSize; }
RtMidiInData RtMidiIn::inputData_ [private] |
Definiert in Zeile 245 der Datei RtMidi.h.
Wird benutzt von cancelCallback(), getMessage(), ignoreTypes(), setCallback() und setQueueSizeLimit().