Skip to content

API Reference#

actions #

actions_handler #

ActionsHandler #

Allows to execute actions and get their state using ids of controller elements.

Initializes the handler.

Parameters:

Name Type Description Default
bound_controller #
BoundController

Controller and binds that should be handled.

required
app #
Application

Application where the actions will be executed.

required
get_knob_value #
get_knob_value(knob_id: int) -> Optional[int]

Returns knob's value from the action associated with the knob.

handle_button_action #
handle_button_action(button_id: int) -> None

Executes an action associated with the button if it exists.

handle_knob_action #
handle_knob_action(
    *, knob_id: int, old_value: int, new_value: int
) -> None

Executes an action based on how the knob's value changed if it exists.

Parameters:

Name Type Description Default
knob_id #
int

The id of the knob.

required
old_value #
int

Value of the knob before it was rotated.

required
new_value #
int

Received new value of the knob.

required
is_button_toggled #
is_button_toggled(button_id: int) -> Optional[bool]

Checks if the action associated with the button is toggled.

bound_controller #

BoundController #

Bases: BaseModel

A controller with actions bound to its elements.

Attributes:

Name Type Description
knob_value_min int

The minimum value sent by the controller when a knob is rotated. Should be in the range [0, 127].

knob_value_max int

The maximum value sent by the controller when a knob is rotated. Should be in the range [0, 127].

buttons dict[int, ButtonActions]

All actions for a button with given id.

knobs dict[int, KnobActions]

All actions for a knob with given id.

create classmethod #

Creates an instance of BoundController.

Ensures that the arguments are valid, i.e., all needed actions exist, binds are intended for the provided controller, and all the bound elements exist on the controller.

Parameters:

Name Type Description Default
binds #
Binds

Information about binds.

required
controller #
Controller

Information about the controller the binds are for.

required
actions #
list[CommandRule]

List of actions available in the application the binds are for.

required

Returns:

Type Description
BoundController

A created model.

Raises:

Type Description
ValueError

If the provided arguments are invalid together.

get_button_press_action #
get_button_press_action(
    button_id: int,
) -> Optional[CommandRule]

Finds the action to be executed when a button is pressed.

Returns None if there is no such action.

get_knob_decrease_action #
get_knob_decrease_action(
    knob_id: int,
) -> Optional[CommandRule]

Finds action to be executed when knob's value is decreased.

Returns None if there is no such action.

get_knob_increase_action #
get_knob_increase_action(
    knob_id: int,
) -> Optional[CommandRule]

Finds action to be executed when knob's value is increased.

Returns None if there is no such action.

ButtonActions #

Bases: BaseModel

Action bound to a button.

Attributes:

Name Type Description
action_press CommandRule

Action to be executed when the button is pressed.

KnobActions #

Bases: BaseModel

Actions bound to a knob.

Attributes:

Name Type Description
action_increase Optional[CommandRule]

Action to be executed when the knob's value increases.

action_decrease Optional[CommandRule]

Action to be executed when the knob's value decreases.

config #

Config #

Class that stores configuration.

Attributes:

Name Type Description
BINDS_READONLY_DIR Path

Path to readonly binds shipped with the library.

BINDS_USER_DIR Path

Path to binds owned by the user.

BINDS_DIRS list[Path]

List of all paths where binds can be found.

BINDS_READONLY_DIR Path

Path to readonly controller schemas shipped with the library.

CONTROLLERS_USER_DIR Path

Path to controller schemas owned by the user.

CONTROLLER_DIRS list[Path]

List of all paths where controller schemas can be found.

APP_STATE_FILE Path

Path to a file where recent settings are saved.

get_yaml_files_in_dirs #

get_yaml_files_in_dirs(
    directories: Iterable[Path],
) -> list[Path]

Returns paths of all .yaml or .yml files in directories.

controller #

connected_controller #

ConnectedController #

A controller connected to the physical device capable of sending and receiving signals.

Attributes:

Name Type Description
controller Controller

Data about the controller, the create method will try to connect to.

actions_handler ActionsHandler

Actions handler class, responsible for executing actions, specific to a button press or a knob turn.

midi_in MidiIn

Midi input client interface from python-rtmidi package.

midi_out MidiOut

Midi output client interface from python-rtmidi package.

button_ids frozenset[int]

