NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
|
Receives MIDI messages from an hardware MIDI in port. More...
#include <driver.h>
Public Member Functions | |
MIDIInDriver (int id, unsigned int queue_size=DEFAULT_QUEUE_SIZE) | |
Creates a MIDIInDriver object which can receive MIDI messages from the given hardware in port. More... | |
virtual | ~MIDIInDriver () |
The destructor closes the hardware port and deletes the object. More... | |
virtual void | Reset () |
Resets the driver to default conditions: More... | |
int | GetPortId () const |
Returns the id number of the hardware in port. More... | |
std::string | GetPortName () |
Returns the name of the hardware in port. More... | |
bool | IsPortOpen () const |
Returns true is the hardware port is open. More... | |
bool | CanGet () const |
Returns true if the queue is non-empty. More... | |
unsigned int | GetQueueSize () const |
Returns the queue size. More... | |
MIDIProcessor * | GetProcessor () |
Returns a pointer to the in processor. More... | |
const MIDIProcessor * | GetProcessor () const |
Returns a pointer to the in processor. More... | |
virtual void | SetProcessor (MIDIProcessor *proc) |
Sets the in processor, which can manipulate all incoming messages (see MIDIProcessor). More... | |
virtual void | OpenPort () |
Opens the hardware in port. More... | |
virtual void | ClosePort () |
Closes the hardware out port. More... | |
void | LockQueue () |
Locks the queue so it cannot be written by other threads (such as the RtMidi callback). More... | |
void | UnlockQueue () |
Unlocks the queue (see LockQueue()). More... | |
void | FlushQueue () |
Empties the queue in a thread-safe way. More... | |
virtual bool | InputMessage (MIDIRawMessage &msg) |
Gets the next message in the queue, copying it into msg (the message is deleted from the queue). More... | |
virtual bool | ReadMessage (MIDIRawMessage &msg, unsigned int n) |
Gets the n-th message in the queue without deleting it (so the message remains available for other purposes). More... | |
Static Protected Member Functions | |
static void | HardwareMsgIn (double time, std::vector< unsigned char > *msg_bytes, void *p) |
This is the callback function executed by RtMidi when a message arrives to the hardware port. More... | |
Receives MIDI messages from an hardware MIDI in port.
Every MIDI in port is denoted by a specific id number, enumerated by the RtMidi class, and by a name, given by the OS; this class communicates between the hardware ports and the other library classes. The incoming MIDI messages are stamped with the system time in milliseconds and the port number (see the MIDIRawMessage struct and HardwareMsgIn() for details) and put in an internal queue; you can get them with the InputMessage() and ReadMessage() methods. Moreover you can set a MIDIProcessor for processing them as they arrive.
When the program starts, the MIDIManager searches for all the hardware ports in the system and creates a driver for everyone of them, so you find them ready to use.
MIDIInDriver::MIDIInDriver | ( | int | id, |
unsigned int | queue_size = DEFAULT_QUEUE_SIZE |
||
) |
Creates a MIDIInDriver object which can receive MIDI messages from the given hardware in port.
id | The id of the hardware port. Numbers of the ports and their names can be retrieved by the MIDIManager::GetNumMIDIOutPorts() and MIDIManager::GetMIDIOutName() static methods. |
queue_size | The size of the queue; you could try to change this if you have trouble in receiving MIDI messages from the hardware, otherwise left unchanged (default size is 256). |
|
virtual |
The destructor closes the hardware port and deletes the object.
|
virtual |
Resets the driver to default conditions:
|
inline |
Returns the id number of the hardware in port.
|
inline |
Returns the name of the hardware in port.
|
inline |
Returns true is the hardware port is open.
|
inline |
Returns true if the queue is non-empty.
|
inline |
Returns the queue size.
|
inline |
Returns a pointer to the in processor.
|
inline |
Returns a pointer to the in processor.
|
virtual |
Sets the in processor, which can manipulate all incoming messages (see MIDIProcessor).
If you want to eliminate a processor already set, call it with 0 as parameter (this only sets the processor pointer to 0! The driver doesn't own its processor).
|
virtual |
Opens the hardware in port.
This usually requires a noticeable amount of time, so it's better not to immediately start to get messages. If the port is already open the object remembers how many times it was open, so a corresponding number of ClosePort() must be called to effectively close the port.
|
virtual |
Closes the hardware out port.
If the port was open more than once it only decrements the count (leaving it open), while it does nothing if the port is already close. If you want to force the closure call Reset().
|
inline |
Locks the queue so it cannot be written by other threads (such as the RtMidi callback).
You can then safely inspect and get its data, unlocking it when you have finished and want to get new messages.
|
inline |
Unlocks the queue (see LockQueue()).
void MIDIInDriver::FlushQueue | ( | ) |
Empties the queue in a thread-safe way.
|
virtual |
Gets the next message in the queue, copying it into msg (the message is deleted from the queue).
[out] | msg | the message got from the queue |
|
virtual |
Gets the n-th message in the queue without deleting it (so the message remains available for other purposes).
[out] | msg | is a direct reference to the queued message, so it's your responsability not to alter it |
n | the message index in the in queue |
|
staticprotected |
This is the callback function executed by RtMidi when a message arrives to the hardware port.
It converts raw data taken from the port into a MIDIRawMessage (eventually processing it with the processor) and pushes it on the internal queue. You must not call it directly.