use smallvec::{SmallVec, smallvec};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChannelConfig {
Mono,
Stereo,
Surround5_1,
Surround7_1,
Discrete(u32),
}
impl ChannelConfig {
#[must_use]
pub const fn count(self) -> u32 {
match self {
Self::Mono => 1,
Self::Stereo => 2,
Self::Surround5_1 => 6,
Self::Surround7_1 => 8,
Self::Discrete(n) => n,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BusKind {
Main,
Sidechain,
Auxiliary,
}
#[derive(Debug, Clone)]
pub struct Bus {
pub name: String,
pub kind: BusKind,
pub channels: ChannelConfig,
}
#[derive(Debug, Clone)]
pub struct BusLayout {
pub inputs: SmallVec<[Bus; 2]>,
pub outputs: SmallVec<[Bus; 2]>,
}
impl BusLayout {
#[must_use]
pub fn new() -> Self {
Self {
inputs: SmallVec::new(),
outputs: SmallVec::new(),
}
}
#[must_use]
pub fn mono() -> Self {
Self {
inputs: smallvec![Bus::main("Input", ChannelConfig::Mono)],
outputs: smallvec![Bus::main("Output", ChannelConfig::Mono)],
}
}
#[must_use]
pub fn stereo() -> Self {
Self {
inputs: smallvec![Bus::main("Input", ChannelConfig::Stereo)],
outputs: smallvec![Bus::main("Output", ChannelConfig::Stereo)],
}
}
#[must_use]
pub fn stereo_with_sidechain(sidechain_name: &str) -> Self {
Self {
inputs: smallvec![
Bus::main("Input", ChannelConfig::Stereo),
Bus::sidechain(sidechain_name, ChannelConfig::Stereo),
],
outputs: smallvec![Bus::main("Output", ChannelConfig::Stereo)],
}
}
#[must_use]
pub fn total_input_channels(&self) -> u32 {
self.inputs.iter().map(|b| b.channels.count()).sum()
}
#[must_use]
pub fn total_output_channels(&self) -> u32 {
self.outputs.iter().map(|b| b.channels.count()).sum()
}
}
impl Default for BusLayout {
fn default() -> Self {
Self::new()
}
}
impl Bus {
#[must_use]
pub fn main(name: &str, channels: ChannelConfig) -> Self {
Self {
name: name.to_string(),
kind: BusKind::Main,
channels,
}
}
#[must_use]
pub fn sidechain(name: &str, channels: ChannelConfig) -> Self {
Self {
name: name.to_string(),
kind: BusKind::Sidechain,
channels,
}
}
#[must_use]
pub fn auxiliary(name: &str, channels: ChannelConfig) -> Self {
Self {
name: name.to_string(),
kind: BusKind::Auxiliary,
channels,
}
}
}