Tutorial   Class/Enum List   File List   Compound Members   C interface  

Public Member Functions | List of all members
rt::midi::RtMidiOut Class Reference

A realtime MIDI output class. More...

#include <RtMidi.h>

Inheritance diagram for rt::midi::RtMidiOut:
rt::midi::RtMidi

Public Member Functions

 RtMidiOut (RtMidi::Api api=UNSPECIFIED, const std::string &clientName="RtMidi Output Client")
 Default constructor that allows an optional client name.
 
 ~RtMidiOut (void) throw ()
 The destructor closes any open MIDI connections.
 
RtMidi::Api getCurrentApi (void) throw ()
 Returns the MIDI API specifier for the current instance of RtMidiOut.
 
void openPort (unsigned int portNumber=0, const std::string &portName=std::string("RtMidi Output"))
 Open a MIDI output connection.
 
void closePort (void)
 Close an open MIDI connection (if one exists).
 
virtual bool isPortOpen () const
 Returns true if a port is open and false if not.
 
void openVirtualPort (const std::string &portName=std::string("RtMidi Output"))
 Create a virtual output port, with optional name, to allow software connections (OS X, JACK and ALSA only).
 
unsigned int getPortCount (void)
 Return the number of available MIDI output ports.
 
std::string getPortName (unsigned int portNumber=0)
 Return a string identifier for the specified MIDI port type and number.
 
void sendMessage (const std::vector< unsigned char > *message)
 Immediately send a single message out an open MIDI output port.
 
void sendMessage (const unsigned char *message, size_t size)
 Immediately send a single message out an open MIDI output port.
 
virtual void setErrorCallback (RtMidiErrorCallback errorCallback=NULL, void *userData=0)
 Set an error callback function to be invoked when an error has occurred.
 
- Public Member Functions inherited from rt::midi::RtMidi
bool supportsAutoReconnect (void) const
 Whether this backend can restore connections after device removal.
 
void setAutoReconnect (bool enabled)
 Enable or disable automatic recovery (enabled by default when supported).
 

Additional Inherited Members

- Public Types inherited from rt::midi::RtMidi
enum  Api {
  UNSPECIFIED , MACOSX_CORE , LINUX_ALSA , UNIX_JACK ,
  WINDOWS_MM , RTMIDI_DUMMY , WEB_MIDI_API , WINDOWS_UWP ,
  ANDROID_AMIDI , WINDOWS_MIDI_SERVICES , NUM_APIS
}
 MIDI API specifier arguments. More...
 
- Static Public Member Functions inherited from rt::midi::RtMidi
static RtMidiApiAvailability checkApiAvailability (RtMidi::Api api)
 Query whether an API can be used by this build on this system.
 
static std::string getVersion (void) throw ()
 A static function to determine the current RtMidi version.
 
static void getCompiledApi (std::vector< RtMidi::Api > &apis) throw ()
 A static function to determine the available compiled MIDI APIs.
 
static std::string getApiName (RtMidi::Api api)
 Return the name of a specified compiled MIDI API.
 
static std::string getApiDisplayName (RtMidi::Api api)
 Return the display name of a specified compiled MIDI API.
 
static RtMidi::Api getCompiledApiByName (const std::string &name)
 Return the compiled MIDI API having the given name.
 

Detailed Description

A realtime MIDI output class.

This class provides a common, platform-independent API for MIDI output. It allows one to probe available MIDI output ports, to connect to one such port, and to send MIDI bytes immediately over the connection. Create multiple instances of this class to connect to more than one MIDI device at the same time. With the OS-X, Linux ALSA and JACK MIDI APIs, it is also possible to open a virtual port to which other MIDI software clients can connect.

Constructor & Destructor Documentation

◆ RtMidiOut()

rt::midi::RtMidiOut::RtMidiOut ( RtMidi::Api  api = UNSPECIFIED,
const std::string &  clientName = "RtMidi Output Client" 
)

Default constructor that allows an optional client name.

An exception will be thrown if a MIDI system initialization error occurs.

If no API argument is specified and multiple API support has been compiled, the first API with at least one port is used, trying them in this order: CoreMIDI, ALSA, JACK, Windows MIDI Services, WinMM, UWP, Web MIDI, Android. If none has a port, the first that opens is used.

Member Function Documentation

◆ openPort()

void rt::midi::RtMidiOut::openPort ( unsigned int  portNumber = 0,
const std::string &  portName = std::string( "RtMidi Output" ) 
)
inlinevirtual

Open a MIDI output connection.

An optional port number greater than 0 can be specified. Otherwise, the default or first port found is opened. An exception is thrown if an error occurs while attempting to make the port connection.

Implements rt::midi::RtMidi.

◆ isPortOpen()

bool rt::midi::RtMidiOut::isPortOpen ( void  ) const
inlinevirtual

Returns true if a port is open and false if not.

Note that this only applies to connections made with the openPort() function, not to virtual ports.

Implements rt::midi::RtMidi.

◆ openVirtualPort()

void rt::midi::RtMidiOut::openVirtualPort ( const std::string &  portName = std::string( "RtMidi Output" ))
inlinevirtual

Create a virtual output port, with optional name, to allow software connections (OS X, JACK and ALSA only).

This function creates a virtual MIDI output port to which other software applications can connect. This type of functionality is currently only supported by the CoreMIDI (macOS and iOS), ALSA and JACK APIs (the other APIs report a warning and open nothing). An exception is thrown if an error occurs while attempting to create the virtual port.

Implements rt::midi::RtMidi.

◆ getPortName()

std::string rt::midi::RtMidiOut::getPortName ( unsigned int  portNumber = 0)
inlinevirtual

Return a string identifier for the specified MIDI port type and number.

Returns
The name of the port with the given Id is returned.
Return values
Anempty string is returned if an invalid port specifier is provided. User code should assume a UTF-8 encoding.

Implements rt::midi::RtMidi.

◆ sendMessage() [1/2]

void rt::midi::RtMidiOut::sendMessage ( const std::vector< unsigned char > *  message)
inline

Immediately send a single message out an open MIDI output port.

An exception is thrown if an error occurs during output or an output connection was not previously established.

On some backends, Windows MM in particular, a SysEx message is sent synchronously: this call does not return until the driver has finished with the data, which for a large dump over a slow link can take a noticeable amount of time. Avoid calling it from a user-interface thread.

A large SysEx may not survive one call; send it in pieces (see tests/sysexchunked.cpp). Between two applications on ALSA, one larger than 5572 bytes is lost at the receiver, while the sender only gets an error from 16356 bytes. On JACK, one larger than 16379 bytes is not sent. To a hardware port on ALSA, only 4096 bytes fit the kernel's buffer (snd_seq_midi output_buffer_size) and the rest is cut off with no error: send pieces of at most that, each once the last has drained at the device's rate (3125 bytes per second for DIN MIDI).

◆ sendMessage() [2/2]

void rt::midi::RtMidiOut::sendMessage ( const unsigned char *  message,
size_t  size 
)
inline

Immediately send a single message out an open MIDI output port.

An exception is thrown if an error occurs during output or an output connection was not previously established.

On some backends, Windows MM in particular, a SysEx message is sent synchronously: this call does not return until the driver has finished with the data, which for a large dump over a slow link can take a noticeable amount of time. Avoid calling it from a user-interface thread.

A large SysEx may not survive one call; send it in pieces (see tests/sysexchunked.cpp). Between two applications on ALSA, one larger than 5572 bytes is lost at the receiver, while the sender only gets an error from 16356 bytes. On JACK, one larger than 16379 bytes is not sent. To a hardware port on ALSA, only 4096 bytes fit the kernel's buffer (snd_seq_midi output_buffer_size) and the rest is cut off with no error: send pieces of at most that, each once the last has drained at the device's rate (3125 bytes per second for DIN MIDI).

Parameters
messageA pointer to the MIDI message as raw bytes
sizeLength of the MIDI message in bytes

◆ setErrorCallback()

void rt::midi::RtMidiOut::setErrorCallback ( RtMidiErrorCallback  errorCallback = NULL,
void *  userData = 0 
)
inlinevirtual

Set an error callback function to be invoked when an error has occurred.

The callback function will be called whenever an error has occurred. It is best to set the error callback function before opening a port.

Implements rt::midi::RtMidi.


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

©2003-2023 Gary P. Scavone, McGill University. All Rights Reserved.
Maintained by Gary P. Scavone, gary at music.mcgill.ca