NiCMidi 1.1.0
A MIDI library derived from J.D.Koftinoff jdksmidi
MIDIOutDriver Class Reference

Sends MIDI messages to an hardware MIDI out port. More...

#include <driver.h>

Public Member Functions

 MIDIOutDriver (int id)
 Creates a MIDIOutDriver object which can send MIDI messages to the given hardware out port. More...
 
virtual ~MIDIOutDriver ()
 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 out port. More...
 
std::string GetPortName ()
 Returns the name of the hardware out port. More...
 
bool IsPortOpen () const
 Returns true is the hardware port is open. More...
 
MIDIProcessorGetOutProcessor ()
 Returns a pointer to the out processor. More...
 
const MIDIProcessorGetOutProcessor () const
 Returns a pointer to the out processor. More...
 
virtual void SetOutProcessor (MIDIProcessor *proc)
 Sets the out processor, which can manipulate all outgoing messages (see MIDIProcessor). More...
 
virtual void OpenPort ()
 Opens the hardware out port. More...
 
virtual void ClosePort ()
 Closes the hardware out port. More...
 
virtual void AllNotesOff (int chan=-1)
 Turns off all the sounding notes on the port (or on the given MIDI channel). More...
 
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 port. More...
 

Protected Member Functions

virtual void HardwareMsgOut (const MIDIMessage &msg)
 Sends the message to the hardware MIDI port using the RtMidi library functions. More...
 

Static Protected Attributes

static const int DRIVER_MAX_RETRIES = 100
 The maximum number of retries the method OutputMessage() will try before hanging (and skipping a message). More...
 
static const int DRIVER_WAIT_AFTER_SYSEX = 20
 The number of milliseconds the driver waits after sending a MIDI system exclusive message. More...
 

Detailed Description

Sends MIDI messages to an hardware MIDI out port.

Every MIDI out 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. You can set a MIDIProcessor for processing outgoing MIDI messages.

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.

Constructor & Destructor Documentation

◆ MIDIOutDriver()

MIDIOutDriver::MIDIOutDriver ( int  id)

Creates a MIDIOutDriver object which can send MIDI messages to the given hardware out port.

Parameters
idThe id of the hardware port. Numbers of the ports and their names can be retrieved by the MIDIManager::GetNumMIDIOuts() and MIDIManager::GetMIDIOutName() static methods.
Note
If id is not valid or the function fails, a dummy port with no functionality is created.
As said in the class description, the drivers are created automatically by the MIDIManager when the program starts, so usually you don't have to create or destroy them by yourself.

◆ ~MIDIOutDriver()

virtual MIDIOutDriver::~MIDIOutDriver ( )
virtual

The destructor closes the hardware port and deletes the object.

Member Function Documentation

◆ Reset()

virtual void MIDIOutDriver::Reset ( )
virtual

Resets the driver to default conditions:

  • Hardware MIDI port closed (resets the open count)
  • No extra processor (warning: this only sets the processor pointer to 0! The driver doesn't own its processor).

◆ GetPortId()

int MIDIOutDriver::GetPortId ( ) const
inline

Returns the id number of the hardware out port.

◆ GetPortName()

std::string MIDIOutDriver::GetPortName ( )
inline

Returns the name of the hardware out port.

Examples
test_advancedsequencer.cpp.

◆ IsPortOpen()

bool MIDIOutDriver::IsPortOpen ( ) const
inline

Returns true is the hardware port is open.

◆ GetOutProcessor() [1/2]

MIDIProcessor * MIDIOutDriver::GetOutProcessor ( )
inline

Returns a pointer to the out processor.

◆ GetOutProcessor() [2/2]

const MIDIProcessor * MIDIOutDriver::GetOutProcessor ( ) const
inline

Returns a pointer to the out processor.

◆ SetOutProcessor()

virtual void MIDIOutDriver::SetOutProcessor ( MIDIProcessor proc)
inlinevirtual

Sets the out processor, which can manipulate all outgoing 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).

◆ OpenPort()

virtual void MIDIOutDriver::OpenPort ( )
virtual

Opens the hardware out port.

This usually requires a noticeable amount of time, so it's better not to immediately start to send 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.

Examples
test_component.cpp.

◆ ClosePort()

virtual void MIDIOutDriver::ClosePort ( )
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().

Examples
test_component.cpp.

◆ AllNotesOff()

virtual void MIDIOutDriver::AllNotesOff ( int  chan = -1)
virtual

Turns off all the sounding notes on the port (or on the given MIDI channel).

This is normally done by sending an All Notes Off message, but you can change this behaviour (see DRIVER_USES_MIDIMATRIX). See also Numbering conventions.

Parameters
chanif you left the default silences all channels, otherwise you can give an unique channel to turn off

◆ OutputMessage()

virtual void MIDIOutDriver::OutputMessage ( const MIDITimedMessage msg)
virtual

Makes a copy of the message, processes it with the out processor and then sends it to the hardware port.

If the port is busy waits 1 msec and retries until DRIVER_MAX_RETRIES is reached.

Examples
test_component.cpp, and test_thru.cpp.

◆ HardwareMsgOut()

virtual void MIDIOutDriver::HardwareMsgOut ( const MIDIMessage msg)
protectedvirtual

Sends the message to the hardware MIDI port using the RtMidi library functions.

Member Data Documentation

◆ DRIVER_MAX_RETRIES

const int MIDIOutDriver::DRIVER_MAX_RETRIES = 100
staticprotected

The maximum number of retries the method OutputMessage() will try before hanging (and skipping a message).

◆ DRIVER_WAIT_AFTER_SYSEX

const int MIDIOutDriver::DRIVER_WAIT_AFTER_SYSEX = 20
staticprotected

The number of milliseconds the driver waits after sending a MIDI system exclusive message.


The documentation for this class was generated from the following file: