jdxi_editor.midi.io.controller_map

Routes control-change messages from a hardware controller (not the JD-Xi) to filter controls of the synth editor that is open, and to the effect levels that the JD-Xi’s own right-hand knobs set.

Each supported controller is a ControllerProfile, read from JSON rather than written here:

  • midi_controllers.json next to this module holds the built-in controllers (the Arturia MiniLab 3 and the SINCO VMX8);

  • ~/.jdxi_editor/midi_controllers.json (user_config_path()) is the user’s copy, written on first start by install_user_config(). A controller in it overrides the keys it gives of the built-in one with the same id; a new id adds a controller.

Set the environment variable JDXI_EDITOR_MIDI_CONTROLLERS to read another user file, or to an empty string to use the built-in controllers only. Changes to the file take effect when the editor is restarted. Mappings learnt in the MIDI Controller dialog are stored separately and take precedence (jdxi_editor.midi.io.controller_settings).

A controller entry looks like:

{
  "id": "minilab3",
  "label": "Arturia MiniLab 3",
  "port_names": ["minilab"],
  "secondary_port_names": ["din thru", "mcu", "hui", "alv"],
  "single_port": false,
  "mappings": [{"cc": 74, "control": "CUTOFF", "source": "Knob 1"}, ...],
  "transport": [{"action": "PLAY", "cc": 107}, {"action": "PAUSE", "note": 93}]
}

control is a FilterControl name and source the physical knob or fader, shown in the MIDI Controller dialog. transport lists the controller’s transport buttons (TransportAction names), each sending a cc or a note, with an optional channel (0 = MIDI channel 1).

Example

>>> MINILAB3_FILTER_MAP[74]
<FilterControl.CUTOFF: 'FILTER_CUTOFF'>
>>> MINILAB3.sources[FilterControl.CUTOFF]
'Knob 1'
>>> find_controller_port(["JD-Xi", "Minilab3 DIN THRU", "Minilab3 MIDI"])
'Minilab3 MIDI'
>>> find_controller_ports(["JD-Xi", "SINCO VMX8-Private", "SINCO VMX8-Master"])
['SINCO VMX8-Private']
>>> VMX8_FILTER_MAP[32]
<FilterControl.CUTOFF: 'FILTER_CUTOFF'>

Attributes

EFFECT_CONTROLS

BUILTIN_CONFIG_PATH

USER_CONFIG_NAME

CONFIG_ENV_VAR

CONTROLLER_PROFILES

MINILAB3

VMX8

MINILAB3_FILTER_MAP

VMX8_FILTER_MAP

CONTROLLER_PORT_NAMES

Classes

FilterControl

Controls a hardware controller can drive; values are parameter names.

TransportAction

Transport commands a hardware controller's buttons can request.

TransportSpec

One transport button of a controller, as midi_controllers.json lists it.

ControllerProfile

A supported hardware controller: how to find its ports, and its default map.

Functions

user_config_path() → Optional[pathlib.Path]

Where the user's controller config is read from.

read_entries(path) → list[dict]

The raw controllers entries of one JSON config file.

_parse(entries, origin) → list[ControllerProfile]

Profiles from raw entries; an entry that cannot be read is logged and skipped.

read_profiles(path) → list[ControllerProfile]

The controllers in one JSON config file.

load_controller_profiles([user_path]) → tuple[ControllerProfile, ...]

The built-in controllers, overridden or extended by the user's config.

install_user_config([path]) → Optional[pathlib.Path]

Copy the built-in controller config to the user's, if there is none yet.

_profile(profile_id) → ControllerProfile

profile_by_id(profile_id) → ControllerProfile

The profile with profile_id, or the MiniLab 3 one if there is none.

detect_profile(port_names) → Optional[ControllerProfile]

The first supported controller that has a port among port_names.

find_controller_ports(port_names) → list[str]

The input ports to open for the connected hardware controller.

find_controller_port(port_names) → Optional[str]

Pick the main input port of a supported hardware controller.

Module Contents

class jdxi_editor.midi.io.controller_map.FilterControl[source]

Bases: enum.Enum

Controls a hardware controller can drive; values are parameter names.

Despite the name, this also covers the program effect levels (EFFECT_CONTROLS), which the Effects editor holds.

