Skip to content

Ports

MidiIO

MidiIO(port_name: str, *, virtual: bool = False, loopback: bool = False)

Bases: MultiPort

MIDI input/output port that combines MidiIn and MidiOut ports with the same name. Produces and sends MidiMsg objects.

Parameters:

  • port_name (str) –

    MIDI port name

  • virtual (bool, default: False ) –

    Create virtual input and output ports

  • loopback (bool, default: False ) –

    Immediately send the messages received by the input port with the output port

is_opened

is_opened: bool

True if port is listening messages / ready to send messages

passthrough_out

passthrough_out(midi_output: MidiOut) -> None

Attach MidiOut as a pass-through port to send all incoming messages as soon as they arrive, before sending them to calls. This can greatly reduce latency.

Parameters:

subscribe

subscribe(
    type: None | Container | MidiType = None,
    channel: None | Container | int | tuple[int, ...] = None,
    data1: None | Container | int | tuple[int, ...] = None,
    data2: None | Container | int | tuple[int, ...] = None,
) -> Callable

Decorator to subscribe a callable to all the wrapped inputs' messages.

Decorator without arguments subscribes a callable to all the input's messages.

Decorator with arguments subscribes a callable to the input's messages that match conditions set by arguments. It works the same way as message's matches method:

  1. If condition is None or omitted it matches anything.

  2. If condition equals the message's attribute value it matches the attribute.

  3. If condition is a container (list, tuple) and contains the message's attribute value, it matches the attribute.

Examples
  1. Calls function for all MIDI port's messages:
    @midi_input_instance.subscribe
    def function(msg: MidiMsg) -> None:
        pass
    
  2. Calls function for OSC messages from specific address:
    @osc_input_instance.subscribe(address='/live/song/get/track_data')
    def function(msg: OscMsg) -> None:
        pass
    
  3. Call object instance method for MIDI port's "note on" and "note off" messages:
    midi_input_instance.subscribe((MidiType.NOTE_ON, MidiType.NOTE_OFF))(object.method)
    

Returns:

  • Callable

    Subscribed callable.

send

send(msg: MidiMsg) -> None

Send the MIDI message.

Parameters:

MidiIn

MidiIn(port_name: str, *, virtual: bool = False)

Bases: _MidiPortMixin, Input

MIDI input port. Produces MidiMsg objects.

Parameters:

  • port_name (str) –

    MIDI input port name

  • virtual (bool, default: False ) –

    Create virtual port

is_opened

is_opened: bool

True if port is listening messages / ready to send messages

passthrough_out

passthrough_out(midi_output: MidiOut) -> None

Attach MidiOut as a pass-through port to send all incoming messages as soon as they arrive, before sending them to calls. This can greatly reduce latency.

Parameters:

subscribe

subscribe(
    type: None | Container | MidiType = None,
    channel: None | Container | int | tuple[int, ...] = None,
    data1: None | Container | int | tuple[int, ...] = None,
    data2: None | Container | int | tuple[int, ...] = None,
) -> Callable

Decorator to subscribe a callable to the input's messages.

Decorator without arguments subscribes a callable to all the input's messages.

Decorator with arguments subscribes a callable to the input's messages that match conditions set by arguments. It works the same way as message's matches method:

  1. If condition is None or omitted it matches anything.

  2. If condition equals the message's attribute value it matches the attribute.

  3. If condition is a container (list, tuple) and contains the message's attribute value, it matches the attribute.

Examples
  1. Calls function for all MIDI port's messages:
    @midi_input_instance.subscribe
    def function(msg: MidiMsg) -> None:
        pass
    
  2. Calls function for OSC messages from specific address:
    @osc_input_instance.subscribe(address='/live/song/get/track_data')
    def function(msg: OscMsg) -> None:
        pass
    
  3. Call object instance method for MIDI port's "note on" and "note off" messages:
    midi_input_instance.subscribe((MidiType.NOTE_ON, MidiType.NOTE_OFF))(object.method)
    

Returns:

  • Callable

    Subscribed callable.

MidiOut

MidiOut(port_name: str, *, virtual: bool = False)

Bases: _MidiPortMixin, Output

MIDI output port. Sends MidiMsg objects.

Parameters:

  • port_name (str) –

    MIDI output port name

  • virtual (bool, default: False ) –

    Create virtual port

is_opened

is_opened: bool

True if port is listening messages / ready to send messages

send

send(msg: MidiMsg) -> None

Send the MIDI message.

Parameters: