Skip to main content

Plugin API Reference

The Mixlar Plugin API allows developers to extend functionality through custom Python plugins with access to device events, serial communication, macros, and more.

Plugin Structure

Manifest Format

manifest.json defines plugin metadata, dependencies, and settings schema.

Manifest Fields

Base Plugin Class

All plugins must inherit from BasePlugin:

Lifecycle Hooks

on_load()

Called when plugin is loaded at startup.

on_unload()

Called when plugin is unloaded (app shutdown or plugin disabled).

on_enable()

Called when plugin is re-enabled after being disabled.

on_disable()

Called when plugin is disabled via settings.

Device Event Hooks

on_device_connect(port: str)

Called when hardware device connects.
Parameters:
  • port (str): Serial port name (e.g., “COM3” on Windows)

on_device_disconnect()

Called when hardware device disconnects.

Input Event Hooks

on_slider_change(index: int, value: int)

Called when slider value changes (hardware or software).

on_macro_button(index: int, page: int)

Called when macro button is pressed.

on_mute_button(index: int, state: bool)

Called when mute button is toggled.

on_encoder_turn(direction: int)

Called when rotary encoder is turned.

on_encoder_press(press_type: str)

Called when encoder button is pressed.

Serial & Display Hooks

on_serial_receive(data: str)

Called when raw serial data is received from device.

on_page_change(page_name: str)

Called when display page changes.

on_macro_page_change(page_index: int)

Called when macro page changes.

Application Hooks

on_spotify_track_change(track_info: Dict)

Called when Spotify track changes.
Track Info Fields:
  • title (str): Song title
  • artist (str): Artist name
  • album (str): Album name
  • duration_ms (int): Track duration
  • progress_ms (int): Current progress
  • is_playing (bool): Playback state
  • is_liked (bool): Saved/liked state

on_macro_execute(macro: Dict) → bool

Called before macro execution. Return False to block execution.

API Methods

Serial Communication

send_serial(command: str) → bool

Send command to device via serial.
Returns: True if sent successfully, False if device disconnected Available Commands: See Serial Communication Protocol

Macro Control

trigger_macro(index: int, page: Optional[int] = None) → bool

Programmatically execute a macro.
Parameters:
  • index (int): Macro index (0-8)
  • page (int, optional): Page index (0-3), defaults to current page
Returns: True if triggered successfully

register_macro_type(type_name: str, handler: Callable) → bool

Register custom macro type.
Macro Usage:

State Queries

get_slider_value(index: int) → Optional[int]

Get current slider value.
Returns: Value (0-100) or None if invalid index

get_device_state() → Dict

Get device connection state.

get_spotify_state() → Optional[Dict]

Get current Spotify playback state.
Returns: Dictionary with track info or None if Spotify not active

get_all_macros() → Dict[int, List[Dict]]

Get all configured macros.

Settings Management

get_setting(key: str, default: Any = None) → Any

Get plugin setting value.

set_setting(key: str, value: Any)

Save plugin setting (persists to config).
Note: Settings are automatically saved to mixer_config.json under plugin ID

get_all_settings() → Dict

Get all plugin settings.

UI & Notifications

show_notification(title: str, message: str)

Show system tray notification.
Parameters:
  • title (str): Notification title
  • message (str): Notification message

log(message: str, level: str = ‘info’)

Log message to console with plugin prefix.
Levels: info, warning, error Output: [PluginName] Message

Serial Communication Protocol

Commands (PC → Device)

Messages (Device → PC)

Complete Plugin Example

Best Practices

Thread Safety

Always use daemon threads for background tasks:

Error Handling

Always catch exceptions in hooks:

Resource Cleanup

Clean up resources in on_unload():

Settings Validation

Validate settings before use:

Documentation Version: 1.0 Last Updated: 2025-12-10 API Version: 1.0