Your own MIDI transport
How to drive the pedal with the protocol layer alone, through any MIDI library you like, without the device engine. Use this for a web page, an embedded host, mido or python-rtmidi, or a Rust build with default-features = false.
The pieces
Everything here is pure: no I/O, no threads, and (in Rust) no dependencies. You move the bytes; the library does the rest.
| Piece | Rust | Python | Job |
|---|---|---|---|
| Reassembly | Assembler | Assembler | Turns a raw byte stream (any chunking, split SysEx) into whole messages |
| Parsing | Msg::parse | Msg.parse | Classifies a message (CC, PC, SysEx, notification) |
| Pacing | queue::RequestQueue | queue.RequestQueue | One SysEx in flight, reply matching, timeouts, sync progress |
| Startup reads | queue::handshake() | queue.handshake() | The official app's 127 startup reads |
| Follow-ups | queue::follow_up(&msg) | queue.follow_up(data) | Reads to send after pedal notifications that carry no data |
| State | DeviceState | DeviceState | The pedal model (Reading pedal state) |
| Requests | midi::req::* | midi.req.* | Read requests |
| Commands | midi::host::* | midi.host.* | Live CCs/PCs and SysEx writes (Live edits) |
| BLE framing | blemidi | BLE-MIDI packets (below) |
The loop
Three steps, called regularly: send what the queue releases, feed incoming bytes, expire unanswered requests.
use std::time::{Duration, Instant};
use open_stomp::queue::{RequestQueue, follow_up, handshake};
use open_stomp::{Assembler, DeviceState, Msg, Origin};
let mut q = RequestQueue::new(Duration::from_secs(1));
let mut asm = Assembler::default();
let mut state = DeviceState::default();
q.start_sync(handshake());
loop {
// 1. send whatever the queue releases (nothing while a request is in flight)
while let Some(r) = q.pop() {
my_midi_out(r.bytes());
state.apply(r.bytes(), Origin::Host);
q.sent(r, Instant::now());
}
// 2. feed incoming bytes (any chunking) through the assembler
for bytes in asm.push(&my_midi_in()) {
let msg = Msg::parse(&bytes);
q.on_message(&msg); // releases the next request if this answers it
for r in follow_up(&msg) {
q.read(r);
}
state.apply(&bytes, Origin::Pedal);
}
// 3. move on from requests the pedal never answered
q.expire(Instant::now());
}from open_stomp import Assembler, DeviceState, Origin
from open_stomp.queue import RequestQueue, follow_up, handshake
q, asm, state = RequestQueue(timeout=1.0), Assembler(), DeviceState()
q.start_sync(handshake())
def pump(): # call regularly
while (r := q.pop()) is not None: # nothing while a request is in flight
midi_out.send_message(list(r.bytes))
state.apply(r.bytes, Origin.HOST)
q.sent(r)
q.expire() # move on from unanswered requests
def on_midi_in(data: bytes): # any chunking
for msg in asm.push(data):
q.on_message(msg) # releases the next request if it answers
for r in follow_up(msg):
q.read(r)
state.apply(msg, Origin.PEDAL)my_midi_out, my_midi_in and midi_out stand for your transport.
Rules the pedal needs
- One SysEx at a time: the pedal handles one request at a time, so each waits for its reply or ack before the next goes out. The official app serialises the same way, with a 1 s timeout.
- Live CCs and PCs carry no reply. Send them directly at any time.
- Writes go through the queue: use
q.write(bytes)for SysEx writes, and for any message that must keep its place after queued SysEx, so it doesn't interleave with a pending request. - Apply what you send: the pedal never echoes host messages, so apply your own bytes with
Origin::Host. - Channels: the pedal reports on channel 1 and takes commands on channel 2 (
midi::PEDAL_CH= 0,midi::HOST_CH= 1, 0-based). - Bluetooth: space messages at least 15 ms apart; an unpaced burst froze the pedal (Bluetooth).
The framing and command details are in SysEx framing and Commands.
RequestQueue
| Rust | Python | Does |
|---|---|---|
RequestQueue::new(timeout) | RequestQueue(timeout=1.0) | A queue; timeout is how long a request waits for its reply |
start_sync(reqs) | start_sync(requests) | Replace the queue with reqs, whose replies count towards progress |
read(bytes) | read(data) | Queue a read; ignored when the same request is already waiting |
write(bytes) | write(data) | Queue a write. A queued settings or chain write is replaced by a newer one (they are rewritten whole) |
pop() | pop() | The next message to send, if nothing is in flight |
sent(r, now) | sent(r, at=None) | Record that r went out; it is in flight until answered or timed out |
on_message(&msg) | on_message(data) | Feed a complete incoming message; returns the Done it answers, if any |
expire(now) | expire(at=None) | Expire the in-flight request if it waited too long; returns its Done |
progress() | progress | (done, total) of the sync; (0, 0) when none is running |
in_flight(), len(), is_empty(), clear() | in_flight, len(q), is_empty, clear() | Inspect or drop the queue |
Request:bytes(),expect()(what answers it;Nonefor CCs/PCs),is_sync().Done:requestandanswered(false= timed out).- Python times are seconds since the queue was created (
None= now), so tests can drive timeouts without sleeping.
Read requests
midi::req | Reads |
|---|---|
version(), product() | Firmware version and product name (short frames) |
settings() | The global settings (0x14) |
cur_state() | The current state record (0x15) |
drum(), looper(), tuner() | Their records (0x19, 0x18, 0x6F) |
edit_buffer() | The live preset (0x0C), padded with 14 zero bytes like the official app's request |
chain() | The live signal-chain order (0x0D) |
preset(i) | Stored preset i (0x0B) |
ir_slot(i), user_amp(i) | User IR and user AMP slot info (0x09, 0x58) |
Pad the edit-buffer read
The pedal takes request parameters from the padding bytes: a bare 0x0C request makes it read whatever the previous message left in its buffer, giving empty or truncated replies (seen over Bluetooth). req::edit_buffer() pads it for you.
Parsing messages
Rust Msg | Python kind | Meaning |
|---|---|---|
Cc { ch, cc, val } | "cc": ch, cc, val | Control change |
Pc { ch, prog } | "pc": ch, prog | Program change |
Nep { cmd, dir, payload } | "nep": cmd, dir, payload | Vendor SysEx F0 00 21 7A 70 <cmd> <dir> … F7; dir 0 read, 1 write, 2 reply, 3 ack |
Notify { what, payload } | "notify": what, payload | Pedal notification (cmd 0x7E) |
Short { kind, payload } | "short": short_kind, payload | Short frame: 0x00/0x10 version, 0x60 product |
Other(bytes) | "other": payload | Anything else |
Also in midi: frame(cmd, dir, payload) builds a vendor SysEx frame, hex(bytes) formats bytes, Cmd and Dir name the command and direction bytes, and MFR / UID are the header constants. pack::pack / unpack handle the 8-in-7 packing of records.
Bluetooth LE MIDI
The pedal speaks exactly the USB-MIDI protocol over Bluetooth, framed as BLE-MIDI packets. blemidi (Rust only, pure) does the framing:
| Item | Does |
|---|---|
blemidi::encode(&msgs, ts_ms, max) | Frame whole MIDI messages into packets of at most max bytes (≥ 5), several per packet; ts_ms is the 13-bit millisecond timestamp |
blemidi::Decoder::push(&packet) | Decode a packet into whole messages (SysEx across packets, running status) |
SERVICE, CHARACTERISTIC | The standard BLE-MIDI GATT service and characteristic |
MIN_PACKET | 20: the payload size every BLE link supports |
Building from scratch
If you write your own implementation instead, these are the pieces open-stomp uses or that are worth considering:
| Need | Crate | Notes |
|---|---|---|
| MIDI I/O | midir | ALSA on Linux, CoreMIDI on macOS, WinMM on Windows; delivers SysEx whole (enable ignore(Ignore::None)) |
| Raw ALSA (alternative) | alsa | rawmidi, for full control over SysEx buffering |
| macOS hotplug | core-foundation-sys | CoreMIDI delivers device add/remove notifications on the creating thread's run loop |
| Channels | std::sync::mpsc, crossbeam-channel or tokio | midir's input callback runs on its own thread |
| Bluetooth | btleplug | CoreBluetooth, BlueZ, WinRT |
Find the pedal's port by name with is_stomp_port.
