Skip to main content

maolan_engine/plugins/
types.rs

1//! Pure data types for plugin metadata and state.
2//!
3//! This module contains no FFI or plugin-loading code; it exists so the
4//! engine can refer to plugin info / state types without linking against
5//! `libloading`, `vst3`, `lilv`, or `lv2_raw`.
6
7use crate::midi::io::MidiEvent;
8use serde::{Deserialize, Serialize};
9use std::path::Path;
10
11// ─── CLAP types ───
12
13#[derive(Clone, Debug, PartialEq)]
14pub struct ClapParameterInfo {
15    pub id: u32,
16    pub name: String,
17    pub module: String,
18    pub min_value: f64,
19    pub max_value: f64,
20    pub default_value: f64,
21}
22
23#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
24pub struct ClapPluginState {
25    pub bytes: Vec<u8>,
26}
27
28#[derive(Clone, Debug, PartialEq, Eq)]
29pub struct ClapMidiOutputEvent {
30    pub port: usize,
31    pub event: MidiEvent,
32}
33
34#[derive(Clone, Copy, Debug, Default)]
35pub struct ClapTransportInfo {
36    pub transport_sample: usize,
37    pub playing: bool,
38    pub loop_enabled: bool,
39    pub loop_range_samples: Option<(usize, usize)>,
40    pub bpm: f64,
41    pub tsig_num: u16,
42    pub tsig_denom: u16,
43}
44
45#[derive(Clone, Debug, PartialEq, Eq)]
46pub struct ClapGuiInfo {
47    pub api: String,
48    pub supports_embedded: bool,
49}
50
51#[derive(Clone, Copy, Debug)]
52pub struct ClapParamUpdate {
53    pub param_id: u32,
54    pub value: f64,
55}
56
57#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
58pub struct ClapPluginInfo {
59    pub name: String,
60    pub path: String,
61    pub capabilities: Option<ClapPluginCapabilities>,
62}
63
64#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
65pub struct ClapPluginCapabilities {
66    pub has_gui: bool,
67    pub gui_apis: Vec<String>,
68    pub supports_embedded: bool,
69    pub supports_floating: bool,
70    pub has_params: bool,
71    pub has_state: bool,
72    pub audio_inputs: usize,
73    pub audio_outputs: usize,
74    pub midi_inputs: usize,
75    pub midi_outputs: usize,
76}
77
78pub fn is_supported_clap_binary(path: &Path) -> bool {
79    path.extension()
80        .is_some_and(|ext| ext.eq_ignore_ascii_case("clap"))
81}
82
83// ─── VST3 types ───
84
85#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
86pub struct Vst3PluginInfo {
87    pub id: String,
88    pub name: String,
89    pub vendor: String,
90    pub path: String,
91    pub category: String,
92    pub version: String,
93    pub audio_inputs: usize,
94    pub audio_outputs: usize,
95    pub has_midi_input: bool,
96    pub has_midi_output: bool,
97}
98
99#[derive(Clone, Debug, Serialize, Deserialize)]
100pub struct ParameterInfo {
101    pub id: u32,
102    pub title: String,
103    pub short_title: String,
104    pub units: String,
105    pub step_count: i32,
106    pub default_value: f64,
107    pub flags: i32,
108}
109
110#[derive(Clone, Debug, Serialize, Deserialize)]
111pub struct Vst3PluginState {
112    pub plugin_id: String,
113    pub component_state: Vec<u8>,
114    pub controller_state: Vec<u8>,
115}
116
117#[derive(Clone, Debug, PartialEq, Eq)]
118pub struct Vst3GuiInfo {
119    pub has_gui: bool,
120    pub size: Option<(i32, i32)>,
121}
122
123// ─── LV2 types ───
124
125#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
126pub struct Lv2PluginInfo {
127    pub uri: String,
128    pub name: String,
129    pub class_label: String,
130    pub bundle_uri: String,
131    pub required_features: Vec<String>,
132    pub audio_inputs: usize,
133    pub audio_outputs: usize,
134    pub midi_inputs: usize,
135    pub midi_outputs: usize,
136}