jdxi_editor.midi.io.request_queue

jdxi_editor.midi.io.request_queue One paced queue for all SysEx sent with send_with_delay.

The JD-Xi answers one RQ1 (data request) at a time and drops requests that arrive while it is still sending a reply. Editors used to start a thread each on program change, so dozens of requests (many identical) went out within a few milliseconds and about half were never answered.

The queue sends one message at a time from a single worker thread:

  • an RQ1 is followed by a wait for the DT1 reply at the same address (or a timeout), then a short gap

  • any other message is followed by MIDI_SLEEP_TIME, as before

  • a request that is already queued or waiting for its reply is not queued again; the reply reaches every listener anyway

Replies are reported through notify_reply(); the MIDI helper’s JDXiDevice owns the queue and passes on every incoming message.

Example

>>> sent = []
>>> queue = SysExRequestQueue(sent.append, reply_timeout=0.01)
>>> rq1 = bytes.fromhex("F0 41 10 00 00 00 0E 11 19 42 00 00 00 00 00 40 65 F7")
>>> queue.submit([rq1, rq1])
1
>>> queue.wait_idle(1.0)
True
>>> len(sent)
1

Attributes

ROLAND_ID

RQ1_COMMAND

DT1_COMMAND

SYSEX_START

REPLY_TIMEOUT

REPLY_GAP

Classes

Sysex

Sysex Constants

_Item

SysExRequestQueue

Send messages one at a time, waiting for each RQ1's reply.

Functions

roland_address(data, command) → Optional[str]

4-byte address (hex) of a Roland SysEx message with command, else None.

Module Contents

jdxi_editor.midi.io.request_queue.ROLAND_ID = 65[source]
jdxi_editor.midi.io.request_queue.RQ1_COMMAND = 17[source]
jdxi_editor.midi.io.request_queue.DT1_COMMAND = 18[source]
jdxi_editor.midi.io.request_queue.SYSEX_START = 240[source]
class jdxi_editor.midi.io.request_queue.Sysex[source]

Sysex Constants

START = 240[source]
END = 247[source]
jdxi_editor.midi.io.request_queue.REPLY_TIMEOUT = 0.3[source]
jdxi_editor.midi.io.request_queue.REPLY_GAP = 0.005[source]
jdxi_editor.midi.io.request_queue.roland_address(data: Sequence[int], command: int) → str | None[source]

4-byte address (hex) of a Roland SysEx message with command, else None.

Accepts the message with or without F0 (mido’s sysex.data omits it). Layout without F0: 41, device, model×4, command, address×4, …

class jdxi_editor.midi.io.request_queue._Item[source]
data: bytes[source]
reply_address: str | None[source]
class jdxi_editor.midi.io.request_queue.SysExRequestQueue(send: Callable[[bytes], Any], *, reply_timeout: float = REPLY_TIMEOUT, reply_gap: float = REPLY_GAP, message_gap: float = MIDI_SLEEP_TIME)[source]

Send messages one at a time, waiting for each RQ1’s reply.

_send[source]
_reply_timeout = 0.3[source]
_reply_gap = 0.005[source]
_message_gap = 0.025[source]
_items: collections.deque[_Item][source]
_pending: set[bytes][source]
_awaiting_data: bytes | None = None[source]
_cond[source]
_reply[source]
_awaiting: str | None = None[source]
_busy = False[source]
_worker: threading.Thread | None = None[source]
submit(messages: Iterable[str | bytes | Sequence[int]]) → int[source]

Queue messages (hex strings or bytes); returns how many were queued.

notify_reply(data: Sequence[int]) → None[source]

Report incoming SysEx; a DT1 at the awaited address ends the wait.

The request is no longer pending from this moment: the same request made now (a read starting after this reply) is sent again, instead of being dropped as a duplicate while the queue pauses after the reply.

clear() → int[source]

Drop everything not yet sent (e.g. on disconnect); a request awaiting its reply stops waiting. Returns how many messages were dropped.

wait_idle(timeout: float) → bool[source]

Block until everything queued has been sent (for tests and shutdown).

_ensure_worker() → None[source]
_run() → None[source]
_process(item: _Item) → None[source]