diff --git a/src/backend/paramavailability.rs b/src/backend/paramavailability.rs index 72c4e76..549f8b3 100644 --- a/src/backend/paramavailability.rs +++ b/src/backend/paramavailability.rs @@ -1,3 +1,5 @@ +use wireplumber::spa::SpaPod; + #[derive(Debug, Copy, Clone, PartialEq, Eq, glib::Enum, Default)] #[enum_type(name = "ProfileAvailability")] pub enum ParamAvailability { @@ -16,3 +18,10 @@ impl From for ParamAvailability { } } } + + +impl<'a> From<&'a SpaPod> for ParamAvailability { + fn from(value: &'a SpaPod) -> Self { + value.id().map_or(ParamAvailability::Unknown, |x| x.into()) + } +} diff --git a/src/backend/pwdeviceobject.rs b/src/backend/pwdeviceobject.rs index 3750f89..da5872c 100644 --- a/src/backend/pwdeviceobject.rs +++ b/src/backend/pwdeviceobject.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later -use crate::backend::PwProfileObject; +use crate::backend::{ParamAvailability, PwProfileObject}; use glib::{ self, clone, subclass::{prelude::*, Signal}, @@ -170,10 +170,6 @@ impl PwDeviceObject { None, gtk::gio::Cancellable::NONE, clone!(@weak self as widget => move |res| { - let keys = wp::spa::SpaIdTable::from_name("Spa:Pod:Object:Param:Profile").expect("id table"); - let index_key = keys.find_value_from_short_name("index").expect("index key"); - let description_key = keys.find_value_from_short_name("description").expect("decription key"); - let available_key = keys.find_value_from_short_name("available").expect("available key"); if let Ok(Some(iter)) = res { let mut profiles: Vec = Vec::new(); @@ -184,9 +180,9 @@ impl PwDeviceObject { continue; } - let index = pod.find_spa_property(&index_key).expect("Index!").int().expect("Int"); - let description = pod.find_spa_property(&description_key).expect("Format!").string().expect("String"); - let available = pod.find_spa_property(&available_key).expect("Availability!").id().expect("Id"); + let index: i32 = pod.spa_property(&wp::spa::ffi::SPA_PARAM_PROFILE_index).expect("Profile index"); + let description: String = pod.spa_property(&wp::spa::ffi::SPA_PARAM_PROFILE_description).expect("Profile description"); + let available = pod.find_spa_property(&wp::spa::ffi::SPA_PARAM_PROFILE_available).expect("Profile availability").id().expect("Id"); profiles.push(PwProfileObject::new(index as u32, &description, available)); } @@ -203,10 +199,6 @@ impl PwDeviceObject { pub(crate) fn update_current_profile_index(&self) { let device = self.wpdevice(); - let keys = wp::spa::SpaIdTable::from_name("Spa:Pod:Object:Param:Profile").expect("id table"); - let index_key = keys.find_value_from_short_name("index").expect("index key"); - let description_key = keys.find_value_from_short_name("description").expect("decription key"); - if let Some(params) = device.enum_params_sync("Profile", None) { for a in params { let pod: wp::spa::SpaPod = a.get().unwrap(); @@ -214,8 +206,8 @@ impl PwDeviceObject { continue; } - let index = pod.find_spa_property(&index_key).expect("Index!").int().expect("Int"); - let description = pod.find_spa_property(&description_key).expect("Format!").string().expect("String"); + let index: i32 = pod.spa_property(&wp::spa::ffi::SPA_PARAM_PROFILE_index).expect("Profile index"); + let description: String = pod.spa_property(&wp::spa::ffi::SPA_PARAM_PROFILE_description).expect("Profile description"); pwvucontrol_info!("Current profile #{} {}", index, description); self.set_profile_index(index as u32); @@ -244,12 +236,6 @@ impl PwDeviceObject { None, gtk::gio::Cancellable::NONE, clone!(@weak self as widget => move |res| { - let keys = wp::spa::SpaIdTable::from_name("Spa:Pod:Object:Param:Route").expect("id table"); - let index_key = keys.find_value_from_short_name("index").expect("index key"); - let description_key = keys.find_value_from_short_name("description").expect("decription key"); - let available_key = keys.find_value_from_short_name("available").expect("available key"); - let direction_key = keys.find_value_from_short_name("direction").expect("direction key"); - let profiles_key = keys.find_value_from_short_name("profiles").expect("profiles key"); if let Ok(Some(iter)) = res { let removed = widget.imp().routemodel.n_items(); @@ -262,11 +248,11 @@ impl PwDeviceObject { continue; } - let index = pod.find_spa_property(&index_key).expect("Index").int().expect("Int"); - let description = pod.find_spa_property(&description_key).expect("Format!").string().expect("String"); - let available = pod.find_spa_property(&available_key).expect("Availability!").id().expect("Id"); - let direction = pod.find_spa_property(&direction_key).expect("Direction!").id().expect("Id"); - let profiles = pod.find_spa_property(&profiles_key).expect("Profiles!"); + let index: i32 = pod.spa_property(&wp::spa::ffi::SPA_PARAM_ROUTE_index).expect("Route index"); + let description: String = pod.spa_property(&wp::spa::ffi::SPA_PARAM_ROUTE_description).expect("Route description"); + let direction: RouteDirection = pod.spa_property(&wp::spa::ffi::SPA_PARAM_ROUTE_direction).expect("Route direction"); + let available: ParamAvailability = pod.spa_property(&wp::spa::ffi::SPA_PARAM_ROUTE_available).expect("Route available"); + let profiles = pod.find_spa_property(&wp::spa::ffi::SPA_PARAM_ROUTE_profiles).expect("Profiles!"); assert!(profiles.is_array()); let profiles_vec: Vec = profiles.array_iterator::().map(|x| x as u32).collect(); diff --git a/src/backend/pwnodeobject.rs b/src/backend/pwnodeobject.rs index b0d2458..812244c 100644 --- a/src/backend/pwnodeobject.rs +++ b/src/backend/pwnodeobject.rs @@ -353,11 +353,6 @@ impl PwNodeObject { node.enum_params(Some("Format"), None, gtk::gio::Cancellable::NONE, clone!(@weak self as widget, @weak node => move |res| { if let Ok(Some(iter)) = res { - let keys = wp::spa::SpaIdTable::from_name("Spa:Pod:Object:Param:Format").expect("id table"); - let channels_key = keys.find_value_from_short_name("channels").expect("channels key"); - let rate_key = keys.find_value_from_short_name("rate").expect("channels key"); - let format_key = keys.find_value_from_short_name("format").expect("format key"); - let position_key = keys.find_value_from_short_name("position").expect("position key"); for a in iter { let pod: wp::spa::SpaPod = a.get().unwrap(); @@ -373,24 +368,24 @@ impl PwNodeObject { } } - let choice = pod.find_spa_property(&format_key).expect("Format!"); + let choice = pod.find_spa_property(&wp::spa::ffi::SPA_FORMAT_AUDIO_format).expect("Format!"); let format = get_pod_maybe_choice(choice).id().expect("Format id"); if format == 0 { pwvucontrol_warning!("Format is 0, ignoring..."); return; } - let channels = match pod.find_spa_property(&channels_key) { + let channels = match pod.find_spa_property(&wp::spa::ffi::SPA_FORMAT_AUDIO_channels) { Some(pod) => get_pod_maybe_choice(pod).int().expect("Channels int"), None => 0 }; - let rate = match pod.find_spa_property(&rate_key) { + let rate = match pod.find_spa_property(&wp::spa::ffi::SPA_FORMAT_AUDIO_rate) { Some(pod) => get_pod_maybe_choice(pod).int().expect("Rate int"), None => 0 }; - let choice = pod.find_spa_property(&position_key).expect("Position!"); + let choice = pod.find_spa_property(&wp::spa::ffi::SPA_FORMAT_AUDIO_position).expect("Position!"); let positionpod = get_pod_maybe_choice(choice); let vec: Vec = positionpod.array_iterator().map(|x: i32| x as u32).collect(); let mut a = [0u32;64]; @@ -424,20 +419,16 @@ impl PwNodeObject { .enum_params_sync("Props", None) .expect("getting params"); - let keys = wp::spa::SpaIdTable::from_name("Spa:Pod:Object:Param:Props").expect("id table"); - let volume_key = keys.find_value_from_short_name("volume").expect("volume key"); - let monitorvolumes_key = keys.find_value_from_short_name("monitorVolumes").expect("monitorVolumes key"); - for a in params { let pod: wp::spa::SpaPod = a.get().unwrap(); if pod.is_object() { - if let Some(val) = pod.find_spa_property(&volume_key) { + if let Some(val) = pod.find_spa_property(&wp::spa::ffi::SPA_PROP_volume) { if let Some(volume) = val.float() { self.set_mainvolume(volume); } } - if let Some(val) = pod.find_spa_property(&monitorvolumes_key) { + if let Some(val) = pod.find_spa_property(&wp::spa::ffi::SPA_PROP_monitorVolumes) { if val.is_array() { let volume = val.array_iterator::().max_by(f32::total_cmp); self.set_monitorvolume(volume.unwrap_or_default()); diff --git a/src/backend/pwrouteobject.rs b/src/backend/pwrouteobject.rs index 68d0496..76316b2 100644 --- a/src/backend/pwrouteobject.rs +++ b/src/backend/pwrouteobject.rs @@ -46,12 +46,12 @@ glib::wrapper! { } impl PwRouteObject { - pub(crate) fn new(index: u32, description: &str, availability: u32, direction: u32, profiles: &[u32]) -> Self { + pub(crate) fn new(index: u32, description: &str, availability: ParamAvailability, direction: RouteDirection, profiles: &[u32]) -> Self { let new: PwRouteObject = glib::Object::builder() .property("index", index) .property("description", format!("{description} ({index})")) - .property("availability", ParamAvailability::from(availability)) - .property("direction", RouteDirection::from(direction)) + .property("availability", availability) + .property("direction", direction) .build(); new.set_profiles(profiles); diff --git a/src/backend/routedirection.rs b/src/backend/routedirection.rs index 12c77fb..b42bc65 100644 --- a/src/backend/routedirection.rs +++ b/src/backend/routedirection.rs @@ -1,3 +1,5 @@ +use wireplumber::spa::SpaPod; + #[derive(Debug, Copy, Clone, PartialEq, Eq, glib::Enum, Default)] #[enum_type(name = "RouteDirection")] pub enum RouteDirection { @@ -17,6 +19,12 @@ impl From for RouteDirection { } } +impl<'a> From<&'a SpaPod> for RouteDirection { + fn from(value: &'a SpaPod) -> Self { + value.id().map_or(RouteDirection::Unknown, |x| x.into()) + } +} + impl From for u32 { fn from(value: RouteDirection) -> Self { value as u32