truce_rack_core/info.rs
1//! Metadata types — what scanners hand back, what plugins
2//! report about themselves.
3
4use std::path::PathBuf;
5
6/// What kind of plugin this is. Hosts use this to filter their
7/// browser (instruments separately from effects, etc.).
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum PluginCategory {
10 /// Audio effect — takes audio in, produces audio out.
11 Effect,
12 /// Instrument — takes MIDI in, produces audio out.
13 Instrument,
14 /// MIDI effect — takes MIDI in, produces MIDI out.
15 NoteEffect,
16 /// Analyzer / metering — observes audio, may not produce
17 /// audio output.
18 Analyzer,
19 /// Other tool category (utility, format converter, etc.).
20 Tool,
21}
22
23/// Scanner-side info about a discovered plugin. This is what
24/// hosts hand back from [`crate::PluginScanner::scan`]; the
25/// caller picks one and hands it back to
26/// [`crate::PluginScanner::load`] to materialise an instance.
27#[derive(Debug, Clone)]
28pub struct PluginInfo {
29 /// Display name.
30 pub name: String,
31 /// Vendor / manufacturer name.
32 pub vendor: String,
33 /// Plugin version, packed as host saw it.
34 pub version: u32,
35 /// Category for browser UIs.
36 pub category: PluginCategory,
37 /// Filesystem path to the bundle / dylib (where applicable).
38 pub path: PathBuf,
39 /// Format-specific stable id. CLAP uses the plugin id string,
40 /// VST3 uses the 16-byte CID rendered as hex, AU uses the
41 /// `type/subtype/manufacturer` 4ccs packed as
42 /// `"type:subtype:mfr"`. Hosts pass this back into `load`.
43 pub unique_id: String,
44 /// Which format wrapper produced this entry — `"clap"`,
45 /// `"vst3"`, `"au"`, etc. Lets a multi-format host that
46 /// aggregates scans tell entries apart in its browser.
47 pub format: &'static str,
48 /// Whether the plugin reports a GUI (a custom editor view).
49 pub has_editor: bool,
50 /// Whether the plugin handles MIDI input. Used by hosts that
51 /// only want to enumerate instruments / note effects.
52 pub accepts_midi: bool,
53}
54
55impl std::fmt::Display for PluginInfo {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 write!(
58 f,
59 "[{}] {} — {} (v{}, {:?})",
60 self.format, self.name, self.vendor, self.version, self.category
61 )
62 }
63}
64
65/// Per-parameter metadata. The host needs all of this *before*
66/// activation so it can build a parameter UI and wire automation.
67#[derive(Debug, Clone)]
68pub struct ParameterInfo {
69 /// Stable id for this parameter (format-specific — CLAP is a
70 /// 32-bit hash, VST3 is the `ParamID`, AU is the address).
71 pub id: u32,
72 /// Display name for the host UI.
73 pub name: String,
74 /// Short name for tight UI cells (truncated form of `name`).
75 pub short_name: String,
76 /// Unit label (`"dB"`, `"Hz"`, `"%"`, empty for unitless).
77 pub unit: String,
78 /// Minimum value in the parameter's native unit.
79 pub min: f64,
80 /// Maximum value in the parameter's native unit.
81 pub max: f64,
82 /// Default value in the parameter's native unit.
83 pub default: f64,
84 /// For stepped/integer parameters, the number of distinct
85 /// values (`0` for continuous).
86 pub step_count: u32,
87 /// Flag bits — bypass, automatable, hidden, etc.
88 pub flags: ParameterFlags,
89}
90
91bitflags::bitflags! {
92 /// Bitset for parameter capabilities and host hints. Format
93 /// wrappers map their native flags into this set.
94 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
95 pub struct ParameterFlags: u32 {
96 /// This parameter is the plugin's master bypass switch.
97 const BYPASS = 1 << 0;
98 /// Parameter can be automated (recorded by host
99 /// automation lanes).
100 const AUTOMATABLE = 1 << 1;
101 /// Host shouldn't show in its parameter list (plugin
102 /// uses it internally for state, but it's not user-facing).
103 const HIDDEN = 1 << 2;
104 /// Value is read-only (meter-style — plugin writes,
105 /// host reads, no UI mutation).
106 const READ_ONLY = 1 << 3;
107 /// Values are an enumeration with named entries — host
108 /// should call `parameter_value_string` to format
109 /// instead of formatting numerically.
110 const ENUMERATED = 1 << 4;
111 }
112}
113
114/// A factory preset entry.
115#[derive(Debug, Clone)]
116pub struct PresetInfo {
117 /// Zero-based index in the plugin's preset list.
118 pub index: usize,
119 /// Preset display name.
120 pub name: String,
121 /// Format-specific id passed back to `load_preset`. Stored
122 /// as `i32` because AU uses signed preset numbers (negative
123 /// values are reserved). CLAP / VST3 use ids comfortably
124 /// inside the `i32` range.
125 pub preset_number: i32,
126}