Skip to main content

A modern C++ MIDI 1 / MIDI 2 real-time & file I/O library. Supports Windows, macOS, Linux and WebMIDI.

Project description

libremidi

Build status

Packaging status

libremidi is a cross-platform C++20 library for real-time and MIDI file input and output.

This is a fork / rewrite based on two libraries:

Additionnally, for MIDI 2 parsing support we use cmidi2!

Read the documentation here.

Citation

If you use this work as part of academic research, please kindly cite the paper:

@inproceedings{celerier2024libremidi,
  title={libremidi: a cross-platform library for real-time MIDI 1 and 2},
  author={Celerier, Jean-Micha{\"e}l},
  booktitle={Proceedings of the Sound and Music Computing Conference (SMC)},
  year={2024},
  address={Porto, Portugal}
}

Changelog

Since v5.4

  • ALSA: observation will now slightly be delayed as otherwise udev fields are sometimes not populated yet.
  • Port the Android backend from RtMidi, developed by @YellowLabrador.
  • C++: add initial C++ modules support: import libremidi;. So far compilers other than Clang 20+ crash. Enable with -DLIBREMIDI_LIBRARY_MODE=MODULE. Note that one cannot mix a module-based and a non-module based API. An example is provided in examples/modules.cpp
  • Add a utility libremidi::set_client_name / client_name function to simplify construction of an API object with a custom client name.
  • Many improvements to MIDI 1 <-> MIDI 2 conversion, every MIDI 1 message is supported now.
  • Port information: add as much metadata as we can get from the host API.
  • Port information: remove sorting and comparison as there's no generally correct way to compare two port_information / input_port / output_port objects. Multiple ways of doing this comparison depending on the use case have been provided as examples in <libremidi/port_comparison.hpp>.
  • Port information: added a heuristics-based libremidi::find_closest_port(query, existing_ports) utility function which tries to lookup the most likely candidate for a MIDI port across backends with the lookup information that can be provided.
  • Python: add a pyproject.toml to facilitate integration with the Python ecosystem. Thanks @TheStaticTurtle!
  • Windows MIDI Services: support updated to the RC1 release headers.
  • Windows MIDI Services: add support for the newly introduced COM fast-path to provide maximum performance.

Since v5.3

  • Minor bugfixes
  • More MinGW CI
  • Add an example of converting MIDI files to .pat format
  • MSVC ARM64 CI

Since v5.2

  • Minor bugfixes
  • Support detecting presence of ALSA sequencer at runtime
  • Add conversion functions for MIDI 1 <-> 2

Since v5.1

  • Report USB device identifiers with ALSA and udev
  • PipeWire and JACK UMP support (requires PipeWire v1.4+)

Since v5

  • Use stdx::error for error reporting until C++26 and std::error are widely available :-)
  • Hunt exceptions down
  • MIDI 2 support on Windows with the Windows MIDI Services.
  • WinUWP support on MinGW / MSYS2.
  • Getters for USB location, etc. in libremidi::port_information.
  • Reverse-engineered implementation of Mackie Control Universal & Logic Control protocols. Tested with TouchMCU and a BCF2000.
  • C API for bindings to other languages (libremidi-c.h).
  • Python binding.
  • Haskell binding courtesy of @ejconlon λ!
  • Java binding courtesy of @atsushieno!
  • Support for getting raw, unfiltered MIDI data (e.g. no SYSEX recombination logic).
  • Computer Keyboard backend to easily map scancodes to keyboard-like MIDI maps ⌨.
  • Network backend to send MIDI 1 and UMP packets over OSC 🛜.
  • libremidi finally supports MIDI 2 on all desktop platforms 🎉!

Since v4.5

  • Input logic refactored across all backends.
    • e.g. previously not backends had the same rules wrt timestamping, sysexes, etc. Now there is a single MIDI state machine which processes this.
  • PipeWire support.
  • Many bugfixes across the stack.

Since v4.4

  • iOS support restored (thanks @fwcd)
  • CI work: added Debian Bullseye, Bookworm, Trixie and make sure UMP code is being built.
  • Add compatibility with ni-midi2: the libremidi::ump type will convert automatically from / to midi::universal_packet and it is possible to send directly some ni-midi2 data types through libremidi::midi_out.
  • Added an example of very basic MIDI-CI interoperation with MIDI2.0Workbench: https://github.com/jcelerier/libremidi/blob/master/examples/midi2_interop.cpp
  • Observer: add a track_any flag to track MIDI ports that are not reported as being hardware or software.
  • UMP: allow send_ump to handle UMP streams, not only single UMP packets.

Since v4.3

  • Improvements to timing handling.
    • Added a Custom timestamping mechanism which allows the user to provide a custom callback to run timestamping as close as possible to the event's reception.
    • Added midi_in::absolute_timestamp() to get the origin timestamp for driver-provided ticks as accurately as possible.
      • e.g. in practice this is taking the time just near the ALSA queue creation or WinMM MIDI open.
    • Bugfixes in JACK
    • Many warning fixes - thanks @lilggamegenius for the extensive work!
    • Fix MIDI dump example - thanks @chdiesch!
    • Add SOVERSION to dynamic library

Since v4.2

  • More robust MIDI 2.0 support.
    • On macOS through CoreMIDI (input / output, requires macOS 11+).
    • On Linux through ALSA sequencer API (input / output, requires kernel 6.5+ and latest libasound).
    • The API can be used through MIDI 1 or MIDI 2 affordances, e. g. one can send UMP packets to a MIDI 1 API, they will get converted automatically.
    • More backends to come, in particular with the new Windows MIDI Services started here!
    • Sysex handling on MIDI 2.0 is the responsibility of the user of the library, which simplifies the design immensely and allows the library to be used in stricter real-time contexts (as an UMP message has a fixed size, unlike MIDI 1 sysex which required potentially unbounded dynamic allocations with the previous design).
    • See midi_echo.cpp for a complete example.
  • Linux: libasound and udev are now entirely loaded at run-time through dlopen. This is necessary for making apps that will run on older Linux versions which do not have the ALSA UMP APIs yet. Note that to make an app which supports MIDI 2 on recent Linuxes and still runs on older ones, you will need to use the latest ALSA library headers as part of your build on an older distribution, by building alsa-lib yourself (as the old distributions with an old glibc that you want to build against to make compatible software of course also ship an old libasound which won't have the UMP API...).

Since v4

  • Experimental MIDI 2.0 support.
  • A neat configuration system which enables to pass options to the underlying backends.
  • Possibility to share the contexts across inputs and outputs to avoid creating multiple clients in e.g. JACK.
  • Hotplug support for all the backends!
  • Reworked port opening API which now uses handles instead of port indices to increase robustness in the face of disconnection / reconnection of MIDI devices.
  • Integer timestamps everywhere, and in nanoseconds. Additionnally, it is now possible to choose different timestamping methods (e.g. relative, absolute monotonic clock...).
  • Experimental API to allow to poll manually in ALSA (Sequencer and Raw), in order to give more control to the user and enable processing events on any kind of Linux event-loop.
  • Increase the checks done by the MIDI parser.
  • Internally it's pretty much a complete rewrite. Standard threading primitives are now used, as well as modern Linux facilities for polling control (eventfd, timerfd). Most of the code has been refactored.
  • Ability to set a fixed message size for zero-allocation scenarios, with -DLIBREMIDI_SLIM_MESSAGE=<NBytes> (in CMake or directly to the compiler)

Since v3

  • Allow to pass span when available (C++20) or (uint8_t* bytes, std::size_t size) pairs whenever possible to reduce copying.

Since v1

  • The library can be used header-only, as explained in the docs
  • Callbacks are passed by std::function and generally simplified.
  • Ability to use boost::small_vector to pass midi bytes instead of std::vector to reduce allocations.
  • Less indirections, virtuals and memory allocations.
  • Simplify usage of some functions, use C++ return style everywhere.
  • Use of standard C++ snake_case.
  • Simplification of exceptions.
  • Passes clean through clang-tidy, clang analyzer, GCC -Wall -Wextra, ASAN, UBSAN etc etc.
  • Support chunking of output data (only supported on raw ALSA backend so far).

New & improved backends

  • JACK support on Windows.
  • JACK support through weakjack to allow runtime loading of JACK.
  • UWP MIDI support on Windows
  • Emscripten support to run on a web browser with WebMIDI.
  • Raw ALSA support in addition to the existing ALSA sequencer support.

Roadmap

  • Migrate to std::expected instead of exceptions for error handling.
  • Finish MIDI 2 implementations, provide helpers, etc.
  • More tests and compliance checks
  • Work even more towards this library being a zero-cost abstraction on top of native MIDI APIs
  • Rethink some design issues with the original RtMidi, for instance the way port numbers work is not reliable
  • Refactor duplicated code across backends

They use this library

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylibremidi-5.4.1.tar.gz (15.7 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pylibremidi-5.4.1-cp314-cp314t-win_amd64.whl (652.5 kB view details)

Uploaded CPython 3.14tWindows x86-64

pylibremidi-5.4.1-cp314-cp314t-win32.whl (597.5 kB view details)

Uploaded CPython 3.14tWindows x86

pylibremidi-5.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl (918.8 kB view details)

Uploaded CPython 3.14tmusllinux: musl 1.2+ x86-64

pylibremidi-5.4.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (463.2 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pylibremidi-5.4.1-cp314-cp314t-macosx_11_0_arm64.whl (430.7 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

pylibremidi-5.4.1-cp310-abi3-win_amd64.whl (632.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

pylibremidi-5.4.1-cp310-abi3-win32.whl (582.9 kB view details)

Uploaded CPython 3.10+Windows x86

pylibremidi-5.4.1-cp310-abi3-musllinux_1_2_x86_64.whl (912.0 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

pylibremidi-5.4.1-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (457.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

pylibremidi-5.4.1-cp310-abi3-macosx_11_0_arm64.whl (427.2 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file pylibremidi-5.4.1.tar.gz.

File metadata

  • Download URL: pylibremidi-5.4.1.tar.gz
  • Upload date:
  • Size: 15.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pylibremidi-5.4.1.tar.gz
Algorithm Hash digest
SHA256 a39f888c75d61b0c58541c6c4086d4744ef52145124a1456583b33c8f9b78e22
MD5 b08f508b8800306c56fb198db560481b
BLAKE2b-256 912cd9970b1653ae4aa43fa7299011d0e736fb4d5b960e3e5ea33b8eae5fc709

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1.tar.gz:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylibremidi-5.4.1-cp314-cp314t-win_amd64.whl.

File metadata

File hashes

Hashes for pylibremidi-5.4.1-cp314-cp314t-win_amd64.whl
Algorithm Hash digest
SHA256 286f320400b11d2a34b937d34894264398dad07dd84481321342e0fdacbf6ffa
MD5 4366c39bc505e243da598be3a45a644f
BLAKE2b-256 32be4c9062c1973eedd478feabbae1e8895d3408afeab8f4fb789a09641b6e4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1-cp314-cp314t-win_amd64.whl:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylibremidi-5.4.1-cp314-cp314t-win32.whl.

File metadata

  • Download URL: pylibremidi-5.4.1-cp314-cp314t-win32.whl
  • Upload date:
  • Size: 597.5 kB
  • Tags: CPython 3.14t, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pylibremidi-5.4.1-cp314-cp314t-win32.whl
Algorithm Hash digest
SHA256 565cab83f3d338329641564a578491dd731ce40ae9008ce2aef29fca042a7acb
MD5 e009f93fe5b77ec0df143e2dede449b4
BLAKE2b-256 e2058b1180093e53b96870378f2692b959f0dd4c42081566edb91dec72aa574e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1-cp314-cp314t-win32.whl:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylibremidi-5.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pylibremidi-5.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5fd4d16c51e8b103846919c8a9501c45eb65bf939c4ff225638db02614ef08f9
MD5 b97e19b45cc116c834a660322a5c5360
BLAKE2b-256 1508c02cbcbb560e29498fbdfc259d6bae149c200afe495573e745bae17a417d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylibremidi-5.4.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylibremidi-5.4.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1686ef616b8b0f1f080355418ff76f0a0b7d082848295ae151d6505660c72686
MD5 784f9d04462dd0b76b8168cb0ce38e14
BLAKE2b-256 c0283c30ad3a26efadeb61eb9971cfbf4576ebed0be1fdb782996a3b43197569

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylibremidi-5.4.1-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylibremidi-5.4.1-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 755aa6549bc43ae83245c213ebcb658beadcd284d56a02b9e12ee7599c89e28a
MD5 9f756124df6875c512e3cac5f320ea74
BLAKE2b-256 568fb52b078e5718b3b4cc7ba8fa3e49198c77167b70b8054e4a64e027636f1f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylibremidi-5.4.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: pylibremidi-5.4.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 632.4 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pylibremidi-5.4.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8ff0de30c588378ad67dba0d0edabb30479be6d83b7fd6761c2a093e1cdf0623
MD5 57591396b96b63df6aab8fd3b2a519c3
BLAKE2b-256 7ab3c0488378d22f2cd7f0af7706e8bdad38678e765d9e803d7fde4b88399d6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1-cp310-abi3-win_amd64.whl:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylibremidi-5.4.1-cp310-abi3-win32.whl.

File metadata

  • Download URL: pylibremidi-5.4.1-cp310-abi3-win32.whl
  • Upload date:
  • Size: 582.9 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pylibremidi-5.4.1-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 76bc922452a32dc9c47239e877e7042b59f7489a7059cb997076c11a99eddabe
MD5 193d391f81ed32a9c644f005776c546b
BLAKE2b-256 b31f84bf91e38b1706c76019e48fe6ce8b9f8b050e2c9636dcb3089c34bf14bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1-cp310-abi3-win32.whl:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylibremidi-5.4.1-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pylibremidi-5.4.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 28dbc807944d4fe950bf67ad109d8be2cd626a1d0644a4ec1db90baec74bc650
MD5 b98c3e51d8e245a628c872a3b463b4cc
BLAKE2b-256 a44fc85a600daa301fc0adaf4ce50409ef23dcfc6df7d9e236857fffbaa2f24b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylibremidi-5.4.1-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pylibremidi-5.4.1-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5be9691633b02f7d87962af5520fcc70fe92e373bbceac1c017828a61632880b
MD5 09a4ed848909992f849a31ba147a4039
BLAKE2b-256 74d50fa9c6e60a16179699ca17adaedbf6ebfcce5ac7a5be6c54a98fd986b861

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pylibremidi-5.4.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylibremidi-5.4.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1221bb26f908a3f0daa7686454ae398a4f09539b7beb26a409d4d930c944f468
MD5 110348ed0b458fef27ae1b35bb36e70f
BLAKE2b-256 b8eaef9e9d1f348a19f9002c85b7f658503450c301191ff3bcb48c4788d06259

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylibremidi-5.4.1-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: publish_pypi.yml on celtera/libremidi

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page