Set of all button ids on the controller.

knob_ids frozenset[int]

Set of all knob ids on the controller.

knob_engagement dict[int, int]

A dictionary that keeps the value of every knob.

butons_mutex QMutex

Mutex for worker threads.

flashing_buttons set[int]

Set with ids of buttons that are currently flashing.

knobs_mutex QMutex

Mutex for worker threads.

flashing_knobs set[int]

Set of the knob ids, that are currently flashing.

stopped bool

Indicates if the stop method was called.

paused bool

Indicates if the synchronization and standard handling is paused.

paused_button_callback Optional[Callable[[int], None]]

Function to be called with button id as an argument when paused and a message is received.

paused_knob_callback Optional[Callable[[int], None]]

Function to be called with knob id as an argument when paused and a message is received.

synchronize_buttons_thread Thread

Thread that checks values of the actions associated with buttons.

force_synchronize dict[int, bool]

Dictionary that indicates if there was a message from a button with given id, but the value associated with it wasn't synchronized yet.

Initializes ConnectedController.

Parameters:

Name Type Description Default
actions_handler #
ActionsHandler

Provides methods capable of executing actions in the app.

required
controller #
Controller

Information about the controller.

required
midi_in #
MidiIn

Midi input client with the controller's port opened.

required
midi_out #
MidiOut

Midi output client with the controller's port opened.

required
build_message #
build_message(
    command: int, channel: int, data: list[int]
) -> list[int]

Builds the MIDI message, that is later sent to the controller.

change_knob_value #
change_knob_value(id: int, new_value: int) -> None

Sends the MIDI message, responsible for changing a value assigned to a knob.

Parameters:

Name Type Description Default
id #
int

Knob id.

required
new_value #
int

Value to set the knob to.

required
check_set_and_run staticmethod #
check_set_and_run(
    func: Callable[[], None],
    id: int,
    mutex: QMutex,
    id_set: set[int],
) -> None

Checks if the provided set contains id. It executes func if it doesn't and does nothing otherwise.

Parameters:

Name Type Description Default
func #
Callable[[], None]

Function to execute.

required
id #
int

Id for which we check provided set.

required
mutex #
QMutex

Mutex for ensuring that checking id presence is mutually exclusive.

required
id_set #
set[int]

Set containing ids.

required
flash_button #
flash_button(id: int) -> None

Flashes the button LED on a MIDI controller.

Parameters:

Name Type Description Default
id #
int

Id of the button.

required
flash_knob #
flash_knob(id: int) -> None

Flashes the LEDs corresponding to a knob on a MIDI controller.

Parameters:

Name Type Description Default
id #
int

Id of the knob.

required
handle_button_disengagement #
handle_button_disengagement(data: list[int]) -> None

Runs the action bound to the button.

Parameters:

Name Type Description Default
data #
list[int]

Standard MIDI message.

required
handle_button_engagement #
handle_button_engagement(data: list[int]) -> None

Curently does nothing.

Parameters:

Name Type Description Default
data #
list[int]

Standard MIDI message.

required
handle_knob_message #
handle_knob_message(data: list[int]) -> None

Runs the action bound to the knob turn, specified in actions_handler.

Parameters:

Name Type Description Default
data #
list[int]

Standard MIDI message.

required
handle_midi_message #
handle_midi_message(
    command: int, channel: int, data: list[int]
) -> None

Handles the incoming MIDI message.

The message is interpreted as follows: [command*16+channel, data[0], data[1]], where the three numbers are unsigned ints.

Parameters:

Name Type Description Default
command #
int

Command id.

required
channel #
int

Channel the MIDI message came from.

required
data #
list[int]

Remaining part of the MIDI message.

required
init_buttons #
init_buttons() -> None

Initializes the buttons on the controller, setting them to the 'off' value.

init_knobs #
init_knobs() -> None

Initializes the knobs on the controller, setting them to the minimal value.

Adds knob entries to knob_engagement dictionary.

midi_callback #
midi_callback(
    event: tuple[list[int], float], data=None
) -> None

Callback function for MIDI input, specified by rtmidi package.

Parameters:

Name Type Description Default
event #
tuple[list[int], float]

Pair of (MIDI message, delta time).

required
pause #
pause(
    paused_button_callback: Optional[Callable[[int], None]],
    paused_knob_callback: Optional[Callable[[int], None]],
) -> None

