Skip to content

Ports

IoPort

IoPort(uid: str, input_port: Input, output_port: Output)

Bases: Port

Combines Input and Output ports into a single i/o port.

Parameters:

  • uid (str) –

    Port's unique ID

  • input_port (Input) –

    input port to wrap

  • output_port (Output) –

    output port to wrap

subscribe

subscribe(
    *msg_matches_args: None | MatchCondition | Container[Any] | Any,
    **msg_matches_kwargs: dict[
        str, None | MatchCondition | Container[Any] | Any
    ]
) -> 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, range, etc.) 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: Msg) -> None

Send message using wrapped output ports

Parameters:

  • msg (Msg) –

    Message to send.

Input

Input(uid: Hashable | None = None)

Bases: Subscribable, Port

Input port base class

subscribe

subscribe(
    *msg_matches_args: None | MatchCondition | Any,
    **msg_matches_kwargs: dict[str, None | MatchCondition | Any]
) -> 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, range, etc.) 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.

Output

Output(uid: Hashable | None = None)

Bases: Port

Output port base class

Parameters:

  • uid (Hashable | None, default: None ) –

    Port's unique ID

send

send(msg: Msg) -> None

Send message using the output port.

Parameters:

  • msg (Msg) –

    Message to send.

Notes

Supposed to be overridden in subclasses. Should call log._msg_sent(self, msg) after message sent.

Port

Port(uid: Hashable | None = None)

Port base class.

Notes

Port declarations with the same arguments will return the same instance port (singleton).

Parameters:

  • uid (Hashable | None, default: None ) –

    Port's unique ID