Boddlnagg/midir
Acerca de
Procesamiento MIDI en tiempo real y multiplataforma con Rust.
Diseño y multimediaWhat you can do
- WinMM (Windows)
- CoreMIDI (macOS, iOS)
- WinRT (Windows 8+), enable the winrt feature
- Windows MIDI Services (Windows 11 25H2+, 64-bit apps), enable the winmidi2 feature
Crecimiento de estrellas medido
- in 24h
- 0
- in 7 days
- +2
- in 15 days
- +4
- in 1 month
- +14
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
README.md
Originalmidir 
Cross-platform, realtime MIDI processing in Rust.
Features
midir is inspired by RtMidi and supports the same features*, including virtual ports (except on Windows) and full SysEx support – but with a rust-y API!
* With the exception of message queues, but these can be implemented on top of callbacks using e.g. Rust's channels.
midir currently supports the following platforms/backends:
- ALSA (Linux)
- WinMM (Windows)
- CoreMIDI (macOS, iOS)
- WinRT (Windows 8+), enable the
winrtfeature - Windows MIDI Services (Windows 11 25H2+, 64-bit apps), enable the
winmidi2feature - Jack (Linux, macOS), enable the
jackfeature - Web MIDI (Chrome, Opera, perhaps others browsers)
- Android (API 29+, NDK AMidi + JNI)
A higher-level API for parsing and assembling MIDI messages might be added in the future.
Documentation & Example
API docs can be found at docs.rs. You can find some examples in the examples directory. Or simply run cargo run --example test_play after cloning this repository.
Android
- Requires Android API 29+ and the Android NDK (r20b+).
- Build (example, to remove before merging):
- Install:
cargo install cargo-ndk - Targets:
rustup target add aarch64-linux-android - Build:
cargo ndk -t arm64-v8a -o ./app/src/main/jniLibs build --release
- Install:
- Permissions/features:
- Manifest should declare
<uses-feature android:name="android.software.midi" android:required="false" />(not needed for USB/BLE MIDI).
- Manifest should declare
Windows MIDI Services (Preview)
The winmidi2 feature uses Windows MIDI Services (Windows.Devices.Midi2) instead of WinMM. midir's API stays the same. You see the same MIDI 1.0 ports that WinMM apps see, with the same names and in the same order. The one exception is the Microsoft GS Wavetable Synth, which only WinMM lists, so an output port's position in the list can be one lower than with the WinMM backend. Don't save a port's position to find it again later, with any backend: positions change whenever a device is plugged in or removed. Save the port's id or name instead. Messages from MIDI 2.0 devices are converted to MIDI 1.0, and timestamps are in microseconds, like the other backends.
What it needs:
- Windows 11 25H2 or later. On older versions of Windows,
MidiInput::newandMidiOutput::newreturn an error. - A 64-bit app (x64 or Arm64). The Windows MIDI Services API is only available to 64-bit apps, so the
winmidi2feature doesn't build for 32-bit targets. - Windows MIDI Services in its normal mode. If the PC is set to Legacy API mode,
MidiInput::newandMidiOutput::newreturn an error. - The API DLL, until it's part of Windows. That's planned for 2027. Until then, your app has to ship
Windows.Devices.Midi2.dllandWindows.Devices.Midi2.priin the same folder as its.exe. They're in theruntimes\win-x64\nativeandruntimes\win-arm64\nativefolders of theWindows.Devices.Midi2NuGet package on the Windows MIDI Services releases page. When Windows has its own copy, Windows uses that one instead of yours, so your app keeps working. Shipping these files is your choice as the app developer, and the release notes list the terms that come with it.
The winmidi2 feature can't be combined with winrt. Virtual ports aren't supported yet.
Ports change while your app runs
midir can't tell your app when a port is added, removed or renamed. That's a gap in midir today, with every backend. Most of this was already true with WinMM, but it happens much more with Windows MIDI Services:
- People can rename ports. A port's name can change while your app is running.
- Ports come and go. Bluetooth LE MIDI, Network MIDI 2.0 and other newer transports add and remove ports often. Windows keeps the WinMM port numbers in one unbroken run, so when a port goes away, the numbers after it move down. A device that's removed and comes back often gets a different number.
- Don't check for new ports in a tight loop. Each full check is hard on Windows' Plug and Play system. If it runs on your UI thread and the PC has more than a few ports, your app can stop responding, and Windows will mark it as not responding.
Windows MIDI Services has a port watcher (MidiLegacyPortDeviceWatcher) for exactly these reasons. The winmidi2 backend uses one behind the scenes. It keeps its own port list up to date, so ports(), port_count() and port_name() read that list instead of asking Plug and Play each time. The first of these calls in a process waits for the watcher's first full list. Still, call them when you need them (for example when the user opens a port menu), not on a timer.
To regenerate the bindings in src/backend/winmidi2/bindings.rs, see tools/winmidi2-bindgen.
Explorar proyectos relacionados
Cargando…