Pauses synchronization and messages handling.

resume #
resume() -> None

Resumes synchronization and messages handling.

send_midi_message #
send_midi_message(data: list[int]) -> None

Sends the specified MIDI message.

Parameters:

Name Type Description Default
data #
list[int]

Standard MIDI message.

required
stop #
stop() -> None

Stops all threads and callbacks.

After calling this method, the object can be safely discarded.

synchronize_buttons #
synchronize_buttons() -> None

Synchronizes button values on controller with values from app.

For example, if user executes an action assosciated with a button directly in a GUI rather than on the MIDI controller, then this function will handle it.

turn_off_button_led #
turn_off_button_led(id: int) -> None

Sends the MIDI message, responsible for changing the button LED to 'off' state.

Parameters:

Name Type Description Default
id #
int

Button id.

required
turn_on_button_led #
turn_on_button_led(id: int) -> None

Sends the MIDI message, responsible for changing the button LED to 'on' state.

Parameters:

Name Type Description Default
id #
int

Button id.

required

gui #

binds_editor #

BindsEditor #

BindsEditor(
    controller: Controller,
    binds: Binds,
    actions: list[CommandRule],
    save_binds: Callable[[Binds], None],
    connected_controller: Optional[ConnectedController],
)

Bases: QDialog

Widget that allows to change actions bound to each knob/button and save them (or exit without saving).

Attributes:

Name Type Description
save_binds Callable[[list[KnobBind], list[ButtonBind]], None]

Function called after "Save and exit" button is clicked.

knobs_radio QRadioButton

Button that allows to switch binds view to knobs.

buttons_radio QRadioButton

Button that allows to switch binds view to buttons.

tab_widget QTabWidget

Tab widget for switching between knobs and buttons configurations.

knobs_widget KnobBinds

Widget with binds editor for knobs.

buttons_widget ButtonBinds

Widget with binds editor for buttons.

show_action_names_checkbox_button QCheckBox

Checkbox that toggles between action names and ids for buttons.

show_action_names_checkbox_knob QCheckBox

Checkbox that toggles between action names and ids for knobs.

Creates BindsEditor widget.

Parameters:

Name Type Description Default
controller #
Controller

Controller for which the binds are created.

required
binds #
Binds

Current binds that the widget will be initialized with.

required
actions #
list[CommandRule]

List of all actions available to bind.

required
save_binds #
Callable[[Binds], None]

Function called after "Save and exit" button is clicked.

required
update_action_names_checkboxes #
update_action_names_checkboxes()

Updates the checkboxes to be in sync.

ButtonBinds #

Bases: QWidget

Widget that allows to change actions bound to each button.

Attributes:

Name Type Description
actions_ list[CommandRule]

List of all actions available to bind and an empty string (used when no action is bound).

button_combos dict[int, ActionsQComboBox]

Dictionary mapping button ids to ActionsQComboBoxes used to set action.

binds_dict dict[int, ControllerElement]

Dictionary that allows to get a controller's button by its id.

stop bool

Indicates whether the widget should ignore new light up and highlight requests.

thread_list list[QThread]

List of worker threads responsible for lighting up buttons.

highlight_timers list[QTimer]

Timers used to unhighlight buttons.

Creates ButtonBinds widget.

Parameters:

Name Type Description Default
buttons #
list[ControllerElement]

List of all available buttons.

required
button_binds #
list[ButtonBind]

List of current binds.

required
actions #
list[CommandRule]

List of all actions available to bind.

required
connected_controller #
ConnectedController

Object representing currently connected MIDI controller.

required
show_action_names_checkbox #
QCheckBox

Checkbox that toggles between action names and ids.

required
get_binds #
get_binds() -> list[ButtonBind]

Returns list of all binds currently set in this widget.

highlight_button #
highlight_button(button_id: int) -> None

Highlights combos associated with button_id.

Starts a timer that unhighlights the combos after HIGHLIGHT_DURATION_MS.

stop_highlighting_button #
stop_highlighting_button(button_id: int) -> None

Unhighlights combos associated with knob_id.

KnobBinds #

Bases: QWidget

Widget that allows to change actions bound to each knob.

Attributes:

Name Type Description
actions_ list[CommandRule]

List of all actions available to bind and an empty string (used when no action is bound).

