jdxi_editor.midi.io.request_queue ================================= .. py:module:: jdxi_editor.midi.io.request_queue .. autoapi-nested-parse:: 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. .. rubric:: 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 ---------- .. autoapisummary:: jdxi_editor.midi.io.request_queue.ROLAND_ID jdxi_editor.midi.io.request_queue.RQ1_COMMAND jdxi_editor.midi.io.request_queue.DT1_COMMAND jdxi_editor.midi.io.request_queue.SYSEX_START jdxi_editor.midi.io.request_queue.REPLY_TIMEOUT jdxi_editor.midi.io.request_queue.REPLY_GAP Classes ------- .. autoapisummary:: jdxi_editor.midi.io.request_queue.Sysex jdxi_editor.midi.io.request_queue._Item jdxi_editor.midi.io.request_queue.SysExRequestQueue Functions --------- .. autoapisummary:: jdxi_editor.midi.io.request_queue.roland_address Module Contents --------------- .. py:data:: ROLAND_ID :value: 65 .. py:data:: RQ1_COMMAND :value: 17 .. py:data:: DT1_COMMAND :value: 18 .. py:data:: SYSEX_START :value: 240 .. py:class:: Sysex Sysex Constants .. py:attribute:: START :value: 240 .. py:attribute:: END :value: 247 .. py:data:: REPLY_TIMEOUT :value: 0.3 .. py:data:: REPLY_GAP :value: 0.005 .. py:function:: roland_address(data: Sequence[int], command: int) -> Optional[str] 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, ... .. py:class:: _Item .. py:attribute:: data :type: bytes .. py:attribute:: reply_address :type: Optional[str] .. py:class:: SysExRequestQueue(send: Callable[[bytes], Any], *, reply_timeout: float = REPLY_TIMEOUT, reply_gap: float = REPLY_GAP, message_gap: float = MIDI_SLEEP_TIME) Send messages one at a time, waiting for each RQ1's reply. .. py:attribute:: _send .. py:attribute:: _reply_timeout :value: 0.3 .. py:attribute:: _reply_gap :value: 0.005 .. py:attribute:: _message_gap :value: 0.025 .. py:attribute:: _items :type: collections.deque[_Item] .. py:attribute:: _pending :type: set[bytes] .. py:attribute:: _awaiting_data :type: Optional[bytes] :value: None .. py:attribute:: _cond .. py:attribute:: _reply .. py:attribute:: _awaiting :type: Optional[str] :value: None .. py:attribute:: _busy :value: False .. py:attribute:: _worker :type: Optional[threading.Thread] :value: None .. py:method:: submit(messages: Iterable[Union[str, bytes, Sequence[int]]]) -> int Queue *messages* (hex strings or bytes); returns how many were queued. .. py:method:: notify_reply(data: Sequence[int]) -> None 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. .. py:method:: clear() -> int Drop everything not yet sent (e.g. on disconnect); a request awaiting its reply stops waiting. Returns how many messages were dropped. .. py:method:: wait_idle(timeout: float) -> bool Block until everything queued has been sent (for tests and shutdown). .. py:method:: _ensure_worker() -> None .. py:method:: _run() -> None .. py:method:: _process(item: _Item) -> None