jvconnected.interfaces.midi.midi_io
- 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 apydispatch.ListProperty
object.
- ListProperty outport_names: tp.List[str]
list of output port names to use (as
str
)outport_names
is apydispatch.ListProperty
object.
- DictProperty inports: tp.Dict[str, InputPort]
Mapping of
InputPort
instances stored with theirname
as keysinports
is apydispatch.DictProperty
object.
- DictProperty outports: tp.Dict[str, OutputPort]
Mapping of
OutputPort
instances stored with theirname
as keysoutports
is apydispatch.DictProperty
object.
- DictProperty mapped_devices: tp.Dict[str, 'jvconnected.interfaces.midi.mapped_device.MappedDevice']
Mapping of
MappedDevice
instances stored with the device id as keysmapped_devices
is apydispatch.DictProperty
object.
- DictProperty device_channel_map: Dict[str, int]
Mapping of
MappedDevice
instances stored with the device id as keysdevice_channel_map
is apydispatch.DictProperty
object.
- DictProperty channel_device_map: Dict[int, str]
Mapping of Midi channel assignments using the Midi channel as keys and
device_id
as valueschannel_device_map
is apydispatch.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 apydispatch.Event
object.
- interface_name: ClassVar[str] = 'midi'
Unique name for the interface. Must be defined by subclasses
- 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 add_input(name: str)[source]
Add an input port
The port name will be added to
inport_names
and stored in theconfig
.If MidiIO is
running
, an instance ofInputPort
will be created and added toinports
.- 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 theconfig
.If MidiIO is
running
, an instance ofOutputPort
will be created and added tooutports
.- 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
andinport_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
andoutport_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
- 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 amapped_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 theconfig
.- Parameters
device (jvconnected.device.Device) – The
Device
to mapsend_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
ValidationError – If midi_channel was provided and already in use
ValueError – If there are no Midi channels available
- async unmap_device(device_id: str, unassign_channel: bool = False)[source]
Unmap a device
- Parameters
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
frommapped_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
- Raises
ValidationError – If the given midi_channel is already in use