use {
crate::{
dsp_graph::DspGraph,
dsp_source::{DspSource, SourceType},
DEFAULT_SAMPLE_RATE,
},
bevy::{
prelude::{default, Resource},
utils::HashMap,
},
uuid::Uuid,
};
#[derive(Resource)]
pub struct DspManager {
collection: HashMap<Uuid, DspSource>,
sample_rate: f32,
}
impl Default for DspManager {
fn default() -> Self {
Self::new(*DEFAULT_SAMPLE_RATE)
}
}
impl DspManager {
pub(crate) fn new(sample_rate: f32) -> Self {
Self {
sample_rate,
collection: default(),
}
}
pub(crate) fn add_graph<D: DspGraph>(&mut self, dsp_graph: D, source_type: SourceType) {
self.collection.insert(
dsp_graph.id(),
DspSource::new(dsp_graph, self.sample_rate, source_type),
);
}
#[allow(clippy::needless_pass_by_value)]
pub fn get_graph<D: DspGraph>(&self, dsp_graph: D) -> Option<&DspSource> {
self.collection.get(&dsp_graph.id())
}
}