knob_combos dict[int, tuple[ActionsQComboBox, ActionsQComboBox]]

Dictionary mapping knob ids to ActionsQComboBoxes used to set increase and deacrease action.

binds_dict dict[int, ControllerElement]

Dictionary that allows to get a controller's knob by its id.

stop bool

Indicates whether the widget should ignore new light up and highlight requests.

thread_list list[QThread]

List of worker threads responsible for lighting up knobs.

highlight_timers list[QTimer]

Timers used to unhighlight knobs.

Creates KnobBinds widget.

Parameters:

Name Type Description Default
knobs #
list[ControllerElement]

List of all available knobs.

required
knob_binds #
list[KnobBind]

List of current binds.

required
actions #
list[CommandRule]

List of all actions available to bind.

required
connected_controller #
ConnectedController

Object representing currently connected MIDI controller.

required
show_action_names_checkbox #
QCheckBox

Checkbox that toggles between action names and ids.

required
get_binds #
get_binds() -> list[KnobBind]

Returns a list of all binds currently set in this widget.

highlight_knob #
highlight_knob(knob_id: int) -> None

Highlights combos associated with knob_id.

Starts a timer that unhighlights the combos after HIGHLIGHT_DURATION_MS.

stop_highlighting_knob #
stop_highlighting_knob(knob_id: int) -> None

Unhighlights combos associated with knob_id.

midi_status #

MidiStatus #

MidiStatus()

Bases: QWidget

Widget that allows to select currently used controller, binds, MIDI ports, to edit binds and to start/stop handling MIDI messages.

Attributes:

Name Type Description
current_binds DynamicQComboBox

Button that allows to select binds using its menu. Its text is set to currently selected binds.

current_controller DynamicQComboBox

Button that allows to select controller using its menu. Its text is set to currently selected controller.

current_midi_in DynamicQComboBox

Button that allows to select MIDI input port using its menu. Its text is set to currently selected port.

current_midi_out DynamicQComboBox

Button that allows to select MIDI output port using its menu. Its text is set to currently selected port.

status QLabel

Either "Running" or "Not running". Describes the status of MIDI messages handling.

start_handling_button QPushButton

Starts handling MIDI messages using currently selected items.

stop_handling_button QPushButton

Stops handling MIDI messages.

refresh #
refresh()

Updates all widgets to ensure they match the data stored inside the StateManager.

utils #

ActionsQComboBox #

ActionsQComboBox(
    actions: list[CommandRule],
    default_action_id: Optional[str],
    parent: QWidget = None,
)

Bases: QComboBox

QComboBox that allows to search available actions.

It also supports switching the display text for each action between its title and its id.

Creates ActionsQComboBox widget.

Parameters:

Name Type Description Default
actions #
list[CommandRule]

List of available actions.

required
default_action_id #
Optional[str]

Optional default action used to initialize the widget.

required
parent #
QWidget

Parent widget.

None
get_selected_action_id #
get_selected_action_id() -> Optional[str]

Returns the id of currently selected action.

toggle_names_mode #
toggle_names_mode() -> None

Switches the display text for each action between its title and its id.

DynamicQComboBox #

DynamicQComboBox(
    current_item: Optional[T],
    get_items: Callable[[], list[T]],
    select_item: Callable[[T], None],
    get_item_label: Callable[[T], str] = str,
    parent: QWidget = None,
)

Bases: QComboBox

QComboBox that refreshes the list of items each time it is opened.

Creates DynamicQComboBox widget.

Parameters:

Name Type Description Default
current_item #
Optional[T]

Optional default item.

required
get_items #
Callable[[], list[T]]

Function that fetches the list of current items. An option corresponding to "None" will be added anyway.

required
select_item #
Callable[[T], None]

Function that should be called when the user chooses an option.

required
get_item_label #
Callable[[T], str]

Function that returns a label corresponding to an item. Doesn't have to accept the "None" option.

str
parent #
QWidget

Parent widget.

None
refresh_items #
refresh_items()

Refresh the list of items. Optionally set currently selected item.

set_current #
set_current(
    item: Optional[T],
    _items: Optional[list[Optional[T]]] = None,
)

Sets the currently selected item.

Does not select the item if it's not in the list returned by get_items(). If provided, _items is used instead of calling get_items().

