Skip to content

Ports

OscIO

OscIO(input_listener_ip_port: str | int, output_target_ip_port: str | int)

Bases: MultiPort

Open Sound Control input/output port that combines OscIn and OscOut ports. Produces and sends OscMsg objects.

Parameters:

  • input_listener_ip_port (str | int) –

    'ip:port' or local port to listen for incoming OSC messages

  • output_target_ip_port (str | int) –

    'ip:port' or local port to send output OSC messages to

is_opened

is_opened: bool

True if port is listening messages / ready to send messages

query

query(
    address: str,
    data: str | bytes | bool | int | float | list | tuple = None,
    *,
    timeout_sec: float = 1
) -> str | bytes | bool | float | list | tuple

Queries data by sending the request to OSC address and returns the data of response from that address

Parameters:

  • address (str) –

    OSC address to send request to

  • data (str | bytes | bool | int | float | list | tuple, default: None ) –

    data to send request with, not used to match response

  • timeout_sec (float, default: 1 ) –

    time for response until raising TimeoutError

Raises:

  • TimeoutError

    on query timeout

Returns:

  • str | bytes | bool | float | list | tuple

    Response OSC message data

subscribe

subscribe(
    address: None | Container | str = None,
    data: (
        None | Container | str | bytes | bool | int | float | list | tuple
    ) = 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: OscMsg) -> None

Send the OSC message.

Parameters:

  • msg (OscMsg) –

    object to send

OscIn

OscIn(listener_ip_port: str | int)

Bases: Input

Open Sound Control input port. Produces OscMsg objects.

Parameters:

  • listener_ip_port (str | int) –

    'ip:port' or local port to listen for incoming OSC messages

is_opened

is_opened: bool

True if port is listening messages / ready to send messages

subscribe

subscribe(
    address: None | Container | str = None,
    data: (
        None | Container | str | bytes | bool | int | float | list | tuple
    ) = 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.

OscOut

OscOut(target_ip_port: str | int)

Bases: Output

Open Sound Control output port. Sends OscMsg objects.

Parameters:

  • target_ip_port (str | int) –

    'ip:port' or local port to send output OSC messages to

is_opened

is_opened: bool

True if port is listening messages / ready to send messages

send

send(msg: OscMsg) -> None

Send the OSC message.

Parameters:

  • msg (OscMsg) –

    object to send