jvconnected.interfaces.midi.mapped_device

class jvconnected.interfaces.midi.mapped_device.MappedDevice(*args, **kwargs)[source]

Bases: Dispatcher

Manages midi input and output for a single Device

Parameters
  • midi_io – The parent MidiIO instance

  • midi_channel (int) – Midi channel to use (0 to 15)

  • device – The Device instance

param_specs

A dict of jvconnected.interfaces.paramspec.ParameterGroupSpec instances

Type

Dict[str, ParameterGroupSpec]

mapped_params

A dict of MappedParameter instances stored with the MappedParameter.name as keys

Type

Dict[str, MappedParameter]

async handle_incoming_messages(msgs: Iterable[Message])[source]

Dispatch incoming messages to all MappedParameter instances

The MappedParameter.handle_incoming_messages() method is called for each parameter instance in mapped_params

async send_all_parameters()[source]

Send values for all mapped parameters (full refresh)

async send_message(msg: Message)[source]

Send the given message with midi_io

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

Send a sequence of messages with midi_io

class jvconnected.interfaces.midi.mapped_device.MappedParameter(*args, **kwargs)[source]

Bases: Dispatcher

Handles midi input and output for a single parameter within a jvconnected.device.ParameterGroup

mapped_device

The parent MappedDevice instance

Type

MappedDevice

param_group

The ParameterGroupSpec definition that describes the parameter

Type

ParameterGroupSpec

map_obj

The midi mapping definition

Type

mapper.Map

name

Unique name of the parameter as defined by the full_name of the map_obj

Type

str

param_spec

The ParameterSpec instance within the param_group

channel

The midi channel to use, typically gathered from mapped_device

Type

int

value_min: int = 0

Minimum value for the parameter as it exists in the jvconnected.device.ParameterGroup

value_max: int = 1

Maximum value for the parameter as it exists in the jvconnected.device.ParameterGroup

property is_14_bit: bool

True if the map_obj uses 14 bit values

property midi_max: int

Maximum value for MIDI data

Will be 127 (0x7f) in most cases. If is_14_bit, the value will be 16383 (0x3fff).

property midi_range: int

Total range of MIDI values calculated as midi_max + 1

property value_range: Number

Total range of values calculated as

\[\begin{split}V_{offset} &= \begin{cases} 1, & \quad \text{if }V_{min} = 0\\ 0, & \quad \text{if }V_{min}\ne 0 \end{cases}\\ V_{range} &= V_{max} - V_{min} + V_{offset}\end{split}\]

where \(V_{min}\) = value_min and \(V_{max}\) is value_max

message_valid(msg: BaseMessage) bool[source]

Check the incoming message parameters to determine whether it should be handled by this object

scale_to_midi(value: Union[Number, bool]) int[source]

Scale the given value to the range allowed in midi messages

For boolean input, the result will be

\[\begin{split}result = \begin{cases} M_{max}, & \quad \text{if value is true}\\ 0, & \quad \text{otherwise} \end{cases}\end{split}\]

For numeric input

\[result = \frac{value - V_{min}}{V_{range}} \cdot M_{max}\]

where \(M_{max}\) = midi_max, \(M_{range}\) = midi_range, \(V_{min}\) = value_min and \(V_{range}\) = value_range

scale_from_midi(value: int) int[source]

Scale a value from the midi range to the param_spec range

\[result = \frac{value}{M_{range}} \cdot V_{range} + V_{min}\]

where \(M_{range}\) = midi_range, \(V_{min}\) = value_min and \(V_{range}\) = value_range

get_message_type(value: Union[Number, bool]) str[source]

Get the mido.Message type argument for an outgoing mido.Message with the given value.

Typically one of ['control_change', 'note_on', 'note_off', 'pitchwheel']

get_message_kwargs(value: Union[Number, bool]) Dict[source]

Get keyword arguments to build an outgoing mido.Message with the given value

build_message(value: Union[Number, bool]) Message[source]

Create a mido.Message to send for the given parameter value

Uses get_message_type() and get_message_kwargs() for message arguments

get_current_value() Any[source]

Get the current device value

class jvconnected.interfaces.midi.mapped_device.MappedController(*args, **kwargs)[source]

Bases: MappedParameter

MappedParameter subclass that uses midi control-change messages

controller

The controller number

Type

int

value_min: int = 0

Minimum value for the parameter as it exists in the jvconnected.device.ParameterGroup

value_max: int = 1

Maximum value for the parameter as it exists in the jvconnected.device.ParameterGroup

message_valid(msg: BaseMessage) bool[source]

Check the incoming message parameters to determine whether it should be handled by this object

get_message_type(value: Union[Number, bool]) str[source]

Get the mido.Message type argument for an outgoing mido.Message with the given value.

Typically one of ['control_change', 'note_on', 'note_off', 'pitchwheel']

get_message_kwargs(value: Union[Number, bool]) Dict[source]

Get keyword arguments to build an outgoing mido.Message with the given value

class jvconnected.interfaces.midi.mapped_device.MappedController14Bit(*args, **kwargs)[source]

Bases: MappedController

A MappedController using 14-bit Midi values

property controller_msb: int

The controller index containing the most-significant 7 bits

This will always be equal to the controller value

property controller_lsb: int

The controller index containing the least-significant 7 bits

Per the MIDI 1.0 specification, this will be controller_msb + 32

message_valid(msg: BaseMessage) bool[source]

Check the incoming message parameters to determine whether it should be handled by this object

build_message(value: Union[Number, bool]) List[Message][source]

Create a mido.Message to send for the given parameter value

Uses get_message_type() and get_message_kwargs() for message arguments

class jvconnected.interfaces.midi.mapped_device.MappedNoteParam(*args, **kwargs)[source]

Bases: MappedParameter

MappedParameter subclass that uses midi note messages

Intended for boolean values. Sends a note_on message with velocity of 127 for True and 0 for False.

Incoming note_on messages with velocity < 0 are treated as True, velocity == 0 and note_off messages are considered False.

note

The midi note number

Type

int

message_valid(msg: BaseMessage) bool[source]

Check the incoming message parameters to determine whether it should be handled by this object

get_message_type(value: Union[Number, bool]) str[source]

Get the mido.Message type argument for an outgoing mido.Message with the given value.

Typically one of ['control_change', 'note_on', 'note_off', 'pitchwheel']

get_message_kwargs(value: Union[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: MappedController

A MappedController that sends outgoing messages like MappedController, 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_pos attribute of jvconnected.device.ExposureParams where the value can only be changed using the increase_gain() and decrease_gain() methods.

message_valid(msg: BaseMessage) bool[source]

Check the incoming message parameters to determine whether it should be handled by this object

get_message_type(value: Union[Number, bool]) str[source]

Get the mido.Message type argument for an outgoing mido.Message with the given value.

Typically one of ['control_change', 'note_on', 'note_off', 'pitchwheel']

get_message_kwargs(value: Union[Number, bool]) Dict[source]

Get keyword arguments to build an outgoing mido.Message with the given value