CUTOFF = 'FILTER_CUTOFF'[source]
RESONANCE = 'FILTER_RESONANCE'[source]
KEYFOLLOW = 'FILTER_CUTOFF_KEYFOLLOW'[source]
ENV_DEPTH = 'FILTER_ENV_DEPTH'[source]
ENV_VELOCITY = 'FILTER_ENV_VELOCITY_SENSITIVITY'[source]
ENV_ATTACK = 'FILTER_ENV_ATTACK_TIME'[source]
ENV_DECAY = 'FILTER_ENV_DECAY_TIME'[source]
ENV_SUSTAIN = 'FILTER_ENV_SUSTAIN_LEVEL'[source]
ENV_RELEASE = 'FILTER_ENV_RELEASE_TIME'[source]
EFFECT1_LEVEL = 'EFX1_LEVEL'[source]
EFFECT2_LEVEL = 'EFX2_LEVEL'[source]
DELAY_LEVEL = 'DELAY_LEVEL'[source]
REVERB_LEVEL = 'REVERB_LEVEL'[source]
jdxi_editor.midi.io.controller_map.EFFECT_CONTROLS[source]
class jdxi_editor.midi.io.controller_map.TransportAction[source]

Bases: enum.Enum

Transport commands a hardware controller’s buttons can request.

PLAY[source]
PAUSE[source]
STOP[source]
RECORD[source]
REWIND[source]
FAST_FORWARD[source]
class jdxi_editor.midi.io.controller_map.TransportSpec[source]

One transport button of a controller, as midi_controllers.json lists it.

Parameters:
  • action – TransportAction what the button does

  • kind – str "cc" (press 127 / release 0) or "note" (note on / off)

  • channel – int MIDI channel as mido numbers it (0 = MIDI channel 1)

  • number – int CC or note number 0-127

action: TransportAction[source]
kind: str[source]
channel: int[source]
number: int[source]
classmethod from_dict(entry: dict) → TransportSpec[source]

Build a button from one transport entry, e.g. {"action": "PLAY", "cc": 52}.

Parameters:

entry – dict with action, one of cc / note, and optionally channel (default 0)

Returns:

TransportSpec

Raises:
  • KeyError – if the action is unknown or neither cc nor note is given

  • ValueError – if a number is outside its MIDI range

to_dict() → dict[source]

This button as a transport entry, the inverse of from_dict().

Returns:

dict e.g. {"action": "PLAY", "cc": 52, "channel": 0}

property label: str[source]

What the button sends, for display.

Returns:

str e.g. "CC 52", "Note 94" or "CC 52 (ch 2)"

matches(message: object) → bool[source]

Whether message is a press of this button.

Parameters:

message – mido.Message

Returns:

bool True for a note-on with velocity, or a CC of 64 or more

class jdxi_editor.midi.io.controller_map.ControllerProfile[source]

A supported hardware controller: how to find its ports, and its default map.

Parameters:
  • profile_id – str stable id, used as the settings key

  • label – str name shown in the MIDI Controller dialog

  • port_names – tuple[str, …] lower-case substrings of its port names

  • secondary_port_names – tuple[str, …] substrings of ports ranked after the main one

  • single_port – bool listen to the main port only; for devices that send every message on each of their ports

  • cc_map – dict CC number -> FilterControl defaults

  • sources – dict FilterControl -> physical control that sends it, e.g. “Knob 1”; controls whose source is unknown are left out

  • transport – tuple[TransportSpec, …] its transport buttons

profile_id: str[source]
label: str[source]
port_names: tuple[str, ...][source]
secondary_port_names: tuple[str, ...] = ()[source]
single_port: bool = False[source]
cc_map: dict[int, FilterControl][source]
sources: dict[FilterControl, str][source]
transport: tuple[TransportSpec, ...] = ()[source]
classmethod from_dict(entry: dict) → ControllerProfile[source]

Build a profile from one controllers entry of the JSON config.

Parameters:

entry – dict with id, label, port_names and mappings, and optionally secondary_port_names, single_port and transport

Returns:

ControllerProfile

Raises:
  • KeyError – if a required key or a control name is unknown

  • ValueError – if a CC number is not 0-127

  • TypeError – if a value has the wrong type

matches(port_name: str) → bool[source]

Whether port_name belongs to this controller.

Parameters:

port_name – str MIDI port name

Returns:

bool

ports(port_names: Iterable[str]) → list[str][source]

This controller’s ports among port_names that should be opened.

Parameters:

port_names – Iterable[str] available MIDI input port names

Returns:

list[str] main port(s) first; only one for single_port