is_subpath #

is_subpath(path: Path, subpath: Path) -> bool

Checks if one path represents a file/directory inside the other directory.

reveal_in_explorer #

reveal_in_explorer(file: Path)

Show where the file is in the system's file explorer.

Currently only Windows, Linux (majority of distributions), and macOS are supported. On Linux, only the folder is opened.

vertical_layout #

vertical_layout(label: str, widget: QWidget) -> QVBoxLayout

Creates vertical layout consisting of the label and widget.

models #

app_state #

AppState #

Bases: YamlBaseModel

Schema of data StateManager should remember between sessions.

Attributes:

Name Type Description
selected_controller_path Optional[Path]

The path of the file with selected controller setup.

selected_binds_path Optional[Path]

The path of the file with selected binds setup.

selected_midi_in Optional[str]

Selected MIDI input port.

selected_midi_out Optional[str]

Selected MIDI output port.

recent_binds_for_controller dict[Path, Optional[Path]]

Mapping between each controller and which binds setup was last used.

recent_midi_ports_for_controller dict[Path, dict[str, Optional[str]]]

Mapping between controllers and the last used MIDI ports (in/out)

load_all_from classmethod #
load_all_from(
    directories: list[Path],
) -> list[tuple[YamlBaseModel, Path]]

Return models with data from all YAML files in multiple directories.

If a yaml file fails to load, it is skipped and a warning is emitted.

Parameters:

Name Type Description Default
directories #
list[Path]

List of paths to directories with YAML files inside.

required

Returns:

Type Description
list[tuple[cls, Path]]

List of created models with paths to corresponding YAML files.

load_from classmethod #
load_from(path: Path) -> YamlBaseModel

Creates a model initialized with data from a YAML file.

Parameters:

Name Type Description Default
path #
Path

YAML file path.

required

Returns:

Type Description
cls

A created model.

save_copy_to #
save_copy_to(path: Path, new_dir: Path) -> Path

Copy YAML to a new file avoiding file name collisions.

save_to #
save_to(path: Path) -> None

Saves the model's data to a YAML file.

Never saves anything to readonly dirs as defined in Config. The folder where the output file should be will also be created.

Parameters:

Name Type Description Default
path #
Path

YAML file path.

required

binds #

Binds #

Bases: YamlBaseModel

User's binds for specific app and controller.

Attributes:

Name Type Description
name str

The name of the binds set. Cannot be empty. Must be unique among all binds sets.

app_name str

For which app are the binds intended. Cannot be empty.

controller_name str

For which controller are the binds intended. Cannot be empty.

button_binds list[ButtonBind]

A list of bound buttons.

knob_binds list[KnobBind]

A list of bound knobs.

check_duplicate_ids classmethod #
check_duplicate_ids(values)

Ensures that every element has different id.

load_all_from classmethod #
load_all_from(
    directories: list[Path],
) -> list[tuple[YamlBaseModel, Path]]

Return models with data from all YAML files in multiple directories.

If a yaml file fails to load, it is skipped and a warning is emitted.

Parameters:

Name Type Description Default
directories #
list[Path]

List of paths to directories with YAML files inside.

required

Returns:

Type Description
list[tuple[cls, Path]]

List of created models with paths to corresponding YAML files.

load_from classmethod #
load_from(path: Path) -> YamlBaseModel

Creates a model initialized with data from a YAML file.

Parameters:

Name Type Description Default
path #
Path

YAML file path.

required

Returns:

Type Description
cls

A created model.

save_copy_to #
save_copy_to(path: Path, new_dir: Path) -> Path

Copy YAML to a new file avoiding file name collisions.

save_to #
save_to(path: Path) -> None

Saves the model's data to a YAML file.

Never saves anything to readonly dirs as defined in Config. The folder where the output file should be will also be created.

Parameters:

Name Type Description Default
path #
Path

YAML file path.

required

ButtonBind #

Bases: BaseModel

Information about an action bound to a button.

Attributes:

Name Type Description
button_id int

The id of the button. Should be in the range [0, 127].

action_id str

The id of an action to be executed when the button is pressed.

KnobBind #

Bases: BaseModel

Information about actions bound to a knob.

Attributes:

Name Type Description
knob_id int

The id of the knob. Should be in the range [0, 127].

action_id_increase str

