1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
//! VST3 plugin discovery functionality
use crate::{error::Result, plugin::PluginInfo};
use serde::{Deserialize, Serialize};
use std::path::{Path, PathBuf};
use std::ptr;
/// Factory-level metadata (the plugin vendor's identity).
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct FactoryInfo {
/// Vendor / manufacturer name.
pub vendor: String,
/// Vendor URL.
pub url: String,
/// Vendor contact email.
pub email: String,
/// Raw factory flags.
pub flags: i32,
}
/// One class exported by a plugin's factory.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ClassInfo {
/// Class display name.
pub name: String,
/// Class category (e.g. "Audio Module Class").
pub category: String,
/// Class id, hex-encoded.
pub class_id: String,
/// Instantiation cardinality.
pub cardinality: i32,
/// Version string (if available).
pub version: String,
}
/// One audio or event bus.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BusInfo {
/// Bus display name.
pub name: String,
/// Bus type (Main = 0, Aux = 1).
pub bus_type: i32,
/// Raw bus flags.
pub flags: i32,
/// Number of channels on this bus.
pub channel_count: i32,
}
/// The plugin's full bus layout.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BusLayout {
/// Audio input buses.
pub audio_inputs: Vec<BusInfo>,
/// Audio output buses.
pub audio_outputs: Vec<BusInfo>,
/// Event (MIDI) input buses.
pub event_inputs: Vec<BusInfo>,
/// Event (MIDI) output buses.
pub event_outputs: Vec<BusInfo>,
}
/// A deep introspection report for a VST3 plugin — factory, classes, and bus layout.
/// This is the static metadata a plugin *inspector* UI needs, beyond the lightweight
/// [`PluginInfo`]. For the parameter list, load the plugin and call
/// [`crate::Plugin::get_parameters`] (which runs the full controller logic).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DetailedPluginInfo {
/// The basic metadata (also part of this report for convenience).
pub info: PluginInfo,
/// Factory / vendor identity.
pub factory: FactoryInfo,
/// All classes exported by the factory.
pub classes: Vec<ClassInfo>,
/// Full audio + event bus layout.
pub buses: BusLayout,
}
/// A complete, serializable report of a plugin: static introspection plus its parameter
/// list. Build it after loading the plugin and serialize to JSON for export (e.g. the
/// inspector's "Copy JSON", or feeding plugin metadata to other tools).
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginReport {
/// Static introspection: factory, classes, bus layout, basic info.
pub detailed: DetailedPluginInfo,
/// The plugin's parameters (normalized values + metadata).
pub parameters: Vec<crate::parameters::Parameter>,
}
impl PluginReport {
/// Bundle a [`DetailedPluginInfo`] with a parameter list (from
/// [`crate::Plugin::get_parameters`]).
pub fn new(
detailed: DetailedPluginInfo,
parameters: Vec<crate::parameters::Parameter>,
) -> Self {
Self {
detailed,
parameters,
}
}
/// Serialize the report to pretty-printed JSON.
pub fn to_json(&self) -> serde_json::Result<String> {
serde_json::to_string_pretty(self)
}
}
/// Scan standard VST3 directories for plugins
pub fn scan_standard_paths() -> Vec<PathBuf> {
let mut paths = Vec::new();
#[cfg(target_os = "macos")]
{
paths.push(PathBuf::from("/Library/Audio/Plug-Ins/VST3"));
if let Ok(home) = std::env::var("HOME") {
paths.push(PathBuf::from(format!(
"{}/Library/Audio/Plug-Ins/VST3",
home
)));
}
}
#[cfg(target_os = "windows")]
{
paths.push(PathBuf::from(r"C:\Program Files\Common Files\VST3"));
paths.push(PathBuf::from(r"C:\Program Files (x86)\Common Files\VST3"));
}
#[cfg(target_os = "linux")]
{
paths.push(PathBuf::from("/usr/lib/vst3"));
paths.push(PathBuf::from("/usr/local/lib/vst3"));
if let Ok(home) = std::env::var("HOME") {
paths.push(PathBuf::from(format!("{}/.vst3", home)));
}
}
paths
}
/// Scan directories for VST3 plugins
pub fn scan_directories(paths: &[PathBuf]) -> Result<Vec<PathBuf>> {
let mut plugins = Vec::new();
for path in paths {
if path.exists() {
scan_directory(path, &mut plugins)?;
}
}
// Remove duplicates and sort
plugins.sort();
plugins.dedup();
Ok(plugins)
}
/// Check if a plugin should be blacklisted
fn is_blacklisted(path: &Path) -> bool {
if let Some(file_name) = path.file_name() {
if let Some(name_str) = file_name.to_str() {
let name_lower = name_str.to_lowercase();
// Blacklist plugins known to cause issues (removed wave blacklisting)
return name_lower.contains("ozone"); // Only ozone for now
}
}
false
}
/// Recursively scan a directory for VST3 plugins
fn scan_directory(dir: &Path, plugins: &mut Vec<PathBuf>) -> Result<()> {
if let Ok(entries) = std::fs::read_dir(dir) {
for entry in entries.flatten() {
let path = entry.path();
// Check if it's a VST3 bundle/file
if let Some(ext) = path.extension() {
if ext == "vst3" {
// Skip blacklisted plugins
if !is_blacklisted(&path) {
plugins.push(path.clone());
} else {
eprintln!("Skipping blacklisted plugin: {}", path.display());
}
}
}
// Recursively scan subdirectories (but not .vst3 bundles)
if path.is_dir() && path.extension() != Some(std::ffi::OsStr::new("vst3")) {
scan_directory(&path, plugins)?;
}
}
}
Ok(())
}
/// Get metadata for a VST3 plugin without fully loading it
pub fn get_plugin_info(path: &Path) -> Result<PluginInfo> {
use vst3::Steinberg::Vst::BusDirections_::*;
use vst3::Steinberg::Vst::MediaTypes_::*;
use vst3::{ComPtr, Interface, Steinberg::Vst::*, Steinberg::*};
unsafe {
// Load the module using our VST3-compliant module loader
let module = crate::internal::module_loader::load_module(path)?;
// Get factory using the proper VST3 loading sequence
let factory_ptr = module.get_factory()?;
let factory = ComPtr::<IPluginFactory>::from_raw(factory_ptr).ok_or_else(|| {
crate::Error::PluginLoadFailed("Failed to create factory ComPtr".to_string())
})?;
// Get factory info
let mut factory_info: PFactoryInfo = std::mem::zeroed();
factory.getFactoryInfo(&mut factory_info);
let vendor = crate::internal::utils::c_str_to_string(&factory_info.vendor);
// Find audio component
let num_classes = factory.countClasses();
let mut plugin_name = String::new();
let mut category = String::new();
let mut version = String::new();
let mut uid = String::new();
let mut has_midi_input = false;
let mut has_midi_output = false;
let mut audio_inputs = 0u32;
let mut audio_outputs = 0u32;
let mut has_gui = false;
for i in 0..num_classes {
let mut class_info: PClassInfo = std::mem::zeroed();
if factory.getClassInfo(i, &mut class_info) == kResultOk {
let class_category = crate::internal::utils::c_str_to_string(&class_info.category);
if class_category.contains("Audio Module Class") {
plugin_name = crate::internal::utils::c_str_to_string(&class_info.name);
// Real version + sub-categories via IPluginFactory2 (PClassInfo.category
// is just "Audio Module Class"; the useful sub-categories live in
// PClassInfo2.subCategories). Left empty rather than faked when absent.
if let Some(f2) = factory.cast::<IPluginFactory2>() {
let mut info2: PClassInfo2 = std::mem::zeroed();
if f2.getClassInfo2(i, &mut info2) == kResultOk {
version = crate::internal::utils::c_str_to_string(&info2.version);
category =
crate::internal::utils::c_str_to_string(&info2.subCategories);
}
}
// Convert UID to string
// cid is an array of bytes, convert to hex string
uid = class_info
.cid
.iter()
.map(|b| format!("{:02X}", b))
.collect::<String>();
// Try to create component to get more info
let mut component_ptr: *mut IComponent = ptr::null_mut();
let result = factory.createInstance(
class_info.cid.as_ptr() as *const std::os::raw::c_char,
IComponent::IID.as_ptr() as *const std::os::raw::c_char,
&mut component_ptr as *mut _ as *mut _,
);
if result == kResultOk && !component_ptr.is_null() {
let component =
ComPtr::<IComponent>::from_raw(component_ptr).ok_or_else(|| {
crate::error::Error::Other("Failed to wrap component".to_string())
})?;
// Initialize with a host context (null crashes u-he/Waves plugins).
let host_app =
crate::internal::com_implementations::create_host_application();
let host_ctx = host_app.to_com_ptr::<IHostApplication>();
let context = host_ctx
.as_ref()
.map(|p| p.as_ptr() as *mut FUnknown)
.unwrap_or(ptr::null_mut());
component.initialize(context);
// Get bus counts
audio_inputs = component.getBusCount(kAudio as i32, kInput as i32) as u32;
audio_outputs = component.getBusCount(kAudio as i32, kOutput as i32) as u32;
// MIDI capability from event bus presence.
has_midi_input = component.getBusCount(kEvent as i32, kInput as i32) > 0;
has_midi_output = component.getBusCount(kEvent as i32, kOutput as i32) > 0;
// GUI detection (lightweight). A plugin has an editor when it provides
// an edit controller — either the component itself implements
// IEditController (single-component) or it names a separate controller
// class. The previous check only handled the single-component case, so
// it wrongly reported "no GUI" for the common separate-component
// plugins. A precise createView probe needs the plugin's full setup
// (component handler + activation) that only the load path performs;
// controller presence is the reliable fast signal here.
has_gui = component.cast::<IEditController>().is_some() || {
let mut cid: [std::os::raw::c_char; 16] = [0; 16];
component.getControllerClassId(&mut cid) == kResultOk
};
// Cleanup
component.terminate();
}
break;
}
}
}
// If no audio component found, use first class
if plugin_name.is_empty() && num_classes > 0 {
let mut class_info: PClassInfo = std::mem::zeroed();
if factory.getClassInfo(0, &mut class_info) == kResultOk {
plugin_name = crate::internal::utils::c_str_to_string(&class_info.name);
}
}
Ok(PluginInfo {
path: path.to_path_buf(),
name: if plugin_name.is_empty() {
path.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("Unknown")
.to_string()
} else {
plugin_name
},
vendor,
version,
category,
uid,
audio_inputs,
audio_outputs,
has_midi_input,
has_midi_output,
has_gui,
})
}
}
/// Deep-introspect a VST3 plugin: factory identity, exported classes, and bus layout.
///
/// Heavier than [`get_plugin_info`] (it enumerates every class and bus) but still does
/// not require driving audio. For the parameter list, load the plugin and call
/// [`crate::Plugin::get_parameters`].
pub fn get_detailed_plugin_info(path: &Path) -> Result<DetailedPluginInfo> {
use vst3::Steinberg::Vst::BusDirections_::*;
use vst3::Steinberg::Vst::BusInfo as VstBusInfo;
use vst3::Steinberg::Vst::MediaTypes_::*;
use vst3::{ComPtr, Interface, Steinberg::Vst::*, Steinberg::*};
// Reuse the lightweight pass for the basic info.
let info = get_plugin_info(path)?;
unsafe {
let module = crate::internal::module_loader::load_module(path)?;
let factory_ptr = module.get_factory()?;
let factory = ComPtr::<IPluginFactory>::from_raw(factory_ptr).ok_or_else(|| {
crate::Error::PluginLoadFailed("Failed to create factory ComPtr".to_string())
})?;
// Factory identity.
let mut fi: PFactoryInfo = std::mem::zeroed();
factory.getFactoryInfo(&mut fi);
let factory_info = FactoryInfo {
vendor: crate::internal::utils::c_str_to_string(&fi.vendor),
url: crate::internal::utils::c_str_to_string(&fi.url),
email: crate::internal::utils::c_str_to_string(&fi.email),
flags: fi.flags,
};
// Exported classes + locate the audio component class id.
let num_classes = factory.countClasses();
let mut classes = Vec::new();
let mut audio_cid: Option<[std::os::raw::c_char; 16]> = None;
for i in 0..num_classes {
let mut ci: PClassInfo = std::mem::zeroed();
if factory.getClassInfo(i, &mut ci) == kResultOk {
let category = crate::internal::utils::c_str_to_string(&ci.category);
let class_id = ci
.cid
.iter()
.map(|b| format!("{:02X}", b))
.collect::<String>();
if category.contains("Audio Module Class") && audio_cid.is_none() {
audio_cid = Some(ci.cid);
}
classes.push(ClassInfo {
name: crate::internal::utils::c_str_to_string(&ci.name),
category,
class_id,
cardinality: ci.cardinality,
version: String::new(), // not available in PClassInfo
});
}
}
// Bus layout from the audio component.
let mut buses = BusLayout::default();
if let Some(cid) = audio_cid {
let mut component_ptr: *mut IComponent = ptr::null_mut();
let result = factory.createInstance(
cid.as_ptr(),
IComponent::IID.as_ptr() as *const std::os::raw::c_char,
&mut component_ptr as *mut _ as *mut _,
);
if result == kResultOk && !component_ptr.is_null() {
if let Some(component) = ComPtr::<IComponent>::from_raw(component_ptr) {
// Initialize with a host context (null crashes u-he/Waves plugins).
let host_app = crate::internal::com_implementations::create_host_application();
let host_ctx = host_app.to_com_ptr::<IHostApplication>();
let context = host_ctx
.as_ref()
.map(|p| p.as_ptr() as *mut FUnknown)
.unwrap_or(ptr::null_mut());
component.initialize(context);
let collect = |media: i32, dir: i32| -> Vec<crate::discovery::BusInfo> {
let mut out = Vec::new();
let count = component.getBusCount(media, dir);
for i in 0..count {
let mut bi: VstBusInfo = std::mem::zeroed();
if component.getBusInfo(media, dir, i, &mut bi) == kResultOk {
out.push(crate::discovery::BusInfo {
name: crate::internal::utils::vst_string_to_string(&bi.name),
bus_type: bi.busType,
flags: bi.flags as i32,
channel_count: bi.channelCount,
});
}
}
out
};
buses.audio_inputs = collect(kAudio as i32, kInput as i32);
buses.audio_outputs = collect(kAudio as i32, kOutput as i32);
buses.event_inputs = collect(kEvent as i32, kInput as i32);
buses.event_outputs = collect(kEvent as i32, kOutput as i32);
component.terminate();
}
}
}
Ok(DetailedPluginInfo {
info,
factory: factory_info,
classes,
buses,
})
}
}
/// Platform-specific VST3 binary path resolution
pub fn get_vst3_binary_path(bundle_path: &Path) -> Result<PathBuf> {
// If it's already pointing to the binary, use it
if bundle_path.is_file() {
return Ok(bundle_path.to_path_buf());
}
// Platform-specific VST3 bundle handling
#[cfg(target_os = "macos")]
{
// macOS: .vst3 bundle structure
if bundle_path.extension() == Some(std::ffi::OsStr::new("vst3")) {
let contents_path = bundle_path.join("Contents").join("MacOS");
if let Ok(entries) = std::fs::read_dir(&contents_path) {
for entry in entries.flatten() {
let file_path = entry.path();
if file_path.is_file() {
if let Some(name) = file_path.file_name() {
if let Some(name_str) = name.to_str() {
// Skip hidden files and common non-binary files
if !name_str.starts_with('.')
&& !name_str.ends_with(".plist")
&& !name_str.ends_with(".txt")
{
return Ok(file_path);
}
}
}
}
}
}
}
}
#[cfg(target_os = "windows")]
{
// Windows: .vst3 file or folder structure
if bundle_path.is_dir() {
// Look for the .vst3 in the per-arch Contents folder. VST3 uses `arm64-win`
// (and `arm64ec-win`) for ARM64 — not `aarch64-win`. Native arch first.
let contents = bundle_path.join("Contents");
let arm64_path = contents.join("arm64-win");
let arm64ec_path = contents.join("arm64ec-win");
let x64_path = contents.join("x86_64-win");
let x86_path = contents.join("x86-win");
for contents_path in &[arm64_path, arm64ec_path, x64_path, x86_path] {
if let Ok(entries) = std::fs::read_dir(contents_path) {
for entry in entries.flatten() {
let file_path = entry.path();
if file_path.extension() == Some(std::ffi::OsStr::new("vst3")) {
return Ok(file_path);
}
}
}
}
}
}
#[cfg(target_os = "linux")]
{
// Linux: Similar to Windows
if bundle_path.is_dir() {
let contents_path = bundle_path.join("Contents");
let arch_paths = [
contents_path.join("aarch64-linux"),
contents_path.join("x86_64-linux"),
contents_path.join("i386-linux"),
];
for arch_path in &arch_paths {
if let Ok(entries) = std::fs::read_dir(arch_path) {
for entry in entries.flatten() {
let file_path = entry.path();
if file_path.extension() == Some(std::ffi::OsStr::new("so")) {
return Ok(file_path);
}
}
}
}
}
}
Err(crate::Error::PluginNotFound(format!(
"Could not find VST3 binary in bundle: {}",
bundle_path.display()
)))
}
#[cfg(test)]
mod report_tests {
use super::*;
use crate::plugin::PluginInfo;
#[test]
fn plugin_report_serializes_and_round_trips() {
let detail = DetailedPluginInfo {
info: PluginInfo {
path: std::path::PathBuf::from("/x/Dexed.vst3"),
name: "Dexed".into(),
vendor: "Digital Suburban".into(),
version: "1.0.0".into(),
category: "Instrument|Synth".into(),
uid: "ABCD".into(),
audio_inputs: 0,
audio_outputs: 1,
has_midi_input: true,
has_midi_output: true,
has_gui: true,
},
factory: FactoryInfo {
vendor: "Digital Suburban".into(),
..Default::default()
},
classes: vec![ClassInfo {
name: "Dexed".into(),
..Default::default()
}],
buses: BusLayout::default(),
};
let report = PluginReport::new(detail, Vec::new());
let json = report.to_json().expect("to_json");
// The export round-trips and preserves the accurate metadata.
let back: PluginReport = serde_json::from_str(&json).expect("round-trip");
assert_eq!(back.detailed.info.name, "Dexed");
assert_eq!(back.detailed.info.category, "Instrument|Synth");
assert!(back.detailed.info.has_midi_output);
assert_eq!(back.detailed.classes.len(), 1);
}
}