use super::{OptimizerConfig, RoomConfig, SpeakerConfig, SystemConfig};
use std::collections::HashMap;
use std::path::Path;
#[derive(Debug, Clone, Default)]
pub struct RoomConfigBuilder(RoomConfig);
impl RoomConfigBuilder {
pub fn new() -> Self {
Self(RoomConfig::default())
}
pub fn from_config(config: RoomConfig) -> Self {
Self(config)
}
#[must_use]
pub fn speaker(mut self, name: impl Into<String>, config: SpeakerConfig) -> Self {
self.0.speakers.insert(name.into(), config);
self
}
#[must_use]
pub fn speakers(mut self, speakers: HashMap<String, SpeakerConfig>) -> Self {
self.0.speakers = speakers;
self
}
#[must_use]
pub fn optimizer(mut self, optimizer: OptimizerConfig) -> Self {
self.0.optimizer = optimizer;
self
}
#[must_use]
pub fn provenance(mut self, provenance: super::ProvenanceConfig) -> Self {
self.0.provenance = provenance;
self
}
#[must_use]
pub fn system(mut self, system: SystemConfig) -> Self {
self.0.system = Some(system);
self
}
#[must_use]
pub fn target_curve(mut self, target_curve: super::TargetCurveConfig) -> Self {
self.0.target_curve = Some(target_curve);
self
}
#[must_use]
pub fn crossovers(mut self, crossovers: HashMap<String, super::CrossoverConfig>) -> Self {
self.0.crossovers = Some(crossovers);
self
}
#[must_use]
pub fn recording_config(mut self, recording_config: super::RecordingConfiguration) -> Self {
self.0.recording_config = Some(recording_config);
self
}
#[must_use]
pub fn ctc(mut self, ctc: super::CtcConfig) -> Self {
self.0.ctc = Some(ctc);
self
}
#[must_use]
pub fn resolve_paths(mut self, base_dir: &Path) -> Self {
self.0.resolve_paths(base_dir);
self
}
pub fn build(self) -> RoomConfig {
self.0
}
}
#[cfg(test)]
mod tests {
use super::RoomConfigBuilder;
use crate::Curve;
use crate::MeasurementSource;
use crate::roomeq::types::{OptimizerConfigBuilder, SpeakerConfig};
#[test]
fn builder_collects_speakers_and_optimizer() {
let config = RoomConfigBuilder::new()
.speaker(
"L",
SpeakerConfig::Single(MeasurementSource::InMemory(Curve::default())),
)
.optimizer(OptimizerConfigBuilder::new().num_filters(8).build())
.build();
assert!(config.speakers.contains_key("L"));
assert_eq!(config.optimizer.num_filters, 8);
}
}