The id of an action to be executed when the knob's value increases.

action_id_decrease str

The id of an action to be executed when the knob's value decreases.

controller #

Controller #

Bases: YamlBaseModel

A controller's schema.

Attributes:

Name Type Description
name str

The name of the controller. Cannot be empty. Must be unique among all schemas.

button_value_off int

The number sent by the controller when a button is in 'off' state. Should be in the range [0, 127].

button_value_on int

The number sent by the controller when a button is in 'on' state. Should be in the range [0, 127].

knob_value_min int

The minimum value sent by the controller when a knob is rotated. Should be in the range [0, 127].

knob_value_max int

The maximum value sent by the controller when a knob is rotated. Should be in the range [0, 127].

default_channel int

The default channel which MIDI messages will be sent on. Should be in the range [1, 16].

preferred_midi_in Optional[str]

MIDI input name that is preferred for this controller.

preferred_midi_out Optional[str]

MIDI output name that is preferred for this controller.

buttons list[ControllerElement]

List of available buttons on the controller.

knobs list[ControllerElement]

List of available knobs on the controller.

check_button_values classmethod #
check_button_values(values)

Ensures that the 'off' and 'on' values for buttons are different.

check_duplicate_ids classmethod #
check_duplicate_ids(values)

Ensures that every button and every knob has a different id.

check_duplicate_names classmethod #
check_duplicate_names(
    v: list[ControllerElement],
) -> list[ControllerElement]

Ensures that no two elements of same kind have the same name.

check_knob_values classmethod #
check_knob_values(values)

Ensures that the minimum value of knobs is smaller than the maximum value.

load_all_from classmethod #
load_all_from(
    directories: list[Path],
) -> list[tuple[YamlBaseModel, Path]]

Return models with data from all YAML files in multiple directories.

If a yaml file fails to load, it is skipped and a warning is emitted.

Parameters:

Name Type Description Default
directories #
list[Path]

List of paths to directories with YAML files inside.

required

Returns:

Type Description
list[tuple[cls, Path]]

List of created models with paths to corresponding YAML files.

load_from classmethod #
load_from(path: Path) -> YamlBaseModel

Creates a model initialized with data from a YAML file.

Parameters:

Name Type Description Default
path #
Path

YAML file path.

required

Returns:

Type Description
cls

A created model.

save_copy_to #
save_copy_to(path: Path, new_dir: Path) -> Path

Copy YAML to a new file avoiding file name collisions.

save_to #
save_to(path: Path) -> None

Saves the model's data to a YAML file.

Never saves anything to readonly dirs as defined in Config. The folder where the output file should be will also be created.

Parameters:

Name Type Description Default
path #
Path

YAML file path.

required

ControllerElement #

Bases: BaseModel

Any element of a controller.

Attributes:

Name Type Description
id int

The ID of the element that the controller sends with every event. Should be in the range [0, 127].

name str

A user-defined name for the element that helps to differentiate elements. Cannot be empty.

utils #

YamlBaseModel #

Bases: BaseModel

load_all_from classmethod #
load_all_from(
    directories: list[Path],
) -> list[tuple[YamlBaseModel, Path]]

Return models with data from all YAML files in multiple directories.

If a yaml file fails to load, it is skipped and a warning is emitted.

Parameters:

Name Type Description Default
directories #
list[Path]

List of paths to directories with YAML files inside.

required

Returns:

Type Description
list[tuple[cls, Path]]

List of created models with paths to corresponding YAML files.

load_from classmethod #
load_from(path: Path) -> YamlBaseModel

Creates a model initialized with data from a YAML file.

Parameters:

Name Type Description Default
path #
Path

YAML file path.

required

Returns:

Type Description
cls

A created model.

save_copy_to #
save_copy_to(path: Path, new_dir: Path) -> Path

Copy YAML to a new file avoiding file name collisions.

save_to #
save_to(path: Path) -> None

Saves the model's data to a YAML file.

Never saves anything to readonly dirs as defined in Config. The folder where the output file should be will also be created.

Parameters:

Name Type Description Default
path #
Path

YAML file path.

required

find_duplicate #

find_duplicate(values: list[Any]) -> Optional[Any]

Checks if there are any duplicates in the list and returns the first one.

Parameters:

Name Type Description Default
values #
list

The list of values to be searched for duplicates.

required

