31#ifndef _NICMIDI_DRIVER_H
32#define _NICMIDI_DRIVER_H
39#include "../rtmidi-4.0.0/RtMidi.h"
58#define DRIVER_USES_MIDIMATRIX 0
59#if DRIVER_USES_MIDIMATRIX
83class MIDIRawMessageQueue {
88 MIDIRawMessageQueue(
unsigned int size) :
89 next_in(0), next_out(0), buffer(size) {}
91 virtual ~MIDIRawMessageQueue() {}
95 void Flush() { next_out = next_in; }
108 bool IsEmpty()
const {
return next_in == next_out; }
111 bool IsFull()
const {
return ((next_in + 1) % buffer.size()) == next_out; }
113 unsigned int GetLength()
const {
return (next_in - next_out) % buffer.size(); }
116 unsigned int next_in;
117 unsigned int next_out;
118 std::vector<MIDIRawMessage> buffer;
163 { processor = proc; }
198 std::recursive_mutex out_mutex;
200#if DRIVER_USES_MIDIMATRIX
207 std::vector<unsigned char> msg_bytes;
251 bool CanGet()
const {
return in_queue.GetLength() > 0; }
303 std::vector<unsigned char>* msg_bytes,
308 static const unsigned int DEFAULT_QUEUE_SIZE = 256;
315 MIDIRawMessageQueue in_queue;
316 std::recursive_mutex in_mutex;
Receives MIDI messages from an hardware MIDI in port.
Definition: driver.h:224
unsigned int GetQueueSize() const
Returns the queue size.
Definition: driver.h:253
void LockQueue()
Locks the queue so it cannot be written by other threads (such as the RtMidi callback).
Definition: driver.h:279
void FlushQueue()
Empties the queue in a thread-safe way.
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.
const MIDIProcessor * GetProcessor() const
Returns a pointer to the in processor.
Definition: driver.h:257
virtual ~MIDIInDriver()
The destructor closes the hardware port and deletes the object.
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 pu...
bool CanGet() const
Returns true if the queue is non-empty.
Definition: driver.h:251
virtual void ClosePort()
Closes the hardware out port.
int GetPortId() const
Returns the id number of the hardware in port.
Definition: driver.h:245
virtual void SetProcessor(MIDIProcessor *proc)
Sets the in processor, which can manipulate all incoming messages (see MIDIProcessor).
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.
virtual void Reset()
Resets the driver to default conditions:
MIDIProcessor * GetProcessor()
Returns a pointer to the in processor.
Definition: driver.h:255
std::string GetPortName()
Returns the name of the hardware in port.
Definition: driver.h:247
void UnlockQueue()
Unlocks the queue (see LockQueue()).
Definition: driver.h:281
virtual bool InputMessage(MIDIRawMessage &msg)
Gets the next message in the queue, copying it into msg (the message is deleted from the queue).
bool IsPortOpen() const
Returns true is the hardware port is open.
Definition: driver.h:249
virtual void OpenPort()
Opens the hardware in port.
This MIDIProcessor subclass implements a matrix which keeps track of notes on and hold pedal for ever...
Definition: matrix.h:43
Stores data representing a MIDI event message.
Definition: msg.h:49
Sends MIDI messages to an hardware MIDI out port.
Definition: driver.h:130
virtual void OpenPort()
Opens the hardware out port.
const MIDIProcessor * GetOutProcessor() const
Returns a pointer to the out processor.
Definition: driver.h:157
virtual void Reset()
Resets the driver to default conditions:
virtual void SetOutProcessor(MIDIProcessor *proc)
Sets the out processor, which can manipulate all outgoing messages (see MIDIProcessor).
Definition: driver.h:162
static const int DRIVER_WAIT_AFTER_SYSEX
The number of milliseconds the driver waits after sending a MIDI system exclusive message.
Definition: driver.h:189
MIDIProcessor * GetOutProcessor()
Returns a pointer to the out processor.
Definition: driver.h:155
static const int DRIVER_MAX_RETRIES
The maximum number of retries the method OutputMessage() will try before hanging (and skipping a mess...
Definition: driver.h:187
virtual void HardwareMsgOut(const MIDIMessage &msg)
Sends the message to the hardware MIDI port using the RtMidi library functions.
virtual void OutputMessage(const MIDITimedMessage &msg)
Makes a copy of the message, processes it with the out processor and then sends it to the hardware po...
virtual void AllNotesOff(int chan=-1)
Turns off all the sounding notes on the port (or on the given MIDI channel).
virtual void ClosePort()
Closes the hardware out port.
virtual ~MIDIOutDriver()
The destructor closes the hardware port and deletes the object.
std::string GetPortName()
Returns the name of the hardware out port.
Definition: driver.h:151
MIDIOutDriver(int id)
Creates a MIDIOutDriver object which can send MIDI messages to the given hardware out port.
int GetPortId() const
Returns the id number of the hardware out port.
Definition: driver.h:149
bool IsPortOpen() const
Returns true is the hardware port is open.
Definition: driver.h:153
A pure virtual class implementing an object that can manipulate a MIDI message, inspecting or changin...
Definition: processor.h:47
The MIDITimedMessage class inherits from the MIDIMessage and represents a message associated with a s...
Definition: msg.h:382
unsigned long long tMsecs
The type of a variable which can hold the elapsed time in milliseconds.
Definition: timer.h:44
Contains the definition of the class MIDIMatrix.
Contains the definition of the classes MIDIMessage and MIDITimedMessage.
Contains the definition of the pure virtual MIDIProcessor class and its specializations MIDIMultiProc...
Used by the MIDIInDriver to keep track of incoming messages.
Definition: driver.h:70
MIDIMessage msg
The MIDI Message received from the port.
Definition: driver.h:75
tMsecs timestamp
The absolute time in msecs.
Definition: driver.h:76
int port
The id of the MIDI in port which received the message.
Definition: driver.h:77
MIDIRawMessage(const MIDIMessage &m, tMsecs t, int p)
The constructor.
Definition: driver.h:73
Contains the definition of the MIDITimer class and some other typedef related to MIDI timing.