use super::{SynthSpec, BASIC};
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SynthConfig {
pub name: String,
pub options: Vec<(String, String)>,
#[cfg_attr(feature = "serde", serde(skip))]
pub samples: Vec<SampleAsset>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SampleAsset {
pub slot: u8,
pub path: String,
pub root_key: Option<u8>,
pub data: std::sync::Arc<[u8]>,
pub span: crate::compiler::diagnostic::Span,
}
pub const SAMPLE_SLOTS: u8 = 8;
impl SynthConfig {
pub fn get(&self, key: &str) -> Option<&str> {
self.options
.iter()
.find(|(k, _)| k == key)
.map(|(_, v)| v.as_str())
}
pub fn get_u32(&self, key: &str) -> Option<u32> {
self.get(key).and_then(|v| v.parse().ok())
}
pub fn defaults(spec: &SynthSpec) -> Self {
SynthConfig {
name: spec.name.to_string(),
options: spec
.options
.iter()
.map(|o| (o.name.to_string(), o.default.to_string()))
.collect(),
samples: Vec::new(),
}
}
}
impl Default for SynthConfig {
fn default() -> Self {
SynthConfig::defaults(&BASIC)
}
}