jvconnected.interfaces.midi
¶
jvconnected.interfaces.midi.midi_io
¶
-
class
jvconnected.interfaces.midi.midi_io.
MidiIO
(*args, **kwargs)[source]¶ Bases:
jvconnected.interfaces.base.Interface
Midi interface handler
- Properties
-
-
inports
: Dict[str, InputPort] → Property(Dict[str, InputPort])¶ Mapping of
InputPort
instances stored with the names as keys
-
outports
: Dict[str, OutputPort] → Property(Dict[str, OutputPort])¶ Mapping of
OutputPort
instances stored with the names as keys
-
mapped_devices
: Dict[str, MappedDevice] → Property(Dict[str, MappedDevice])¶ Mapping of
MappedDevice
instances stored with the device id as keys
-
config
: None → Property(None)¶ Instance of
jvconnected.config.Config
. This is gathered from theengine
afterset_engine()
has been called.
-
-
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: mido.messages.messages.BaseMessage)[source]¶ Send a message to all output ports in
outports
- Parameters
msg – The
Message
to send
-
map_device
(midi_channel: int, device: jvconnected.device.Device)[source]¶ Connect a
jvconnected.device.Device
to amapped_device.MappedDevice
jvconnected.interfaces.midi.aioport
¶
-
class
jvconnected.interfaces.midi.aioport.
BasePort
(*args, **kwargs)[source]¶ Bases:
pydispatch.dispatch.Dispatcher
Async wrapper for
mido.ports
- Parameters
name (str) – The port name
- Properties
- Attributes
stopped (asyncio.Event)
-
class
jvconnected.interfaces.midi.aioport.
InputPort
(*args, **kwargs)[source]¶ Bases:
jvconnected.interfaces.midi.aioport.BasePort
Async wrapper around
mido.ports.BaseInput
- Attributes
queue (asyncio.Queue) – Message queue for the port
-
async
receive
(timeout: Optional[numbers.Number] = None) → Optional[mido.messages.messages.Message][source]¶ Wait for an incoming message
- Parameters
timeout (float, optional) – Time to wait for a message. if
None
, wait until an item is available- Returns
An instance of
mido.Message
. If timeout was provided and no message was retrieved,None
will be returned.
-
async
queue_get
(timeout: Optional[numbers.Number] = None) → Any[source]¶ Convenience method for
get()
on thequeue
- Parameters
timeout (float, optional) – Time to wait for an item on the queue. if
None
, wait until an item is available
-
task_done
()[source]¶ Convenience method for
queue
task_done()
-
class
jvconnected.interfaces.midi.aioport.
OutputPort
(*args, **kwargs)[source]¶ Bases:
jvconnected.interfaces.midi.aioport.BasePort
Async wrapper around
mido.ports.BaseOutput
- Attributes
queue (queue.Queue) – Message queue for the port. Since the output port operates in a separate thread, this is a thread-based queue (not async)
-
async
open
() → bool[source]¶ Open the midi port
- Returns
True
if the port was successfully opened- Return type
-
async
send
(msg: mido.messages.messages.Message)[source]¶ Send a message
The message will be placed on the
queue
and sent from a separate thread- Parameters
msg – The
mido.Message
to send
jvconnected.interfaces.midi.mapper
¶
-
class
jvconnected.interfaces.midi.mapper.
Map
(name: str = '', group_name: str = '', full_name: str = '', index: int = - 1)[source]¶ Bases:
object
-
class
jvconnected.interfaces.midi.mapper.
ControllerMap
(name: str = '', group_name: str = '', full_name: str = '', index: int = - 1, controller: int = 0)[source]¶
-
class
jvconnected.interfaces.midi.mapper.
NoteMap
(name: str = '', group_name: str = '', full_name: str = '', index: int = - 1, note: int = 0)[source]¶
-
class
jvconnected.interfaces.midi.mapper.
AdjustControllerMap
(name: str = '', group_name: str = '', full_name: str = '', index: int = - 1, controller: int = 0)[source]¶
-
class
jvconnected.interfaces.midi.mapper.
MidiMapper
(maps: Optional[Sequence[Union[jvconnected.interfaces.midi.mapper.Map, Dict]]] = None)[source]¶ Bases:
object
Container for MIDI mapping definitions
jvconnected.interfaces.midi.mapped_device
¶
-
class
jvconnected.interfaces.midi.mapped_device.
MappedDevice
(*args, **kwargs)[source]¶ Bases:
pydispatch.dispatch.Dispatcher
Manages midi input and output for a single
Device
- Parameters
- Attributes
param_specs (Dict[str, ParameterGroupSpec]) – A dict of
jvconnected.interfaces.paramspec.ParameterGroupSpec
instancesmapped_params (Dict[str, MappedParameter]) – A dict of
MappedParameter
instances stored with theMappedParameter.name
as keys
-
async
handle_incoming_message
(msg: mido.messages.messages.BaseMessage)[source]¶ Dispatch an incoming message to all
MappedParameter
instancesThe
MappedParameter.handle_incoming_message()
method is called for each parameter instance inmapped_params
-
class
jvconnected.interfaces.midi.mapped_device.
MappedParameter
(*args, **kwargs)[source]¶ Bases:
pydispatch.dispatch.Dispatcher
Handles midi input and output for a single parameter within a
jvconnected.device.ParameterGroup
- Attributes
mapped_device (MappedDevice) – The parent
MappedDevice
instanceparam_group (ParameterGroupSpec) – The
ParameterGroupSpec
definition that describes the parameterparam_name (str) – The parameter name within the param_group
name (str) – Unique name of the parameter as defined by
jvconnected.interfaces.paramspec.ParameterSpec.full_name
param_spec – The
ParameterSpec
instance within theparam_group
channel (int) – The midi channel to use, typically gathered from
mapped_device
value_min (int) – Minimum value for the parameter as it exists in the
jvconnected.device.ParameterGroup
value_max (int) – Maximum value for the parameter as it exists in the
jvconnected.device.ParameterGroup
-
property
value_range
→ Number [read-only]¶ Total range of values calculated as
value_max - value_min
-
async
handle_incoming_message
(msg: mido.messages.messages.BaseMessage)[source]¶ Process an incoming message
If the message is valid for this object, the appropriate setter methods will by called on the
param_spec
-
message_valid
(msg: mido.messages.messages.BaseMessage) → bool[source]¶ Check the incoming message parameters to determine whether it should be handled by this object
-
scale_to_midi
(value: Union[numbers.Number, bool]) → int[source]¶ Scale the given value to a range of 0 to 127
If the given value is
bool
, this will return127
forTrue
and0
forFalse
.Otherwise the result will be \(((value - vmin) / vrange * 127\)
-
scale_from_midi
(value: int) → int[source]¶ Scale a value from \([0,1,..,127]\) to the range expected by the parameter. This results in \((value / 127) * vrange + vmin\)
-
get_message_type
(value: Union[numbers.Number, bool]) → str[source]¶ Get the
mido.Message
type argument for an outgoingmido.Message
with the given value.Typically one of
['control_change', 'note_on', 'note_off', 'pitchwheel']
-
get_message_kwargs
(value: Union[numbers.Number, bool]) → Dict[source]¶ Get keyword arguments to build an outgoing
mido.Message
with the given value
-
build_message
(value: Union[numbers.Number, bool]) → mido.messages.messages.Message[source]¶ Create a
mido.Message
to send for the given parameter valueUses
get_message_type()
andget_message_kwargs()
for message arguments
-
class
jvconnected.interfaces.midi.mapped_device.
MappedController
(*args, **kwargs)[source]¶ Bases:
jvconnected.interfaces.midi.mapped_device.MappedParameter
MappedParameter
subclass that uses midi control-change messages- Attributes
controller (int) – The controller number
-
message_valid
(msg: mido.messages.messages.BaseMessage) → bool[source]¶ Check the incoming message parameters to determine whether it should be handled by this object
-
get_message_type
(value: Union[numbers.Number, bool]) → str[source]¶ Get the
mido.Message
type argument for an outgoingmido.Message
with the given value.Typically one of
['control_change', 'note_on', 'note_off', 'pitchwheel']
-
get_message_kwargs
(value: Union[numbers.Number, bool]) → Dict[source]¶ Get keyword arguments to build an outgoing
mido.Message
with the given value
-
class
jvconnected.interfaces.midi.mapped_device.
MappedNoteParam
(*args, **kwargs)[source]¶ Bases:
jvconnected.interfaces.midi.mapped_device.MappedParameter
MappedParameter
subclass that uses midi note messagesIntended for boolean values. Sends a
note_on
message with velocity of127
for True and0
for False.Incoming
note_on
messages with velocity < 0 are treated asTrue
, velocity == 0 andnote_off
messages are consideredFalse
.- Attributes
note (int) – The midi note number
-
message_valid
(msg: mido.messages.messages.BaseMessage) → bool[source]¶ Check the incoming message parameters to determine whether it should be handled by this object
-
get_message_type
(value: Union[numbers.Number, bool]) → str[source]¶ Get the
mido.Message
type argument for an outgoingmido.Message
with the given value.Typically one of
['control_change', 'note_on', 'note_off', 'pitchwheel']
-
get_message_kwargs
(value: Union[numbers.Number, bool]) → Dict[source]¶ Get keyword arguments to build an outgoing
mido.Message
with the given value
-
class
jvconnected.interfaces.midi.mapped_device.
AdjustController
(*args, **kwargs)[source]¶ Bases:
jvconnected.interfaces.midi.mapped_device.MappedController
A
MappedController
that sends outgoing messages likeMappedController
, but incoming messages will either increment (>=64) or decrement (<64) the value.The use case for this would be for parameters that lack a direct setter method, but instead rely on adjustment methods.
An example would be the
gain
attribute ofjvconnected.device.ExposureParams
where the value can only be changed using theincrease_gain()
anddecrease_gain()
methods.-
message_valid
(msg: mido.messages.messages.BaseMessage) → bool[source]¶ Check the incoming message parameters to determine whether it should be handled by this object
-
get_message_type
(value: Union[numbers.Number, bool]) → str[source]¶ Get the
mido.Message
type argument for an outgoingmido.Message
with the given value.Typically one of
['control_change', 'note_on', 'note_off', 'pitchwheel']
-
get_message_kwargs
(value: Union[numbers.Number, bool]) → Dict[source]¶ Get keyword arguments to build an outgoing
mido.Message
with the given value
-
jvconnected.interfaces.midi.bcf
¶
jvconnected.interfaces.midi.bcf_sysex
¶
-
exception
jvconnected.interfaces.midi.bcf_sysex.
ResponseError
(error_code: int)[source]¶ Bases:
Exception
-
class
jvconnected.interfaces.midi.bcf_sysex.
BCLSyxBase
(manufacturer: Sequence[ByteString] = (0, 32, 50), device_id: Sequence[ByteString] = (127), model: Sequence[ByteString] = (20), command: Sequence[ByteString] = (32), message_index: int = 0)[source]¶ Bases:
object
-
property
index_msb
→ typing.Sequence[typing.ByteString] [read-only]¶ Bits 7-13 of
message_index
-
property
index_lsb
→ typing.Sequence[typing.ByteString] [read-only]¶ Bits 0-6 of
message_index
-
property
-
class
jvconnected.interfaces.midi.bcf_sysex.
BCLSysex
(manufacturer: Sequence[ByteString] = (0, 32, 50), device_id: Sequence[ByteString] = (127), model: Sequence[ByteString] = (20), command: Sequence[ByteString] = (32), message_index: int = 0, bcl_text: str = '')[source]¶
-
class
jvconnected.interfaces.midi.bcf_sysex.
BCLReply
(manufacturer: Sequence[ByteString] = (0, 32, 50), device_id: Sequence[ByteString] = (127), model: Sequence[ByteString] = (20), command: Sequence[ByteString] = (32), message_index: int = 0, error_code: Sequence[ByteString] = (0))[source]¶
-
class
jvconnected.interfaces.midi.bcf_sysex.
BCLBlock
(revision: str = 'F1', text_lines: Sequence[str] = <factory>)[source]¶ Bases:
object
-
class
jvconnected.interfaces.midi.bcf_sysex.
ControlBase
(message_type: str = 'control_change', channel: int = 0, number: int = 0, mode: str = '', value_min: int = 0, value_max: int = 127, value_default: Union[int, NoneType] = None, show_value: bool = True)[source]¶ Bases:
object
-
class
jvconnected.interfaces.midi.bcf_sysex.
EncoderConf
(message_type: str = 'control_change', channel: int = 0, number: int = 0, mode: str = '1dot', value_min: int = 0, value_max: int = 127, value_default: Union[int, NoneType] = None, show_value: bool = True, index: int = 1, encoder_mode: str = 'absolute', resolution: Sequence[int] = (96, 96, 96, 96))[source]¶ Bases:
jvconnected.interfaces.midi.bcf_sysex.ControlBase
-
mode
: str = '1dot'¶ LED Display mode
Choices
[ 'off', '1dot', '1dot/off', '12dot', '12dot/off', 'bar', 'bar/off', 'spread', 'pan', 'qual', 'cut', 'damp', ]
-
-
class
jvconnected.interfaces.midi.bcf_sysex.
FaderConf
(message_type: str = 'control_change', channel: int = 0, number: int = 0, mode: str = 'absolute', value_min: int = 0, value_max: int = 127, value_default: Union[int, NoneType] = None, show_value: bool = True, index: int = 1, motor: bool = True, override: str = 'move', keyoverride: str = 'off')[source]¶
-
class
jvconnected.interfaces.midi.bcf_sysex.
ButtonConf
(message_type: str = 'control_change', channel: int = 0, number: int = 0, mode: str = '', value_min: int = 0, value_max: int = 127, value_default: Union[int, NoneType] = None, show_value: bool = True, index: int = 1, button_mode: str = 'toggleon', increment: int = 1)[source]¶ Bases:
jvconnected.interfaces.midi.bcf_sysex.ControlBase
Choices
['toggleoff', 'toggleon', 'increment']
-
increment
: int = 1¶ Amount to increment/decrement if
button_mode
is'increment'