API Reference#
actions
#
actions_handler
#
ActionsHandler
#
ActionsHandler(
*, bound_controller: BoundController, app: Application
)
Allows to execute actions and get their state using ids of controller elements.
Initializes the handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
BoundController
|
Controller and binds that should be handled. |
required |
|
Application
|
Application where the actions will be executed. |
required |
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
#
create(
*,
binds: Binds,
controller: Controller,
actions: list[CommandRule]
) -> BoundController
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
|
Information about binds. |
required |
|
Controller
|
Information about the controller the binds are for. |
required |
|
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. |
controller
#
connected_controller
#
ConnectedController
#
ConnectedController(
*,
actions_handler: ActionsHandler,
controller: Controller,
midi_in: MidiIn,
midi_out: MidiOut
)
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 |
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_knob_callback |
Optional[Callable[[int], None]]
|
Function to be called with knob id as an argument when |
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 |
|---|---|---|---|
|
ActionsHandler
|
Provides methods capable of executing actions in the app. |
required |
|
Controller
|
Information about the controller. |
required |
|
MidiIn
|
Midi input client with the controller's port opened. |
required |
|
MidiOut
|
Midi output client with the controller's port opened. |
required |
build_message
#
Builds the MIDI message, that is later sent to the controller.
change_knob_value
#
check_set_and_run
staticmethod
#
Checks if the provided set contains id.
It executes func if it doesn't and does nothing otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Callable[[], None]
|
Function to execute. |
required |
|
int
|
Id for which we check provided set. |
required |
|
QMutex
|
Mutex for ensuring that checking |
required |
|
set[int]
|
Set containing ids. |
required |
flash_button
#
flash_knob
#
handle_button_disengagement
#
handle_button_engagement
#
handle_knob_message
#
handle_midi_message
#
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 |
|---|---|---|---|
|
int
|
Command id. |
required |
|
int
|
Channel the MIDI message came from. |
required |
|
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
#
pause
#
pause(
paused_button_callback: Optional[Callable[[int], None]],
paused_knob_callback: Optional[Callable[[int], None]],
) -> None
Pauses synchronization and messages handling.
send_midi_message
#
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
#
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 for which the binds are created. |
required |
|
Binds
|
Current binds that the widget will be initialized with. |
required |
|
list[CommandRule]
|
List of all actions available to bind. |
required |
|
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
#
ButtonBinds(
buttons: list[ControllerElement],
button_binds: list[ButtonBind],
actions: list[CommandRule],
connected_controller: Optional[ConnectedController],
show_action_names_checkbox: QCheckBox,
)
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 |
|---|---|---|---|
|
list[ControllerElement]
|
List of all available buttons. |
required |
|
list[ButtonBind]
|
List of current binds. |
required |
|
list[CommandRule]
|
List of all actions available to bind. |
required |
|
ConnectedController
|
Object representing currently connected MIDI controller. |
required |
|
QCheckBox
|
Checkbox that toggles between action names and ids. |
required |
KnobBinds
#
KnobBinds(
knobs: list[ControllerElement],
knob_binds: list[KnobBind],
actions: list[CommandRule],
connected_controller: Optional[ConnectedController],
show_action_names_checkbox: QCheckBox,
)
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 |
|---|---|---|---|
|
list[ControllerElement]
|
List of all available knobs. |
required |
|
list[KnobBind]
|
List of current binds. |
required |
|
list[CommandRule]
|
List of all actions available to bind. |
required |
|
ConnectedController
|
Object representing currently connected MIDI controller. |
required |
|
QCheckBox
|
Checkbox that toggles between action names and ids. |
required |
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 |
|---|---|---|---|
|
list[CommandRule]
|
List of available actions. |
required |
|
Optional[str]
|
Optional default action used to initialize the widget. |
required |
|
QWidget
|
Parent widget. |
None
|
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 |
|---|---|---|---|
|
Optional[T]
|
Optional default item. |
required |
|
Callable[[], list[T]]
|
Function that fetches the list of current items. An option corresponding to "None" will be added anyway. |
required |
|
Callable[[T], None]
|
Function that should be called when the user chooses an option. |
required |
|
Callable[[T], str]
|
Function that returns a label corresponding to an item. Doesn't have to accept the "None" option. |
str
|
|
QWidget
|
Parent widget. |
None
|
is_subpath
#
Checks if one path represents a file/directory inside the other directory.
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 |
|---|---|---|---|
|
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
save_copy_to
#
Copy YAML to a new file avoiding file name collisions.
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 |
|---|---|---|---|
|
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
save_copy_to
#
Copy YAML to a new file avoiding file name collisions.
ButtonBind
#
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 |
|---|---|---|---|
|
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
save_copy_to
#
Copy YAML to a new file avoiding file name collisions.
ControllerElement
#
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 |
|---|---|---|---|
|
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
save_copy_to
#
Copy YAML to a new file avoiding file name collisions.
find_duplicate
#
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. |
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
#
Returns names of all available MIDI input ports.
get_available_midi_out
#
Returns names of all available MIDI output ports.
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
#
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
#
Updates currently selected controller schema.
Does not have any immediate effect except updating the value and finding the name of the binds set.
select_midi_in
#
Updates currently selected MIDI input port name.
Does not have any immediate effect except updating the value.
select_midi_out
#
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.