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 fromBasePlugin:
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.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.title(str): Song titleartist(str): Artist namealbum(str): Album nameduration_ms(int): Track durationprogress_ms(int): Current progressis_playing(bool): Playback stateis_liked(bool): Saved/liked state
on_macro_execute(macro: Dict) → bool
Called before macro execution. ReturnFalse to block execution.
API Methods
Serial Communication
send_serial(command: str) → bool
Send command to device via serial.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.index(int): Macro index (0-8)page(int, optional): Page index (0-3), defaults to current page
True if triggered successfully
register_macro_type(type_name: str, handler: Callable) → bool
Register custom macro type.State Queries
get_slider_value(index: int) → Optional[int]
Get current slider value.None if invalid index
get_device_state() → Dict
Get device connection state.get_spotify_state() → Optional[Dict]
Get current Spotify playback state.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).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.title(str): Notification titlemessage(str): Notification message
log(message: str, level: str = ‘info’)
Log message to console with plugin prefix.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 inon_unload():
Settings Validation
Validate settings before use:Documentation Version: 1.0 Last Updated: 2025-12-10 API Version: 1.0