use std::sync::Arc;
use crate::plugin::PluginRuntime;
use truce_params::{ParamInfo, Params};
pub trait PluginExport: PluginRuntime + Sized {
type Params: Params;
fn create() -> Self;
fn params(&self) -> &Self::Params;
fn params_arc(&self) -> Arc<Self::Params>;
fn meter_store(&self) -> Arc<crate::meters::MeterStore>;
fn snapshot_slot(&self) -> Arc<crate::snapshot::SnapshotSlot>;
fn task_spawner(&self) -> Option<crate::tasks::AnyTaskSpawner> {
None
}
fn editor_builder(&self) -> crate::editor::EditorBuilder<Self::Params> {
Box::new(|_params| None)
}
#[must_use]
fn param_infos_static() -> Vec<ParamInfo> {
let from_params = <Self::Params as Params>::param_infos_static();
if from_params.is_empty() {
Self::create().params().param_infos()
} else {
from_params
}
}
#[must_use]
fn has_editor_static() -> bool {
let plugin = Self::create();
plugin.editor_builder()(plugin.params_arc()).is_some()
}
}
#[must_use]
pub fn read_custom_state_offthread<P: PluginExport>(plugin: &P) -> Vec<u8> {
plugin.snapshot_slot().read_offthread().unwrap_or_else(|| {
let mut buf = Vec::new();
plugin.snapshot_into(&mut buf);
buf
})
}