Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src-tauri/src/audio/plugins/clap_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,13 @@ impl PluginBackend for ClapBackend {
dirs
}

fn scan_bundle(&self, path: &Path) -> Vec<PluginDescriptor> {
fn scan_bundle(&self, path: &Path) -> Result<Vec<PluginDescriptor>, String> {
// Loading a foreign dylib is inherently unsafe: a non-compliant bundle
// can trigger any behavior just on load. Accepted per format design.
let entry = match unsafe { PluginEntry::load(path) } {
Ok(entry) => entry,
Err(err) => {
tracing::warn!("clap: failed to load {}: {err}", path.display());
return Vec::new();
}
};
let Some(factory) = entry.get_plugin_factory() else {
return Vec::new();
};
let entry = unsafe { PluginEntry::load(path) }.map_err(|err| format!("clap: {err}"))?;
let factory = entry
.get_plugin_factory()
.ok_or("clap: no plugin factory")?;
let path_str = path.to_string_lossy().into_owned();
let mut out = Vec::new();
for desc in factory.plugin_descriptors() {
Expand Down Expand Up @@ -103,7 +97,7 @@ impl PluginBackend for ClapBackend {
version,
});
}
out
Ok(out)
}
}

Expand Down
20 changes: 13 additions & 7 deletions src-tauri/src/audio/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum PluginFormat {

/// One instantiable plugin found by a scan. `uid` is stable across scans so the
/// graph can store a reference and re-resolve the plugin when the project loads.
#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PluginDescriptor {
pub uid: String,
Expand All @@ -70,19 +70,25 @@ pub trait PluginBackend {
fn search_dirs(&self) -> Vec<PathBuf>;
/// Bundle / library extension that marks a plugin, without the leading dot.
fn extension(&self) -> &'static str;
/// Enumerate the plugins inside one bundle / library path.
fn scan_bundle(&self, _path: &Path) -> Vec<PluginDescriptor> {
Vec::new()
/// Enumerate the plugins inside one bundle / library path. `Err` means the
/// bundle could not be read this time, as opposed to holding no effects.
fn scan_bundle(&self, _path: &Path) -> Result<Vec<PluginDescriptor>, String> {
Ok(Vec::new())
}
/// Full discovery for this format. The default walks `search_dirs` for
/// `extension` bundles; a format whose registry is not the filesystem
/// (Audio Units) overrides it.
fn scan(&self) -> Vec<PluginDescriptor> {
let mut out = Vec::new();
for dir in self.search_dirs() {
scan::walk(&dir, self.extension(), &mut |bundle| {
out.extend(self.scan_bundle(bundle))
});
scan::walk(
&dir,
self.extension(),
&mut |bundle| match self.scan_bundle(bundle) {
Ok(found) => out.extend(found),
Err(err) => tracing::warn!("{}: {err}", bundle.display()),
},
);
}
out
}
Expand Down
Loading
Loading