diff --git a/pipeswitch-lib/src/pw/mod.rs b/pipeswitch-lib/src/pw/mod.rs index ceed6a5..41a1f02 100644 --- a/pipeswitch-lib/src/pw/mod.rs +++ b/pipeswitch-lib/src/pw/mod.rs @@ -24,8 +24,6 @@ pub enum PipewireError { MissingProps(u32, ObjectType, HashMap), #[error("direction not valid: {0}")] InvalidDirection(String), - #[error("channel not valid: {0}")] - InvalidChannel(String), #[error("error with core pipewire interface: {0}")] PipewireInterfaceError(#[from] pipewire::Error), #[error("tried to delete a global object that was not yet registered: {0}")] diff --git a/pipeswitch-lib/src/pw/types.rs b/pipeswitch-lib/src/pw/types.rs index b8aea0c..8670d4a 100644 --- a/pipeswitch-lib/src/pw/types.rs +++ b/pipeswitch-lib/src/pw/types.rs @@ -36,42 +36,26 @@ impl Direction { } #[derive(Debug, Clone, PartialEq, Eq)] -pub enum Channel { - Left, - Right, - Mono, - Aux(u32), +pub struct Channel { + short_name: String, } impl Channel { - fn from_channel>(input: Option) -> Result, PipewireError> { - if let Some(input) = input { - let input = input.into(); - Ok(Some(match input.as_str() { - "FL" => Channel::Left, - "FR" => Channel::Right, - "MONO" => Channel::Mono, - i if i.starts_with("AUX") => { - let num = i.split_at("AUX".len()).1.parse()?; - match num { - 0 => Channel::Left, - 1 => Channel::Right, - _ => Channel::Aux(num), - } - } - _ => Err(PipewireError::InvalidChannel(input))?, - })) - } else { - Ok(None) - } + fn from_channel>(input: Option) -> Option { + Some(Self { + short_name: input?.into(), + }) } - fn from_portid(input: u32) -> Result { - Ok(match input { - 0 => Channel::Left, - 1 => Channel::Right, - _ => Channel::Aux(input), - }) + fn from_portid(input: u32) -> Self { + Self { + // TODO(strohel): wouldn't it be better to name them all AUX{n}? + short_name: match input { + 0 => "FL".to_string(), + 1 => "FR".to_string(), + _ => format!("AUX{input}"), + }, + } } } @@ -113,8 +97,8 @@ impl Port { path: get_prop(*OBJECT_PATH), node_id: get_prop_or(*NODE_ID)?.parse()?, dsp: get_prop(*FORMAT_DSP), - channel: Channel::from_channel(get_prop(*AUDIO_CHANNEL))? - .unwrap_or(Channel::from_portid(local_port_id)?), + channel: Channel::from_channel(get_prop(*AUDIO_CHANNEL)) + .unwrap_or(Channel::from_portid(local_port_id)), name: get_prop_or(*PORT_NAME)?, direction: Direction::from(get_prop_or(*PORT_DIRECTION)?)?, alias: get_prop_or(*PORT_ALIAS)?,