Created
June 26, 2023 17:44
-
-
Save saivert/97531bdb03da531d189540c94c06e596 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let test = dict.lookup::<HashMap<String, glib::Variant>>("channelVolumes"); | |
| if let Ok(Some(test)) = test { | |
| for (index_str, v) in test.iter() { | |
| let index: u32 = index_str.parse().expect("erroneous index"); | |
| let map: HashMap<String, glib::Variant> = v.get().unwrap(); | |
| let volume = map.get("volume").and_then(|x|x.get::<f64>()); | |
| let channelname = map.get("channel").and_then(|x|x.get::<String>()).unwrap_or_default(); | |
| let channel = t_audiochannel.find_value_from_short_name(&channelname); | |
| if let (Some(c), Some(v)) = (channel, volume) { | |
| wp::log::info!("Index: {index}, Number: {} = {}", c.number(), v); | |
| self.set_channel_volume(index, v as f32); // TODO: get index via channel map, index of vardict must not be relied upon | |
| } else { | |
| wp::log::critical!("Got invalid data via mixer-api"); | |
| } | |
| } | |
| } else { | |
| wp::log::critical!("Cannot get channel volumes via mixer-api"); | |
| } | |
| let result = dict.lookup::<glib::VariantDict>("channelVolumes"); | |
| if let Ok(Some(channel_volumes)) = result { | |
| for v in channel_volumes.to_variant().iter() { | |
| let index_str: String = v.child_get(0); | |
| let index: u32 = index_str.parse().expect("erroneous index"); | |
| if let Ok(Some(v2)) = v.try_child_get::<glib::Variant>(1) { | |
| let dict: glib::VariantDict = v2.into(); | |
| let channelname: Option<String> = dict.lookup("channel").map_or(None, |x|x); | |
| let channel = t_audiochannel.find_value_from_short_name(&channelname.unwrap_or_default()); | |
| let volume: Option<f64> = dict.lookup("volume").map_or(None, |x|x); | |
| if let (Some(c), Some(v)) = (channel, volume) { | |
| wp::log::info!("Index: {index}, Number: {} = {}", c.number(), v); | |
| self.set_channel_volume(index, v as f32); // TODO: get index via channel map, index of vardict must not be relied upon | |
| } else { | |
| wp::log::critical!("Got invalid data via mixer-api"); | |
| } | |
| } | |
| } | |
| } else { | |
| wp::log::critical!("Cannot get channel volumes via mixer-api"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment