Tutorial   Class/Enum List   File List   Compound Members   C interface  

Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
rt::midi::RtMidi Class Referenceabstract

An abstract base class for realtime MIDI input/output. More...

#include <RtMidi.h>

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

Classes

struct  RtMidiApiAvailability
 Result returned by checkApiAvailability(). More...
 

Public Types

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...
 

Public Member Functions

virtual void openPort (unsigned int portNumber=0, const std::string &portName=std::string("RtMidi"))=0
 Pure virtual openPort() function.
 
virtual void openVirtualPort (const std::string &portName=std::string("RtMidi"))=0
 Pure virtual openVirtualPort() function.
 
virtual unsigned int getPortCount ()=0
 Pure virtual getPortCount() function.
 
virtual std::string getPortName (unsigned int portNumber=0)=0
 Pure virtual getPortName() function.
 
virtual void closePort (void)=0
 Pure virtual closePort() function.
 
virtual bool isPortOpen (void) const =0
 Returns true if a port is open and false if not.
 
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).
 
virtual void setErrorCallback (RtMidiErrorCallback errorCallback=NULL, void *userData=0)=0
 Set an error callback function to be invoked when an error has occurred.
 

Static Public Member Functions

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

An abstract base class for realtime MIDI input/output.

This class implements some common functionality for the realtime MIDI input/output subclasses RtMidiIn and RtMidiOut.

RtMidi GitHub site: https://github.com/thestk/rtmidi RtMidi WWW site: https://caml.music.mcgill.ca/~gary/rtmidi/

RtMidi: realtime MIDI i/o C++ classes Copyright (c) 2003-2023 Gary P. Scavone

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Any person wishing to distribute modifications to the Software is asked to send the modifications to the original developer so that they can be incorporated into the canonical version. This is, however, not a binding provision of this license.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Class Documentation

◆ rt::midi::RtMidi::RtMidiApiAvailability

struct rt::midi::RtMidi::RtMidiApiAvailability

Result returned by checkApiAvailability().

Class Members
bool available = true

True when the API runtime is ready to use.

string message

Human-readable reason if not available.

string installUrl

Installer download URL when a runtime is missing.

Member Enumeration Documentation

◆ Api

MIDI API specifier arguments.

Enumerator
UNSPECIFIED 

Search for a working compiled API.

MACOSX_CORE 

Macintosh OS-X CoreMIDI API.

LINUX_ALSA 

The Advanced Linux Sound Architecture API.

UNIX_JACK 

The JACK Low-Latency MIDI Server API.

WINDOWS_MM 

The Microsoft Multimedia MIDI API.

RTMIDI_DUMMY 

A compilable but non-functional API.

WEB_MIDI_API 

W3C Web MIDI API.

WINDOWS_UWP 

The Microsoft Universal Windows Platform MIDI API.

ANDROID_AMIDI 

Native Android MIDI API.

WINDOWS_MIDI_SERVICES 

Windows MIDI Services (Windows 11 25H2+).

NUM_APIS 

Number of values in this enum.

Member Function Documentation

◆ checkApiAvailability()

static RtMidiApiAvailability rt::midi::RtMidi::checkApiAvailability ( RtMidi::Api  api)
static

Query whether an API can be used by this build on this system.

Call this before constructing any RtMidiIn / RtMidiOut objects that use the specified API. When available is false, message says why, and installUrl holds a download URL if a runtime has to be installed. Windows MIDI Services is available where Windows includes its Windows.Devices.Midi2 API (Windows 11 25H2 and later, as Microsoft rolls it out) and the MIDI service runs in its full mode; elsewhere it is reported as unavailable, and another API can be used. An API that this build does not include is reported as unavailable, and an API that needs no separate runtime is always available. The check is lightweight and does not open any ports.

◆ getCompiledApi()

static void rt::midi::RtMidi::getCompiledApi ( std::vector< RtMidi::Api > &  apis)
throw (
)
static

A static function to determine the available compiled MIDI APIs.

The values returned in the std::vector can be compared against the enumerated list values. Note that there can be more than one API compiled for certain operating systems.

◆ getApiName()

static std::string rt::midi::RtMidi::getApiName ( RtMidi::Api  api)
static

Return the name of a specified compiled MIDI API.

This obtains a short lower-case name used for identification purposes. This value is guaranteed to remain identical across library versions. If the API is unknown, this function will return the empty string.

◆ getApiDisplayName()

static std::string rt::midi::RtMidi::getApiDisplayName ( RtMidi::Api  api)
static

Return the display name of a specified compiled MIDI API.

This obtains a long name used for display purposes. If the API is unknown, this function will return the empty string.

◆ getCompiledApiByName()

static RtMidi::Api rt::midi::RtMidi::getCompiledApiByName ( const std::string &  name)
static

Return the compiled MIDI API having the given name.

A case insensitive comparison will check the specified name against the list of compiled APIs, and return the one which matches. On failure, the function returns UNSPECIFIED.

◆ isPortOpen()

virtual bool rt::midi::RtMidi::isPortOpen ( void  ) const
pure virtual

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.

Implemented in rt::midi::RtMidiIn, and rt::midi::RtMidiOut.

◆ supportsAutoReconnect()

bool rt::midi::RtMidi::supportsAutoReconnect ( void  ) const
inline

Whether this backend can restore connections after device removal.

Support does not guarantee that every device can be identified again. ALSA reconnects identifiable USB ports; closePort() cancels recovery. Matching uses USB vendor/product, serial (or USB location without one), and port number/name. Ambiguous matches are not reconnected. A USB location identifies a socket, not necessarily the same physical unit. Enumeration remains a snapshot; previously saved port indices may change. isPortOpen() continues to describe an explicitly opened connection, including the interval while its device is temporarily absent.

◆ setAutoReconnect()

void rt::midi::RtMidi::setAutoReconnect ( bool  enabled)
inline

Enable or disable automatic recovery (enabled by default when supported).

Disabling recovery leaves an existing MIDI connection intact. Re-enabling it also permits recovery of a device lost while disabled. Monitoring may remain active while recovery is disabled. Unsupported backends ignore this setting and always report false from isAutoReconnectEnabled(). ALSA monitor failures are logged and retried in the background. Persistent worker-start failures use the normal RtMidi error handler on the caller's thread. This setting may wait for an in-progress recovery operation. Serialize openPort(), closePort(), and destruction on each instance as usual. Do not call this setting from a realtime audio or MIDI callback. Messages lost during disconnection are not replayed.

◆ setErrorCallback()

virtual void rt::midi::RtMidi::setErrorCallback ( RtMidiErrorCallback  errorCallback = NULL,
void *  userData = 0 
)
pure virtual

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.

Implemented in rt::midi::RtMidiIn, and rt::midi::RtMidiOut.


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