jvconnected.interfaces.midi.midi_io

exception jvconnected.interfaces.midi.midi_io.ValidationError[source]

Bases: Exception

class jvconnected.interfaces.midi.midi_io.MidiIO(*args, **kwargs)[source]

Bases: Interface

Midi interface handler

ListProperty inport_names: tp.List[str]

list of input port names to use (as str)

inport_names is a pydispatch.ListProperty object.

ListProperty outport_names: tp.List[str]

list of output port names to use (as str)

outport_names is a pydispatch.ListProperty object.

DictProperty inports: tp.Dict[str, InputPort]

Mapping of InputPort instances stored with their name as keys

inports is a pydispatch.DictProperty object.

DictProperty outports: tp.Dict[str, OutputPort]

Mapping of OutputPort instances stored with their name as keys

outports is a pydispatch.DictProperty object.

DictProperty mapped_devices: tp.Dict[str, 'jvconnected.interfaces.midi.mapped_device.MappedDevice']

Mapping of MappedDevice instances stored with the device id as keys

mapped_devices is a pydispatch.DictProperty object.

DictProperty device_channel_map: Dict[str, int]

Mapping of MappedDevice instances stored with the device id as keys

device_channel_map is a pydispatch.DictProperty object.

DictProperty channel_device_map: Dict[int, str]

Mapping of Midi channel assignments using the Midi channel as keys and device_id as values

channel_device_map is a pydispatch.DictProperty object.

Event port_state(io_type: IOType, name: str, state: bool)[source]

Fired when a port is added or removed using one of add_input(), add_output(), remove_input(), remove_output().

port_state is a pydispatch.Event object.

interface_name: ClassVar[str] = 'midi'

Unique name for the interface. Must be defined by subclasses

classmethod get_available_inputs() List[str][source]

Get all detected input port names

classmethod get_available_outputs() List[str][source]

Get all detected output port names

async set_engine(engine: jvconnected.engine.Engine)[source]

Attach the interface to a running instance of jvconnected.engine.Engine

This will be called automatically by the engine if the class is in the jvconnected.interfaces.registry.

If the engine is running, the interface will start (using the open() method). Otherwise it will automatically start when the engine does.

async automap_engine_devices(*args, **kwargs)[source]

Map the engine’s devices by index

async open()[source]

Open any configured input and output ports and begin communication

async close()[source]

Stop communication and close all input and output ports

async open_ports()[source]

Open any configured input and output ports. (Called by open())

async close_ports()[source]

Close all running input and output ports (Called by close())

async add_input(name: str)[source]

Add an input port

The port name will be added to inport_names and stored in the config.

If MidiIO is running, an instance of InputPort will be created and added to inports.

Parameters

name (str) – The port name (as it appears in get_available_inputs())

async add_output(name: str)[source]

Add an output port

The port name will be added to outport_names and stored in the config.

If MidiIO is running, an instance of OutputPort will be created and added to outports.

Parameters

name (str) – The port name (as it appears in get_available_outputs())

async remove_input(name: str)[source]

Remove an input port from inports and inport_names

If the port exists in inports, it will be closed and removed.

Parameters

name (str) – The port name

async remove_output(name: str)[source]

Remove an output port from outports and outport_names

If the port exists in outports, it will be closed and removed.

Parameters

name (str) – The port name

async send_message(msg: BaseMessage)[source]

Send a message to all output ports in outports

Parameters

msg (BaseMessage) – The Message to send

async send_messages(msgs: Sequence[Message])[source]

Send a message to all output ports in outports

Parameters

msgs (Sequence[Message]) – A sequence of Messages to send

async map_device(device: jvconnected.device.Device, send_all_parameters: bool = True, midi_channel: Optional[int] = None) MappedDevice[source]

Connect a jvconnected.device.Device to a mapped_device.MappedDevice

The Midi channel used for the device is retreived from the config if available. If no channel assignment was found, the next available channel is used and saved in the config.

Parameters
  • device (jvconnected.device.Device) – The Device to map

  • send_all_parameters (bool, optional) – If True, send all current parameter values once the device is mapped. Default is True

  • midi_channel (int, optional) – The Midi channel to use for the device (from 0 to 15). If not provided, the channel is assigned automatically using get_midi_channel_for_device()

Raises
async unmap_device(device_id: str, unassign_channel: bool = False)[source]

Unmap a device

Parameters
  • device_id (str) – The id of the device to unmap

  • unassign_channel (bool, optional) – If True, removes the Midi channel assignment for the device and updates the saved config. If False (the default), only removes the MappedDevice from mapped_devices.

async remap_device_channel(device_id: str, midi_channel: int)[source]

Reassign the Midi channel for a device

If the device is online, the existing MappedDevice attached to it is reassigned as well.

Parameters
  • device_id (str) – The id of the device

  • midi_channel (int) – The new Midi channel for the device

Raises

ValidationError – If the given midi_channel is already in use

get_midi_channel_for_device(device_id: str) int[source]

Get the assigned Midi channel for a device or next one available

If the device_id exists in the config, it is used. If no assignment exists, the next available channel is returned.

Raises

ValueError – If there are no available channels

update_config(*args, **kwargs)[source]

Update the config with current state