use sim_kernel::{Error, Result};
use sim_lib_audio_dsp::Gain;
use sim_lib_plugin_core::PluginInstance;
use crate::{Lv2ExportedProcessor, export_gain_as_lv2};
pub trait Lv2HostProvider {
type Plugin: PluginInstance;
fn instantiate(&self, uri: &str) -> Result<Self::Plugin>;
}
#[derive(Clone, Debug, PartialEq)]
pub struct FixtureLv2HostProvider {
uri: String,
gain: f32,
}
impl FixtureLv2HostProvider {
pub fn gain() -> Self {
Self {
uri: "https://sim.dev/lv2/gain".to_owned(),
gain: 0.5,
}
}
pub fn with_gain(mut self, gain: f32) -> Self {
self.gain = gain;
self
}
pub fn with_uri(mut self, uri: impl Into<String>) -> Self {
self.uri = uri.into();
self
}
pub fn uri(&self) -> &str {
&self.uri
}
}
impl Lv2HostProvider for FixtureLv2HostProvider {
type Plugin = Lv2ExportedProcessor<Gain>;
fn instantiate(&self, uri: &str) -> Result<Self::Plugin> {
if uri != self.uri {
return Err(Error::Eval(format!(
"LV2 fixture URI '{uri}' is not available"
)));
}
export_gain_as_lv2(self.gain)
}
}