use crate::{ffi, Synth};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u32)]
pub enum ChorusMode {
Sine = ffi::fluid_chorus_mod_FLUID_CHORUS_MOD_SINE as _,
Triangle = ffi::fluid_chorus_mod_FLUID_CHORUS_MOD_TRIANGLE as _,
}
impl Default for ChorusMode {
fn default() -> Self {
ChorusMode::Sine
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ChorusParams {
pub nr: u32,
pub level: f64,
pub speed: f64,
pub depth: f64,
pub mode: ChorusMode,
}
impl Default for ChorusParams {
fn default() -> Self {
Self {
nr: ffi::FLUID_CHORUS_DEFAULT_N,
level: ffi::FLUID_CHORUS_DEFAULT_LEVEL,
speed: ffi::FLUID_CHORUS_DEFAULT_SPEED,
depth: ffi::FLUID_CHORUS_DEFAULT_DEPTH,
mode: ChorusMode::default(),
}
}
}
impl Synth {
pub fn set_chorus_params(&self, nr: u32, level: f64, speed: f64, depth: f64, mode: ChorusMode) {
unsafe {
ffi::fluid_synth_set_chorus(self.handle, nr as i32, level, speed, depth, mode as i32);
}
}
pub fn set_chorus(&self, params: &ChorusParams) {
self.set_chorus_params(
params.nr,
params.level,
params.speed,
params.depth,
params.mode,
);
}
pub fn set_chorus_on(&self, on: bool) {
unsafe {
ffi::fluid_synth_set_chorus_on(self.handle, on as _);
}
}
pub fn get_chorus_nr(&self) -> u32 {
unsafe { ffi::fluid_synth_get_chorus_nr(self.handle) as _ }
}
pub fn get_chorus_level(&self) -> f64 {
unsafe { ffi::fluid_synth_get_chorus_level(self.handle) as _ }
}
pub fn get_chorus_speed(&self) -> f64 {
unsafe { ffi::fluid_synth_get_chorus_speed_Hz(self.handle) as _ }
}
pub fn get_chorus_depth(&self) -> f64 {
unsafe { ffi::fluid_synth_get_chorus_depth_ms(self.handle) as _ }
}
pub fn get_chorus_mode(&self) -> ChorusMode {
unsafe { core::mem::transmute(ffi::fluid_synth_get_chorus_type(self.handle)) }
}
pub fn get_chorus(&self) -> ChorusParams {
ChorusParams {
nr: self.get_chorus_nr(),
level: self.get_chorus_level(),
speed: self.get_chorus_speed(),
depth: self.get_chorus_depth(),
mode: self.get_chorus_mode(),
}
}
}