jdxi_editor.midi.io.external_controller ======================================= .. py:module:: jdxi_editor.midi.io.external_controller .. autoapi-nested-parse:: External controller input ========================= MIDI input from a hardware controller such as the Arturia MiniLab 3, separate from the JD-Xi's. Its messages are shown in the MIDI Monitor and its control changes are emitted as :attr:`ExternalControllerInput.control_changed`; they are not passed to the JD-Xi input handler, so editors do not mistake a knob turn for the synth reporting a change. Every port the controller exposes is opened, not just the one that looks like its main port: a MiniLab 3 sends its knobs and faders on the port belonging to its current mode (Arturia, DAW, Analog Lab), so listening to one port means a knob turn is missed whenever the device is in another mode. Each port is parsed separately, because a MIDI parser carries running status from one message to the next and two interleaved streams would corrupt each other. :meth:`ExternalControllerInput.rescan` picks up a controller plugged in after the application started. RtMidi callbacks must not call into Qt: on macOS, emitting signals (or any Qt work) from the MIDI thread while another port is still opening deadlocks CoreMIDI. Incoming bytes are queued and drained on the GUI thread instead. Attributes ---------- .. autoapisummary:: jdxi_editor.midi.io.external_controller._PUMP_INTERVAL_MS jdxi_editor.midi.io.external_controller._PORT_OPEN_STAGGER_MS Classes ------- .. autoapisummary:: jdxi_editor.midi.io.external_controller.ExternalControllerInput Module Contents --------------- .. py:data:: _PUMP_INTERVAL_MS :value: 5 .. py:data:: _PORT_OPEN_STAGGER_MS :value: 50 .. py:class:: ExternalControllerInput(parent: Optional[PySide6.QtCore.QObject] = None) Bases: :py:obj:`PySide6.QtCore.QObject` MIDI input from a hardware controller. .. py:attribute:: message_received .. py:attribute:: control_changed .. py:attribute:: ports_changed .. py:attribute:: _inputs :type: dict[str, rtmidi.MidiIn] .. py:attribute:: _parsers :type: dict[str, mido.Parser] .. py:attribute:: _probe .. py:attribute:: port_name :type: Optional[str] :value: None .. py:attribute:: _pending :type: collections.deque[tuple[str, mido.Message]] .. py:attribute:: _pump .. py:attribute:: _ports_to_open :type: list[str] :value: [] .. py:property:: port_names :type: list[str] Names of every controller port being listened to. :return: list[str] .. py:property:: is_open :type: bool Whether any controller port is open. :return: bool .. py:property:: profile :type: Optional[jdxi_editor.midi.io.controller_map.ControllerProfile] The supported controller being listened to or, before any port is open, the one that is plugged in. :return: Optional[ControllerProfile] None if no supported controller is connected .. py:method:: available_ports() -> list[str] Names of all MIDI input ports. :return: list[str] .. py:method:: auto_connect() -> bool Open every supported controller port that is connected. :return: bool True if at least one controller port was opened .. py:method:: connect_ports(port_names: list[str]) -> bool Listen to exactly ``port_names``, closing any other port already open. New ports are opened one at a time on a timer so CoreMIDI can breathe between opens (opening several back-to-back next to an active JD-Xi input deadlocks on macOS). Callbacks are installed only after each port's ``open_port`` returns. :attr:`ports_changed` is emitted when the batch finishes. :param port_names: list[str] MIDI input port names :return: bool True if a port is already open or a batch was started .. py:method:: _open_next_port() -> None Open the next queued controller port, then schedule the rest. :return: None .. py:method:: _finish_port_batch() -> None Start the GUI pump and announce the ports now listened to. :return: None .. py:method:: connect_port(port_name: str) -> bool Listen to ``port_name`` alone, closing any port already open. :param port_name: str MIDI input port name :return: bool True if the port was opened .. py:method:: rescan() -> list[str] Match the open ports to what is plugged in now. Opens controller ports that have appeared since the last scan and drops ones that have gone, so a controller connected after startup is picked up. :attr:`ports_changed` is emitted when the open set changes (after any staggered opens finish). :return: list[str] names of the ports already open (new ones may still be opening) .. py:method:: close() -> None Close every controller port. :return: None .. py:method:: _open_port(port_name: str, *, install_callback: bool = True) -> bool Open one port and listen to it, if it is not open already. :param port_name: str MIDI input port name :param install_callback: bool if False, only open the port; callbacks are installed later once every port in the batch is open :return: bool True if the port is open afterwards .. py:method:: _install_callback(port_name: str) -> None Attach the shared RtMidi callback to an already-open port. :param port_name: str MIDI input port name :return: None .. py:method:: _close_port(port_name: str) -> None Close one port. :param port_name: str MIDI input port name :return: None .. py:method:: _on_midi(event: tuple[list[int], float], data: Any = None) -> None RtMidi callback: parse raw bytes into a queue for the GUI thread. Must not emit Qt signals or touch widgets — that deadlocks CoreMIDI when ports are still opening. :param event: tuple[list[int], float] raw bytes and delta time :param data: Any the port's name, passed to RtMidi when the port opened :return: None .. py:method:: _emit_pending() -> None Drain the RtMidi queue and emit signals on the GUI thread. :return: None