jdxi_editor.midi.io.controller_map.BUILTIN_CONFIG_PATH[source]
jdxi_editor.midi.io.controller_map.USER_CONFIG_NAME = 'midi_controllers.json'[source]
jdxi_editor.midi.io.controller_map.CONFIG_ENV_VAR = 'JDXI_EDITOR_MIDI_CONTROLLERS'[source]
jdxi_editor.midi.io.controller_map.user_config_path() → pathlib.Path | None[source]

Where the user’s controller config is read from.

Returns:

Optional[Path] ~/.jdxi_editor/midi_controllers.json, the path in JDXI_EDITOR_MIDI_CONTROLLERS, or None if that variable is empty

jdxi_editor.midi.io.controller_map.read_entries(path: pathlib.Path) → list[dict][source]

The raw controllers entries of one JSON config file.

Parameters:

path – Path JSON file with a controllers list

Returns:

list[dict] in file order

Raises:
jdxi_editor.midi.io.controller_map._parse(entries: Iterable[dict], origin: object) → list[ControllerProfile][source]

Profiles from raw entries; an entry that cannot be read is logged and skipped.

Parameters:
  • entries – Iterable[dict] raw controller entries

  • origin – object where they came from, for the log

Returns:

list[ControllerProfile]

jdxi_editor.midi.io.controller_map.read_profiles(path: pathlib.Path) → list[ControllerProfile][source]

The controllers in one JSON config file.

An entry that cannot be read is logged and skipped, so one typo does not lose the other controllers.

Parameters:

path – Path JSON file with a controllers list

Returns:

list[ControllerProfile] in file order

Raises:
jdxi_editor.midi.io.controller_map.load_controller_profiles(user_path: pathlib.Path | None = None) → tuple[ControllerProfile, ...][source]

The built-in controllers, overridden or extended by the user’s config.

A user entry with a built-in id overrides only the keys it has: an older copy without transport still gets the built-in transport buttons.

Parameters:

user_path – Optional[Path] user config; defaults to user_config_path()

Returns:

tuple[ControllerProfile, …] built-in order first, then new user ones

jdxi_editor.midi.io.controller_map.install_user_config(path: pathlib.Path | None = None) → pathlib.Path | None[source]

Copy the built-in controller config to the user’s, if there is none yet.

An existing file is never overwritten.

Parameters:

path – Optional[Path] destination; defaults to user_config_path()

Returns:

Optional[Path] the user config, or None if it is disabled or could not be written

jdxi_editor.midi.io.controller_map.CONTROLLER_PROFILES: tuple[ControllerProfile, ...] = ()[source]
jdxi_editor.midi.io.controller_map._profile(profile_id: str) → ControllerProfile[source]
jdxi_editor.midi.io.controller_map.MINILAB3[source]
jdxi_editor.midi.io.controller_map.VMX8[source]
jdxi_editor.midi.io.controller_map.MINILAB3_FILTER_MAP: dict[int, FilterControl][source]
jdxi_editor.midi.io.controller_map.VMX8_FILTER_MAP: dict[int, FilterControl][source]
jdxi_editor.midi.io.controller_map.CONTROLLER_PORT_NAMES[source]
jdxi_editor.midi.io.controller_map.profile_by_id(profile_id: str | None) → ControllerProfile[source]

The profile with profile_id, or the MiniLab 3 one if there is none.

Parameters:

profile_id – Optional[str]

Returns:

ControllerProfile

jdxi_editor.midi.io.controller_map.detect_profile(port_names: Iterable[str]) → ControllerProfile | None[source]

The first supported controller that has a port among port_names.

Parameters:

port_names – Iterable[str] MIDI port names

Returns:

Optional[ControllerProfile] None if no supported controller is connected

jdxi_editor.midi.io.controller_map.find_controller_ports(port_names: Iterable[str]) → list[str][source]

The input ports to open for the connected hardware controller.

For a MiniLab 3 that is every port, since it sends its knobs on the port matching its current mode; for a VMX8, which repeats each message on both its ports, it is the main port alone (see ControllerProfile).

Parameters:

port_names – Iterable[str] available MIDI input port names

Returns:

list[str] the controller’s ports, main port first

jdxi_editor.midi.io.controller_map.find_controller_port(port_names: Iterable[str]) → str | None[source]

Pick the main input port of a supported hardware controller.

Parameters:

port_names – Iterable[str] available MIDI input port names

Returns:

Optional[str] the controller’s main port, or None if none is connected