bbx_midi
MIDI message parsing and streaming utilities for audio applications.
Features
- MIDI message parsing: Parse raw MIDI bytes into structured messages
- Message type helpers: Extract note, velocity, pitch wheel, control data
- Lock-free buffer: Thread-safe SPSC ring buffer for MIDI-to-audio communication
- Input streaming: Real-time MIDI input via
midir - FFI compatible:
#[repr(C)]types for C interop
Message Types
NoteOn/NoteOff- Note events with velocityControlChange- CC messages (mod wheel, sustain, etc.)PitchWheel- Pitch bend with 14-bit resolutionProgramChange- Instrument/patch changesPolyphonicAftertouch- Per-note pressureChannelAftertouch- Channel-wide pressure
MidiEvent
For sample-accurate MIDI timing in audio callbacks:
use ;
let event = MidiEvent ;
Used with PluginDsp::process() for synthesizer plugins.
Usage
use ;
// Parse raw MIDI bytes
let msg = new; // Note On, C4, velocity 100
if msg.get_status == NoteOn
Lock-Free MIDI Buffer
For thread-safe communication between MIDI and audio threads:
use ;
// Create producer/consumer pair
let = midi_buffer;
// MIDI thread: push messages
let msg = new;
producer.try_send;
// Audio thread: pop messages (realtime-safe)
while let Some = consumer.try_pop
The buffer uses an SPSC ring buffer internally, making all consumer operations lock-free and allocation-free for real-time safety.
Cargo Features
streaming
Enables real-time MIDI input via midir:
[]
= { = "...", = ["streaming"] }
use ;
// Create stream with optional filters
let stream = new;
// Start listening (prompts for port selection)
let handle = stream.init;
Used by bbx_sandbox for terminal-based DSP testing with live MIDI input.
License
MIT