use std::sync::Arc;
use crate::{Preset, Settings, Synth};
use crate::core::InterpolationMethod;
impl Synth {
pub fn settings(&self) -> &Settings {
&self.core.settings
}
pub fn set_gain(&mut self, gain: f32) {
self.core.settings.gain = if gain < 0.0 {
0.0
} else if gain > 10.0 {
10.0
} else {
gain
};
self.core.voices.set_gain(gain)
}
pub fn gain(&self) -> f32 {
self.core.settings.gain
}
pub fn set_polyphony(&mut self, polyphony: u16) -> Result<(), ()> {
if polyphony < 1 {
Err(())
} else {
self.core.settings.polyphony = polyphony;
self.core.voices.set_polyphony_limit(polyphony as usize);
Ok(())
}
}
pub fn polyphony(&self) -> u32 {
self.core.settings.polyphony as u32
}
pub fn internal_buffer_size(&self) -> usize {
64
}
pub fn set_interp_method(&mut self, chan: Option<usize>, interp_method: InterpolationMethod) {
if let Some(chan) = chan {
let ch = self.core.channels.iter_mut().find(|ch| ch.id() == chan);
if let Some(ch) = ch {
ch.set_interp_method(interp_method);
}
} else {
for ch in self.core.channels.iter_mut() {
ch.set_interp_method(interp_method);
}
}
}
pub fn channel_preset(&self, chan: u8) -> Option<&Arc<Preset>> {
if let Ok(channel) = self.core.channels.get(chan as usize) {
channel.preset()
} else {
log::warn!("Channel out of range");
None
}
}
}