#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(transparent)]
pub struct PanVolume(i32);
impl PanVolume {
pub const CENTER: Self = Self(64);
pub const LEFT: Self = Self(0);
pub const RIGHT: Self = Self(128);
pub const fn from_separate(left: i32, right: i32) -> Self {
Self(if left < 64 { 128 - left } else { right })
}
pub fn from_ratios(left: f32, right: f32) -> Self {
Self::from_separate((left * 64.) as i32, (right * 64.) as i32)
}
pub const fn as_value(&self) -> i32 {
self.0
}
pub fn as_separate(&self) -> (i32, i32) {
(64.min(128 - self.0), 64.min(self.0))
}
pub fn as_ratios(&self) -> (f32, f32) {
let (left, right) = self.as_separate();
((left as f32) / 64., (right as f32) / 64.)
}
}
impl From<i32> for PanVolume {
fn from(value: i32) -> Self {
Self(value)
}
}
impl Default for PanVolume {
fn default() -> Self {
Self::CENTER
}
}