jdxi_editor.midi.io.controller_map ================================== .. py:module:: jdxi_editor.midi.io.controller_map .. autoapi-nested-parse:: External MIDI controller maps ============================= 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 :class:`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`` (:func:`user_config_path`) is the user's copy, written on first start by :func:`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 (:mod:`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 :class:`FilterControl` name and ``source`` the physical knob or fader, shown in the MIDI Controller dialog. ``transport`` lists the controller's transport buttons (:class:`TransportAction` names), each sending a ``cc`` or a ``note``, with an optional ``channel`` (0 = MIDI channel 1). .. rubric:: Example >>> MINILAB3_FILTER_MAP[74] >>> 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] Attributes ---------- .. autoapisummary:: jdxi_editor.midi.io.controller_map.EFFECT_CONTROLS jdxi_editor.midi.io.controller_map.BUILTIN_CONFIG_PATH jdxi_editor.midi.io.controller_map.USER_CONFIG_NAME jdxi_editor.midi.io.controller_map.CONFIG_ENV_VAR jdxi_editor.midi.io.controller_map.CONTROLLER_PROFILES jdxi_editor.midi.io.controller_map.MINILAB3 jdxi_editor.midi.io.controller_map.VMX8 jdxi_editor.midi.io.controller_map.MINILAB3_FILTER_MAP jdxi_editor.midi.io.controller_map.VMX8_FILTER_MAP jdxi_editor.midi.io.controller_map.CONTROLLER_PORT_NAMES Classes ------- .. autoapisummary:: jdxi_editor.midi.io.controller_map.FilterControl jdxi_editor.midi.io.controller_map.TransportAction jdxi_editor.midi.io.controller_map.TransportSpec jdxi_editor.midi.io.controller_map.ControllerProfile Functions --------- .. autoapisummary:: jdxi_editor.midi.io.controller_map.user_config_path jdxi_editor.midi.io.controller_map.read_entries jdxi_editor.midi.io.controller_map._parse jdxi_editor.midi.io.controller_map.read_profiles jdxi_editor.midi.io.controller_map.load_controller_profiles jdxi_editor.midi.io.controller_map.install_user_config jdxi_editor.midi.io.controller_map._profile jdxi_editor.midi.io.controller_map.profile_by_id jdxi_editor.midi.io.controller_map.detect_profile jdxi_editor.midi.io.controller_map.find_controller_ports jdxi_editor.midi.io.controller_map.find_controller_port Module Contents --------------- .. py:class:: FilterControl Bases: :py:obj:`enum.Enum` Controls a hardware controller can drive; values are parameter names. Despite the name, this also covers the program effect levels (:data:`EFFECT_CONTROLS`), which the Effects editor holds. .. py:attribute:: CUTOFF :value: 'FILTER_CUTOFF' .. py:attribute:: RESONANCE :value: 'FILTER_RESONANCE' .. py:attribute:: KEYFOLLOW :value: 'FILTER_CUTOFF_KEYFOLLOW' .. py:attribute:: ENV_DEPTH :value: 'FILTER_ENV_DEPTH' .. py:attribute:: ENV_VELOCITY :value: 'FILTER_ENV_VELOCITY_SENSITIVITY' .. py:attribute:: ENV_ATTACK :value: 'FILTER_ENV_ATTACK_TIME' .. py:attribute:: ENV_DECAY :value: 'FILTER_ENV_DECAY_TIME' .. py:attribute:: ENV_SUSTAIN :value: 'FILTER_ENV_SUSTAIN_LEVEL' .. py:attribute:: ENV_RELEASE :value: 'FILTER_ENV_RELEASE_TIME' .. py:attribute:: EFFECT1_LEVEL :value: 'EFX1_LEVEL' .. py:attribute:: EFFECT2_LEVEL :value: 'EFX2_LEVEL' .. py:attribute:: DELAY_LEVEL :value: 'DELAY_LEVEL' .. py:attribute:: REVERB_LEVEL :value: 'REVERB_LEVEL' .. py:data:: EFFECT_CONTROLS .. py:class:: TransportAction Bases: :py:obj:`enum.Enum` Transport commands a hardware controller's buttons can request. .. py:attribute:: PLAY .. py:attribute:: PAUSE .. py:attribute:: STOP .. py:attribute:: RECORD .. py:attribute:: REWIND .. py:attribute:: FAST_FORWARD .. py:class:: TransportSpec One transport button of a controller, as ``midi_controllers.json`` lists it. :param action: TransportAction what the button does :param kind: str ``"cc"`` (press 127 / release 0) or ``"note"`` (note on / off) :param channel: int MIDI channel as mido numbers it (0 = MIDI channel 1) :param number: int CC or note number 0-127 .. py:attribute:: action :type: TransportAction .. py:attribute:: kind :type: str .. py:attribute:: channel :type: int .. py:attribute:: number :type: int .. py:method:: from_dict(entry: dict) -> TransportSpec :classmethod: Build a button from one ``transport`` entry, e.g. ``{"action": "PLAY", "cc": 52}``. :param entry: dict with ``action``, one of ``cc`` / ``note``, and optionally ``channel`` (default 0) :return: TransportSpec :raises KeyError: if the action is unknown or neither ``cc`` nor ``note`` is given :raises ValueError: if a number is outside its MIDI range .. py:method:: to_dict() -> dict This button as a ``transport`` entry, the inverse of :meth:`from_dict`. :return: dict e.g. ``{"action": "PLAY", "cc": 52, "channel": 0}`` .. py:property:: label :type: str What the button sends, for display. :return: str e.g. ``"CC 52"``, ``"Note 94"`` or ``"CC 52 (ch 2)"`` .. py:method:: matches(message: object) -> bool Whether ``message`` is a press of this button. :param message: mido.Message :return: bool True for a note-on with velocity, or a CC of 64 or more .. py:class:: ControllerProfile A supported hardware controller: how to find its ports, and its default map. :param profile_id: str stable id, used as the settings key :param label: str name shown in the MIDI Controller dialog :param port_names: tuple[str, ...] lower-case substrings of its port names :param secondary_port_names: tuple[str, ...] substrings of ports ranked after the main one :param single_port: bool listen to the main port only; for devices that send every message on each of their ports :param cc_map: dict CC number -> FilterControl defaults :param sources: dict FilterControl -> physical control that sends it, e.g. "Knob 1"; controls whose source is unknown are left out :param transport: tuple[TransportSpec, ...] its transport buttons .. py:attribute:: profile_id :type: str .. py:attribute:: label :type: str .. py:attribute:: port_names :type: tuple[str, ...] .. py:attribute:: secondary_port_names :type: tuple[str, ...] :value: () .. py:attribute:: single_port :type: bool :value: False .. py:attribute:: cc_map :type: dict[int, FilterControl] .. py:attribute:: sources :type: dict[FilterControl, str] .. py:attribute:: transport :type: tuple[TransportSpec, ...] :value: () .. py:method:: from_dict(entry: dict) -> ControllerProfile :classmethod: Build a profile from one ``controllers`` entry of the JSON config. :param entry: dict with ``id``, ``label``, ``port_names`` and ``mappings``, and optionally ``secondary_port_names``, ``single_port`` and ``transport`` :return: ControllerProfile :raises KeyError: if a required key or a control name is unknown :raises ValueError: if a CC number is not 0-127 :raises TypeError: if a value has the wrong type .. py:method:: matches(port_name: str) -> bool Whether ``port_name`` belongs to this controller. :param port_name: str MIDI port name :return: bool .. py:method:: ports(port_names: Iterable[str]) -> list[str] This controller's ports among ``port_names`` that should be opened. :param port_names: Iterable[str] available MIDI input port names :return: list[str] main port(s) first; only one for ``single_port`` .. py:data:: BUILTIN_CONFIG_PATH .. py:data:: USER_CONFIG_NAME :value: 'midi_controllers.json' .. py:data:: CONFIG_ENV_VAR :value: 'JDXI_EDITOR_MIDI_CONTROLLERS' .. py:function:: user_config_path() -> Optional[pathlib.Path] Where the user's controller config is read from. :return: Optional[Path] ``~/.jdxi_editor/midi_controllers.json``, the path in ``JDXI_EDITOR_MIDI_CONTROLLERS``, or None if that variable is empty .. py:function:: read_entries(path: pathlib.Path) -> list[dict] The raw ``controllers`` entries of one JSON config file. :param path: Path JSON file with a ``controllers`` list :return: list[dict] in file order :raises OSError: if the file cannot be read :raises ValueError: if it is not valid JSON .. py:function:: _parse(entries: Iterable[dict], origin: object) -> list[ControllerProfile] Profiles from raw entries; an entry that cannot be read is logged and skipped. :param entries: Iterable[dict] raw controller entries :param origin: object where they came from, for the log :return: list[ControllerProfile] .. py:function:: read_profiles(path: pathlib.Path) -> list[ControllerProfile] 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. :param path: Path JSON file with a ``controllers`` list :return: list[ControllerProfile] in file order :raises OSError: if the file cannot be read :raises ValueError: if it is not valid JSON .. py:function:: load_controller_profiles(user_path: Optional[pathlib.Path] = None) -> tuple[ControllerProfile, ...] 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. :param user_path: Optional[Path] user config; defaults to :func:`user_config_path` :return: tuple[ControllerProfile, ...] built-in order first, then new user ones .. py:function:: install_user_config(path: Optional[pathlib.Path] = None) -> Optional[pathlib.Path] Copy the built-in controller config to the user's, if there is none yet. An existing file is never overwritten. :param path: Optional[Path] destination; defaults to :func:`user_config_path` :return: Optional[Path] the user config, or None if it is disabled or could not be written .. py:data:: CONTROLLER_PROFILES :type: tuple[ControllerProfile, ...] :value: () .. py:function:: _profile(profile_id: str) -> ControllerProfile .. py:data:: MINILAB3 .. py:data:: VMX8 .. py:data:: MINILAB3_FILTER_MAP :type: dict[int, FilterControl] .. py:data:: VMX8_FILTER_MAP :type: dict[int, FilterControl] .. py:data:: CONTROLLER_PORT_NAMES .. py:function:: profile_by_id(profile_id: Optional[str]) -> ControllerProfile The profile with ``profile_id``, or the MiniLab 3 one if there is none. :param profile_id: Optional[str] :return: ControllerProfile .. py:function:: detect_profile(port_names: Iterable[str]) -> Optional[ControllerProfile] The first supported controller that has a port among ``port_names``. :param port_names: Iterable[str] MIDI port names :return: Optional[ControllerProfile] None if no supported controller is connected .. py:function:: find_controller_ports(port_names: Iterable[str]) -> list[str] 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 :class:`ControllerProfile`). :param port_names: Iterable[str] available MIDI input port names :return: list[str] the controller's ports, main port first .. py:function:: find_controller_port(port_names: Iterable[str]) -> Optional[str] Pick the main input port of a supported hardware controller. :param port_names: Iterable[str] available MIDI input port names :return: Optional[str] the controller's main port, or None if none is connected