| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
use tracing::instrument; |
| 8 |
|
| 9 |
use crate::error::PluginError; |
| 10 |
use crate::hooks::CompiledHooks; |
| 11 |
use crate::manifest::{manifest_to_profile, parse_manifest}; |
| 12 |
use crate::registry::{LoadedPlugin, PluginRegistry}; |
| 13 |
|
| 14 |
|
| 15 |
const BUNDLED_MANIFESTS: &[(&str, &str)] = &[ |
| 16 |
( |
| 17 |
"sp404mkii", |
| 18 |
include_str!("../plugins/bundled/sp404mkii/manifest.toml"), |
| 19 |
), |
| 20 |
( |
| 21 |
"mpc", |
| 22 |
include_str!("../plugins/bundled/mpc/manifest.toml"), |
| 23 |
), |
| 24 |
( |
| 25 |
"digitakt", |
| 26 |
include_str!("../plugins/bundled/digitakt/manifest.toml"), |
| 27 |
), |
| 28 |
( |
| 29 |
"octatrack", |
| 30 |
include_str!("../plugins/bundled/octatrack/manifest.toml"), |
| 31 |
), |
| 32 |
( |
| 33 |
"op1", |
| 34 |
include_str!("../plugins/bundled/op1/manifest.toml"), |
| 35 |
), |
| 36 |
( |
| 37 |
"deluge", |
| 38 |
include_str!("../plugins/bundled/deluge/manifest.toml"), |
| 39 |
), |
| 40 |
( |
| 41 |
"model_samples", |
| 42 |
include_str!("../plugins/bundled/model_samples/manifest.toml"), |
| 43 |
), |
| 44 |
( |
| 45 |
"polyend_tracker", |
| 46 |
include_str!("../plugins/bundled/polyend_tracker/manifest.toml"), |
| 47 |
), |
| 48 |
( |
| 49 |
"circuit_rhythm", |
| 50 |
include_str!("../plugins/bundled/circuit_rhythm/manifest.toml"), |
| 51 |
), |
| 52 |
( |
| 53 |
"maschine_plus", |
| 54 |
include_str!("../plugins/bundled/maschine_plus/manifest.toml"), |
| 55 |
), |
| 56 |
( |
| 57 |
"m8", |
| 58 |
include_str!("../plugins/bundled/m8/manifest.toml"), |
| 59 |
), |
| 60 |
( |
| 61 |
"digitakt_ii", |
| 62 |
include_str!("../plugins/bundled/digitakt_ii/manifest.toml"), |
| 63 |
), |
| 64 |
( |
| 65 |
"blackbox", |
| 66 |
include_str!("../plugins/bundled/blackbox/manifest.toml"), |
| 67 |
), |
| 68 |
( |
| 69 |
"volca_sample_2", |
| 70 |
include_str!("../plugins/bundled/volca_sample_2/manifest.toml"), |
| 71 |
), |
| 72 |
]; |
| 73 |
|
| 74 |
|
| 75 |
#[instrument(skip_all)] |
| 76 |
pub fn load_bundled(registry: &mut PluginRegistry) -> Result<(), PluginError> { |
| 77 |
for (slug, toml_str) in BUNDLED_MANIFESTS { |
| 78 |
let manifest = parse_manifest(toml_str).map_err(|e| { |
| 79 |
PluginError::ManifestParse(format!("bundled plugin '{slug}': {e}")) |
| 80 |
})?; |
| 81 |
|
| 82 |
let profile = manifest_to_profile(&manifest)?; |
| 83 |
|
| 84 |
|
| 85 |
let hooks = CompiledHooks { |
| 86 |
validate_sample: None, |
| 87 |
transform_filename: None, |
| 88 |
pre_export: None, |
| 89 |
post_export: None, |
| 90 |
}; |
| 91 |
|
| 92 |
registry.insert(LoadedPlugin { |
| 93 |
profile, |
| 94 |
hooks, |
| 95 |
bundled: true, |
| 96 |
}); |
| 97 |
} |
| 98 |
|
| 99 |
Ok(()) |
| 100 |
} |
| 101 |
|
| 102 |
#[cfg(test)] |
| 103 |
mod tests { |
| 104 |
use super::*; |
| 105 |
|
| 106 |
#[test] |
| 107 |
fn all_bundled_manifests_parse() { |
| 108 |
for (slug, toml_str) in BUNDLED_MANIFESTS { |
| 109 |
let manifest = parse_manifest(toml_str) |
| 110 |
.unwrap_or_else(|e| panic!("bundled plugin '{slug}' failed to parse: {e}")); |
| 111 |
let profile = manifest_to_profile(&manifest) |
| 112 |
.unwrap_or_else(|e| panic!("bundled plugin '{slug}' failed to convert: {e}")); |
| 113 |
assert!(!profile.name.is_empty(), "plugin '{slug}' has empty name"); |
| 114 |
assert!( |
| 115 |
!profile.audio.formats.is_empty(), |
| 116 |
"plugin '{slug}' has no formats" |
| 117 |
); |
| 118 |
assert!( |
| 119 |
!profile.audio.sample_rates.is_empty(), |
| 120 |
"plugin '{slug}' has no sample rates" |
| 121 |
); |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
#[test] |
| 126 |
fn load_bundled_populates_registry() { |
| 127 |
let mut registry = PluginRegistry::new(); |
| 128 |
load_bundled(&mut registry).unwrap(); |
| 129 |
assert_eq!(registry.len(), 14); |
| 130 |
} |
| 131 |
} |
| 132 |
|