jdxi_editor.midi.io.external_controller

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 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.

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

_PUMP_INTERVAL_MS

_PORT_OPEN_STAGGER_MS

Classes

ExternalControllerInput

MIDI input from a hardware controller.

Module Contents

jdxi_editor.midi.io.external_controller._PUMP_INTERVAL_MS = 5[source]
jdxi_editor.midi.io.external_controller._PORT_OPEN_STAGGER_MS = 50[source]
class jdxi_editor.midi.io.external_controller.ExternalControllerInput(parent: PySide6.QtCore.QObject | None = None)[source]

Bases: PySide6.QtCore.QObject

MIDI input from a hardware controller.

message_received[source]
control_changed[source]
ports_changed[source]
_inputs: dict[str, rtmidi.MidiIn][source]
_parsers: dict[str, mido.Parser][source]
_probe[source]
port_name: str | None = None[source]
_pending: collections.deque[tuple[str, mido.Message]][source]
_pump[source]
_ports_to_open: list[str] = [][source]
property port_names: list[str][source]

Names of every controller port being listened to.

Returns:

list[str]

property is_open: bool[source]

Whether any controller port is open.

Returns:

bool

property profile: jdxi_editor.midi.io.controller_map.ControllerProfile | None[source]

The supported controller being listened to or, before any port is open, the one that is plugged in.

Returns:

Optional[ControllerProfile] None if no supported controller is connected

available_ports() → list[str][source]

Names of all MIDI input ports.

Returns:

list[str]

auto_connect() → bool[source]

Open every supported controller port that is connected.

Returns:

bool True if at least one controller port was opened

connect_ports(port_names: list[str]) → bool[source]

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. ports_changed is emitted when the batch finishes.

Parameters:

port_names – list[str] MIDI input port names

Returns:

bool True if a port is already open or a batch was started

_open_next_port() → None[source]

Open the next queued controller port, then schedule the rest.

Returns:

None

_finish_port_batch() → None[source]

Start the GUI pump and announce the ports now listened to.

Returns:

None

connect_port(port_name: str) → bool[source]

Listen to port_name alone, closing any port already open.

Parameters:

port_name – str MIDI input port name

Returns:

bool True if the port was opened

rescan() → list[str][source]

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. ports_changed is emitted when the open set changes (after any staggered opens finish).

Returns:

list[str] names of the ports already open (new ones may still be opening)

close() → None[source]

Close every controller port.

Returns:

None

_open_port(port_name: str, *, install_callback: bool = True) → bool[source]

Open one port and listen to it, if it is not open already.

Parameters:
  • port_name – str MIDI input port name

  • install_callback – bool if False, only open the port; callbacks are installed later once every port in the batch is open

Returns:

bool True if the port is open afterwards

_install_callback(port_name: str) → None[source]

Attach the shared RtMidi callback to an already-open port.

Parameters:

port_name – str MIDI input port name

Returns:

None

_close_port(port_name: str) → None[source]

Close one port.

Parameters:

port_name – str MIDI input port name

Returns:

None

_on_midi(event: tuple[list[int], float], data: Any = None) → None[source]

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.

Parameters:
  • event – tuple[list[int], float] raw bytes and delta time

  • data – Any the port’s name, passed to RtMidi when the port opened

Returns:

None

_emit_pending() → None[source]

Drain the RtMidi queue and emit signals on the GUI thread.

Returns:

None