Welcome to libremidi’s documentation!¶
libremidi API¶
Class Hierarchy¶
File Hierarchy¶
Full API¶
Namespaces¶
Classes and Structs¶
Struct chunking_parameters¶
Defined in File libremidi.hpp
Struct Documentation¶
-
struct
libremidi
::
chunking_parameters
¶ Used to determine how large sent messages will be chunked.
Public Members
-
std::chrono::milliseconds
interval
= {}¶
-
int32_t
size
= {}¶
-
std::function<bool(std::chrono::microseconds, int)>
wait
= chunking_parameters::default_wait¶ Will be called by the chunking code to allow the API user to wait.
By default just calls sleep. Arguments are: the time that must be waited, the bytes currently written. Return false if you want to abort the transfer, and true otherwise.
Public Static Functions
-
static inline bool
default_wait
(std::chrono::microseconds time_to_wait, int written_bytes)¶
-
std::chrono::milliseconds
Struct driver_error¶
Defined in File libremidi.hpp
Inheritance Relationships¶
public libremidi::midi_exception
(Struct midi_exception)
Struct Documentation¶
-
struct
libremidi
::
driver_error
: public libremidi::midi_exception¶ Public Functions
-
inline
~driver_error
() override¶
Public Static Attributes
-
static constexpr auto
code
= midi_error::DRIVER_ERROR¶
-
inline
Struct invalid_device_error¶
Defined in File libremidi.hpp
Inheritance Relationships¶
public libremidi::midi_exception
(Struct midi_exception)
Struct Documentation¶
-
struct
libremidi
::
invalid_device_error
: public libremidi::midi_exception¶ Public Functions
-
inline
~invalid_device_error
() override¶
Public Static Attributes
-
static constexpr auto
code
= midi_error::INVALID_DEVICE¶
-
inline
Struct invalid_parameter_error¶
Defined in File libremidi.hpp
Inheritance Relationships¶
public libremidi::midi_exception
(Struct midi_exception)
Struct Documentation¶
-
struct
libremidi
::
invalid_parameter_error
: public libremidi::midi_exception¶ Public Functions
-
inline
~invalid_parameter_error
() override¶
Public Static Attributes
-
static constexpr auto
code
= midi_error::INVALID_PARAMETER¶
-
inline
Struct invalid_use_error¶
Defined in File libremidi.hpp
Inheritance Relationships¶
public libremidi::midi_exception
(Struct midi_exception)
Struct Documentation¶
-
struct
libremidi
::
invalid_use_error
: public libremidi::midi_exception¶ Public Functions
-
inline
~invalid_use_error
() override¶
Public Static Attributes
-
static constexpr auto
code
= midi_error::INVALID_USE¶
-
inline
Struct memory_error¶
Defined in File libremidi.hpp
Inheritance Relationships¶
public libremidi::midi_exception
(Struct midi_exception)
Struct Documentation¶
-
struct
libremidi
::
memory_error
: public libremidi::midi_exception¶ Public Functions
-
inline
~memory_error
() override¶
Public Static Attributes
-
static constexpr auto
code
= midi_error::MEMORY_ERROR¶
-
inline
Struct message¶
Defined in File message.hpp
Struct Documentation¶
-
struct
libremidi
::
message
¶ Public Functions
-
message
() noexcept = default¶
-
inline
message
(const midi_bytes &src_bytes, double src_timestamp)¶
-
inline bool
uses_channel
(int channel) const¶
-
inline int
get_channel
() const¶
-
inline bool
is_meta_event
() const¶
-
inline meta_event_type
get_meta_event_type
() const¶
-
inline message_type
get_message_type
() const¶
-
inline bool
is_note_on_or_off
() const¶
-
inline auto
size
() const¶
-
inline auto &
front
() const¶
-
inline auto &
back
() const¶
-
inline auto &
operator[]
(int i) const¶
-
inline auto &
front
()¶
-
inline auto &
back
()¶
-
inline auto &
operator[]
(int i)¶
-
inline auto
clear
()¶
-
inline auto
begin
() const¶
-
inline auto
end
() const¶
-
inline auto
begin
()¶
-
inline auto
end
()¶
-
inline auto
cbegin
() const¶
-
inline auto
cend
() const¶
-
inline auto
cbegin
()¶
-
inline auto
cend
()¶
-
inline auto
rbegin
() const¶
-
inline auto
rend
() const¶
-
inline auto
rbegin
()¶
-
inline auto
rend
()¶
Public Static Functions
-
static inline uint8_t
make_command
(const message_type type, const int channel) noexcept¶
-
Struct meta_events¶
Defined in File message.hpp
Struct midi_exception¶
Defined in File libremidi.hpp
Inheritance Relationships¶
public runtime_error
public libremidi::driver_error
(Struct driver_error)public libremidi::invalid_device_error
(Struct invalid_device_error)public libremidi::invalid_parameter_error
(Struct invalid_parameter_error)public libremidi::invalid_use_error
(Struct invalid_use_error)public libremidi::memory_error
(Struct memory_error)public libremidi::no_devices_found_error
(Struct no_devices_found_error)public libremidi::system_error
(Struct system_error)public libremidi::thread_error
(Struct thread_error)
Struct Documentation¶
-
struct
libremidi
::
midi_exception
: public runtime_error¶ Base exception class for MIDI problems.
Subclassed by libremidi::driver_error, libremidi::invalid_device_error, libremidi::invalid_parameter_error, libremidi::invalid_use_error, libremidi::memory_error, libremidi::no_devices_found_error, libremidi::system_error, libremidi::thread_error
Public Functions
-
inline
~midi_exception
() override¶
-
inline
Struct no_devices_found_error¶
Defined in File libremidi.hpp
Inheritance Relationships¶
public libremidi::midi_exception
(Struct midi_exception)
Struct Documentation¶
-
struct
libremidi
::
no_devices_found_error
: public libremidi::midi_exception¶ Public Functions
-
inline
~no_devices_found_error
() override¶
Public Static Attributes
-
static constexpr auto
code
= midi_error::NO_DEVICES_FOUND¶
-
inline
Struct observer::callbacks¶
Defined in File libremidi.hpp
Nested Relationships¶
This struct is a nested type of Class observer.
Struct system_error¶
Defined in File libremidi.hpp
Inheritance Relationships¶
public libremidi::midi_exception
(Struct midi_exception)
Struct Documentation¶
-
struct
libremidi
::
system_error
: public libremidi::midi_exception¶ Public Functions
-
inline
~system_error
() override¶
Public Static Attributes
-
static constexpr auto
code
= midi_error::SYSTEM_ERROR¶
-
inline
Struct thread_error¶
Defined in File libremidi.hpp
Inheritance Relationships¶
public libremidi::midi_exception
(Struct midi_exception)
Struct Documentation¶
-
struct
libremidi
::
thread_error
: public libremidi::midi_exception¶ Public Functions
-
inline
~thread_error
() override¶
Public Static Attributes
-
static constexpr auto
code
= midi_error::THREAD_ERROR¶
-
inline
Class midi_in¶
Defined in File libremidi.hpp
Class Documentation¶
-
class
libremidi
::
midi_in
¶ A realtime MIDI input class.
This class provides a common, platform-independent API for realtime MIDI input. It allows access to a single MIDI input port. Incoming MIDI messages are either saved to a queue for retrieval using the getMessage() function or immediately passed to a user-specified callback function. 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 input port to which other MIDI software clients can connect.
by Gary P. Scavone, 2003-2017.
Public Types
Public Functions
-
inline
midi_in
(libremidi::API api = API::UNSPECIFIED, std::string_view clientName = "RtMidi Input Client", unsigned int queueSizeLimit = 100)¶ Default constructor that allows an optional api, client name and queue size.
An exception will be thrown if a MIDI system initialization error occurs. The queue size defines the maximum number of messages that can be held in the MIDI queue (when not using a callback function). If the queue size limit is reached, incoming messages will be ignored.
If no API argument is specified and multiple API support has been compiled, the default order of use is ALSA, JACK (Linux) and CORE, JACK (OS-X).
- Parameters
api
: An optional API id can be specified.clientName
: An optional client name can be specified. This will be used to group the ports that are created by the application.queueSizeLimit
: An optional size of the MIDI input queue can be specified.
-
inline
~midi_in
()¶ If a MIDI connection is still open, it will be closed by the destructor.
-
inline libremidi::API
get_current_api
() const noexcept¶ Returns the MIDI API specifier for the current instance of RtMidiIn.
-
inline void
open_port
(unsigned int portNumber, std::string_view portName)¶ Open a MIDI input connection given by enumeration number.
- Parameters
portNumber
: A port number greater than 0 can be specified. Otherwise, the default or first port found is opened.portName
: A name for the application port that is used to connect to portId can be specified.
-
inline void
open_port
()¶
-
inline void
open_port
(unsigned int port)¶
-
inline void
open_virtual_port
(std::string_view portName)¶ Create a virtual input port, with optional name, to allow software connections (OS X, JACK and ALSA only).
This function creates a virtual MIDI input port to which other software applications can connect. This type of functionality is currently only supported by the Macintosh OS-X, any JACK, and Linux ALSA APIs (the function returns an error for the other APIs).
- Parameters
portName
: An optional name for the application port that is used to connect to portId can be specified.
-
inline void
open_virtual_port
()¶
-
inline void
set_callback
(message_callback callback)¶ Set a callback function to be invoked for incoming MIDI messages.
The callback function will be called whenever an incoming MIDI message is received. While not absolutely necessary, it is best to set the callback function before opening a MIDI port to avoid leaving some messages in the queue.
- Parameters
callback
: A callback function must be given.userData
: Optionally, a pointer to additional data can be passed to the callback function whenever it is called.
-
inline void
cancel_callback
()¶ Cancel use of the current callback function (if one exists).
Subsequent incoming MIDI messages will be written to the queue and can be retrieved with the getMessage function.
-
inline void
close_port
()¶ Close an open MIDI connection (if one exists).
-
inline bool
is_port_open
() const noexcept¶ 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.
-
inline unsigned int
get_port_count
()¶ Return the number of available MIDI input ports.
- Return
This function returns the number of MIDI ports of the selected API.
-
inline std::string
get_port_name
(unsigned int portNumber = 0)¶ Return a string identifier for the specified MIDI input port number.
- Return
The name of the port with the given Id is returned. An empty string is returned if an invalid port specifier is provided. User code should assume a UTF-8 encoding.
-
inline void
ignore_types
(bool midiSysex = true, bool midiTime = true, bool midiSense = true)¶ Specify whether certain MIDI message types should be queued or ignored during input.
By default, MIDI timing and active sensing messages are ignored during message input because of their relative high data rates. MIDI sysex messages are ignored by default as well. Variable values of “true” imply that the respective message type will be ignored.
-
inline message
get_message
()¶ Fill the user-provided vector with the data bytes for the next available MIDI message in the input queue and return the event delta-time in seconds.
This function returns immediately whether a new message is available or not. A valid message is indicated by a non-zero vector size. An exception is thrown if an error occurs during message retrieval or an input connection was not previously established.
-
inline void
set_error_callback
(midi_error_callback errorCallback)¶ Set an error callback function to be invoked when an error has occured.
The callback function will be called whenever an error has occured. It is best to set the error callback function before opening a port.
-
inline void
set_client_name
(std::string_view clientName)¶
-
inline void
set_port_name
(std::string_view portName)¶
-
inline
Class midi_out¶
Defined in File libremidi.hpp
Class Documentation¶
-
class
libremidi
::
midi_out
¶ 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.
by Gary P. Scavone, 2003-2017.
Public Functions
-
inline
midi_out
(libremidi::API api, std::string_view clientName)¶ 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 default order of use is ALSA, JACK (Linux) and CORE, JACK (OS-X).
-
inline
midi_out
()¶
-
inline
~midi_out
()¶ The destructor closes any open MIDI connections.
-
inline libremidi::API
get_current_api
() noexcept¶ Returns the MIDI API specifier for the current instance of RtMidiOut.
-
inline void
open_port
(unsigned int portNumber, std::string_view portName)¶ 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.
-
inline void
open_port
()¶
-
inline void
open_port
(unsigned int port)¶
-
inline void
close_port
()¶ Close an open MIDI connection (if one exists).
-
inline bool
is_port_open
() const noexcept¶ 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.
-
inline void
open_virtual_port
(std::string_view portName)¶ 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 Macintosh OS-X, Linux ALSA and JACK APIs (the function does nothing with the other APIs). An exception is thrown if an error occurs while attempting to create the virtual port.
-
inline void
open_virtual_port
()¶
-
inline unsigned int
get_port_count
()¶ Return the number of available MIDI output ports.
-
inline std::string
get_port_name
(unsigned int portNumber = 0)¶ Return a string identifier for the specified MIDI port type and number.
- Return
The name of the port with the given Id is returned. An empty string is returned if an invalid port specifier is provided. User code should assume a UTF-8 encoding.
-
inline void
send_message
(const std::vector<unsigned char> &message)¶ 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.
-
inline void
send_message
(const unsigned char *message, size_t size)¶ 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.
- Parameters
message
: A pointer to the MIDI message as raw bytessize
: Length of the MIDI message in bytes
-
inline void
set_error_callback
(midi_error_callback errorCallback) noexcept¶ Set an error callback function to be invoked when an error has occured.
The callback function will be called whenever an error has occured. It is best to set the error callback function before opening a port.
-
inline void
set_client_name
(std::string_view clientName)¶
-
inline void
set_port_name
(std::string_view portName)¶
-
inline void
set_chunking_parameters
(std::optional<chunking_parameters> parameters)¶ For large messages, chunk their content and wait. Setting a null optional will disable chunking.
-
inline
Class observer¶
Defined in File libremidi.hpp
Class Documentation¶
Class writer¶
Defined in File writer.hpp
Class Documentation¶
-
class
libremidi
::
writer
¶ Public Functions
-
inline
writer
(int ticks)¶
-
inline
~writer
()¶
-
inline size_t
get_num_tracks
()¶
-
inline void
add_event
(int track, track_event m)¶
-
inline void
add_track
()¶
-
inline void
write
(std::ostream &out)¶
-
inline const std::vector<midi_track> &
get_tracks
()¶
-
inline
Enums¶
Enum API¶
Defined in File libremidi.hpp
Enum Documentation¶
-
enum
libremidi
::
API
¶ MIDI API specifier arguments.
Values:
-
enumerator
UNSPECIFIED
¶ Search for a working compiled API.
-
enumerator
MACOSX_CORE
¶ Macintosh OS-X Core Midi API.
-
enumerator
LINUX_ALSA
¶ The Advanced Linux Sound Architecture API.
-
enumerator
LINUX_ALSA_SEQ
¶
-
enumerator
LINUX_ALSA_RAW
¶ Raw ALSA API.
-
enumerator
UNIX_JACK
¶ The JACK Low-Latency MIDI Server API.
-
enumerator
WINDOWS_MM
¶ The Microsoft Multimedia MIDI API.
-
enumerator
WINDOWS_UWP
¶ The Microsoft WinRT MIDI API.
-
enumerator
EMSCRIPTEN_WEBMIDI
¶ Web MIDI API through Emscripten
-
enumerator
DUMMY
¶ A compilable but non-functional API.
-
enumerator
Enum message_type¶
Defined in File message.hpp
Enum Documentation¶
-
enum
libremidi
::
message_type
¶ Values:
-
enumerator
INVALID
¶
-
enumerator
NOTE_OFF
¶
-
enumerator
NOTE_ON
¶
-
enumerator
POLY_PRESSURE
¶
-
enumerator
CONTROL_CHANGE
¶
-
enumerator
PROGRAM_CHANGE
¶
-
enumerator
AFTERTOUCH
¶
-
enumerator
PITCH_BEND
¶
-
enumerator
SYSTEM_EXCLUSIVE
¶
-
enumerator
TIME_CODE
¶
-
enumerator
SONG_POS_POINTER
¶
-
enumerator
SONG_SELECT
¶
-
enumerator
RESERVED1
¶
-
enumerator
RESERVED2
¶
-
enumerator
TUNE_REQUEST
¶
-
enumerator
EOX
¶
-
enumerator
TIME_CLOCK
¶
-
enumerator
RESERVED3
¶
-
enumerator
START
¶
-
enumerator
CONTINUE
¶
-
enumerator
STOP
¶
-
enumerator
RESERVED4
¶
-
enumerator
ACTIVE_SENSING
¶
-
enumerator
SYSTEM_RESET
¶
-
enumerator
Enum meta_event_type¶
Defined in File message.hpp
Enum Documentation¶
-
enum
libremidi
::
meta_event_type
¶ Values:
-
enumerator
SEQUENCE_NUMBER
¶
-
enumerator
TEXT
¶
-
enumerator
COPYRIGHT
¶
-
enumerator
TRACK_NAME
¶
-
enumerator
INSTRUMENT
¶
-
enumerator
LYRIC
¶
-
enumerator
MARKER
¶
-
enumerator
CUE
¶
-
enumerator
PATCH_NAME
¶
-
enumerator
DEVICE_NAME
¶
-
enumerator
CHANNEL_PREFIX
¶
-
enumerator
MIDI_PORT
¶
-
enumerator
END_OF_TRACK
¶
-
enumerator
TEMPO_CHANGE
¶
-
enumerator
SMPTE_OFFSET
¶
-
enumerator
TIME_SIGNATURE
¶
-
enumerator
KEY_SIGNATURE
¶
-
enumerator
PROPRIETARY
¶
-
enumerator
UNKNOWN
¶
-
enumerator
Enum midi_error¶
Defined in File libremidi.hpp
Enum Documentation¶
-
enum
libremidi
::
midi_error
¶ Defines various error types.
Values:
-
enumerator
WARNING
¶ A non-critical error.
-
enumerator
UNSPECIFIED
¶ The default, unspecified error type.
-
enumerator
NO_DEVICES_FOUND
¶ No devices found on system.
-
enumerator
INVALID_DEVICE
¶ An invalid device ID was specified.
-
enumerator
MEMORY_ERROR
¶ An error occured during memory allocation.
-
enumerator
INVALID_PARAMETER
¶ An invalid parameter was specified to a function.
-
enumerator
INVALID_USE
¶ The function was called incorrectly.
-
enumerator
DRIVER_ERROR
¶ A system driver error occured.
-
enumerator
SYSTEM_ERROR
¶ A system error occured.
-
enumerator
THREAD_ERROR
¶ A thread error occured.
-
enumerator
Functions¶
Function libremidi::available_apis¶
Defined in File libremidi.cpp
Function Documentation¶
Warning
doxygenfunction: Unable to resolve function “libremidi::available_apis” with arguments () in doxygen xml output for project “libremidi” from directory: ./doxyoutput/xml. Potential matches:
- std::vector<libremidi::API> available_apis() noexcept
Function libremidi::clamp¶
Defined in File message.hpp
Template Function libremidi::for_all_backends¶
Defined in File libremidi.cpp
Function libremidi::get_version¶
Defined in File libremidi.cpp
Function Documentation¶
Warning
doxygenfunction: Unable to resolve function “libremidi::get_version” with arguments () in doxygen xml output for project “libremidi” from directory: ./doxyoutput/xml. Potential matches:
- std::string get_version() noexcept
Function libremidi::open_midi_in¶
Defined in File libremidi.cpp
Function libremidi::open_midi_out¶
Defined in File libremidi.cpp
Function libremidi::parseEvent¶
Defined in File reader.cpp
Function Documentation¶
-
inline track_event
libremidi
::
parseEvent
(int tick, int track, uint8_t const *&dataStart, message_type lastEventTypeByte)¶
Function libremidi::util::read_bytes¶
Defined in File reader.cpp
Function Documentation¶
-
inline void
libremidi::util
::
read_bytes
(midi_bytes &buffer, uint8_t const *&data, int num)¶
Function libremidi::util::read_uint16_be¶
Defined in File reader.cpp
Function libremidi::util::read_uint24_be¶
Defined in File reader.cpp
Function libremidi::util::read_uint32_be¶
Defined in File reader.cpp
Function libremidi::util::read_variable_length¶
Defined in File reader.cpp
Function libremidi::util::write_double_be¶
Defined in File writer.cpp
Function libremidi::util::write_float_be¶
Defined in File writer.cpp
Function libremidi::util::write_int16_be¶
Defined in File writer.cpp
Function libremidi::util::write_int32_be¶
Defined in File writer.cpp
Function libremidi::util::write_uint16_be¶
Defined in File writer.cpp
Function libremidi::util::write_uint32_be¶
Defined in File writer.cpp
Function libremidi::util::write_variable_length¶
Defined in File writer.cpp
Variables¶
Variable libremidi::available_backends¶
Defined in File libremidi.cpp
Defines¶
Define LIBREMIDI_DUMMY¶
Defined in File libremidi.cpp
Define Documentation¶
Warning
doxygendefine: Cannot find define “LIBREMIDI_DUMMY” in doxygen xml output for project “libremidi” from directory: ./doxyoutput/xml
Typedefs¶
Typedef libremidi::midi_bytes¶
Defined in File message.hpp
Typedef libremidi::midi_error_callback¶
Defined in File libremidi.hpp
Typedef Documentation¶
-
using
libremidi
::
midi_error_callback
= std::function<void(midi_error type, std::string_view errorText)>¶ Error callback function.
Note that class behaviour is undefined after a critical error (not a warning) is reported.
- Parameters
type
: Type of error.errorText
: Error description.
Typedef libremidi::midi_track¶
Defined in File message.hpp
Typedef Documentation¶
-
typedef std::vector<track_event>
libremidi
::
midi_track
¶