use crate::OxiError;
impl crate::Synth {
pub fn set_tuning(&mut self, chan: u8, tuning: Option<Tuning>) -> Result<(), OxiError> {
let channel = self.core.channels.get_mut(chan as usize)?;
channel.set_tuning(tuning);
Ok(())
}
}
#[derive(Clone, Copy)]
pub struct Tuning {
pub(crate) pitch: [f64; 128],
}
impl Default for Tuning {
fn default() -> Self {
Self::new()
}
}
impl Tuning {
pub fn new() -> Self {
Self {
pitch: std::array::from_fn(|i| i as f64 * 100.0),
}
}
pub fn new_key_tuning(pitch: [f64; 128]) -> Self {
Self { pitch }
}
pub fn new_octave_tuning(pitch: &[f64; 12]) -> Self {
let mut tuning = Self::new();
for (i, v) in tuning.pitch.iter_mut().enumerate() {
*v = i as f64 * 100.0 + pitch[i % 12];
}
tuning
}
pub fn as_slice(&self) -> &[f64; 128] {
&self.pitch
}
pub fn as_slice_mut(&mut self) -> &mut [f64; 128] {
&mut self.pitch
}
}