Returns:

Type Description
Any

The first duplicate if it exists.

None

If there are no duplicates.

state #

state_manager #

SelectedItem #

Bases: NamedTuple

Info about an item (controller or binds) backed by a file.

Attributes:

Name Type Description
name str

Display name of the item.

path Path

Path to the file containing the real data.

StateManager #

StateManager(app: Application)

Stores the state of the app (like selected controller, ports etc.) and allows to update it.

Attributes:

Name Type Description
selected_controller Optional[SelectedItem]

Currently selected schema of a controller.

selected_binds Optional[SelectedItem]

Currently selected binds set.

recent_binds_for_controller dict[Path, Path] = {}

Mapping of controller schemas to the binds set most recently used with the schema.

recent_midi_ports_for_controller dict[Path, dict[str, str]]

Mapping of controller schemas to the MIDI ports most recently used (precisely dict with keys "in" and "out") with the schema.

selected_midi_in Optional[str]

Name of currently selected MIDI input.

selected_midi_out Optional[str]

Name of currently selected MIDI output.

app Application

Used to execute actions.

connected_controller ConnectedController

Object that handles MIDI input and output.

_app_name str

Name of the app we want to handle. Used to filter binds files.

_midi_in MidiIn

MIDI input client interface.

_midi_out MidiOut

MIDI output client interface.

copy_binds #
copy_binds() -> Path

Copies currently selected binds and returns the new path.

delete_binds #
delete_binds() -> Path

Deleted currently selected binds.

get_actions #
get_actions() -> list[CommandRule]

Returns a list of all actions currently registered in app model (and available in the command pallette).

get_available_binds #
get_available_binds() -> list[SelectedItem]

Returns all binds sets suitable for current controller and app.

get_available_controllers #
get_available_controllers() -> list[SelectedItem]

Returns all available controller schemas.

get_available_midi_in #
get_available_midi_in() -> list[str]

Returns names of all available MIDI input ports.

get_available_midi_out #
get_available_midi_out() -> list[str]

Returns names of all available MIDI output ports.

is_running #
is_running() -> bool

Checks if any controller is being handled now.

load_state #
load_state()

Tries to load recent settings from the disk.

save_state #
save_state()

Saves the current settings to the disk.

select_binds #
select_binds(binds: Optional[SelectedItem]) -> None

Updates currently selected binds.

Does not have any immediate effect except updating the value.

select_binds_path #
select_binds_path(binds_path: Optional[Path]) -> None

Updates currently selected binds.

Does not have any immediate effect except updating the value and finding the name of the binds set.

select_controller #
select_controller(
    controller: Optional[SelectedItem],
) -> None

Updates currently selected controller schema.

Does not have any immediate effect except updating the value.

select_controller_path #
select_controller_path(
    controller_path: Optional[Path],
) -> None

Updates currently selected controller schema.

Does not have any immediate effect except updating the value and finding the name of the binds set.

select_default_midi_ports #
select_default_midi_ports()

Selects default port for the controller.

select_midi_in #
select_midi_in(port_name: Optional[str]) -> None

Updates currently selected MIDI input port name.

Does not have any immediate effect except updating the value.

select_midi_out #
select_midi_out(port_name: Optional[str]) -> None

Updates currently selected MIDI output port name.

Does not have any immediate effect except updating the value.

select_recent_binds #
select_recent_binds() -> None

Select binds that were recently used with the current controller.

select_recent_midi_ports #
select_recent_midi_ports()

Select MIDI ports that were recently used with the current controller.

start_handling #
start_handling() -> None

Starts handling MIDI input using current values of binds, controller, etc.

Stops the previous handler first. If any error occurs in this method, the previous handler will NOT be restored.

stop_handling #
stop_handling() -> None

Stops handling any MIDI signals.

get_state_manager #

get_state_manager() -> StateManager

Returns the StateManager singleton.

utils #

SimpleQThread #

SimpleQThread(func: Callable[[], None])

Bases: QThread

QThread responsible for running a function.

Attributes:

Name Type Description
func Callable[[], None]

Function to be called.

run #

run()

Runs the function.

get_copy_name #

get_copy_name(current_name: str) -> str

Finds a good name for a copy of a file.

Currently adds "({timestamp} copy)" to the end of the name, or replaces the timestamp with current time if already present.