Don't invoke alsa functions from the high-level UI code

Instead, call indirection functions from the audio subsystem, so
we don't break module hierarchy.
This commit is contained in:
Julian Ospald 2017-07-15 01:19:10 +02:00
parent bdcf8b0436
commit 0343ec6221
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
3 changed files with 44 additions and 11 deletions

View File

@ -371,6 +371,24 @@ impl Audio {
pub fn connect_handler(&self, cb: Box<Fn(AudioSignal, AudioUser)>) { pub fn connect_handler(&self, cb: Box<Fn(AudioSignal, AudioUser)>) {
self.handlers.add_handler(cb); self.handlers.add_handler(cb);
} }
/// Get the current card name.
pub fn card_name(&self) -> Result<String> {
return self.acard.borrow().card_name();
}
/// Get the currently playable channel names.
pub fn playable_chan_names(&self) -> Vec<String> {
return get_playable_selem_names(&self.acard.borrow().mixer);
}
/// Get the current active channel name.
pub fn chan_name(&self) -> Result<String> {
return self.acard.borrow().chan_name();
}
} }

View File

@ -9,6 +9,7 @@
use audio::{Audio, AudioUser}; use audio::{Audio, AudioUser};
use errors::*; use errors::*;
use prefs::*; use prefs::*;
use support_alsa::*;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
@ -91,3 +92,19 @@ pub fn percent_to_vol(vol: f64, range: (i64, i64), dir: VolDir) -> Result<i64> {
let _v = lrint(vol / 100.0 * ((max - min) as f64), dir) + (min as f64); let _v = lrint(vol / 100.0 * ((max - min) as f64), dir) + (min as f64);
return Ok(_v as i64); return Ok(_v as i64);
} }
/// Get all playable card names.
pub fn get_playable_card_names() -> Vec<String> {
return get_playable_alsa_card_names();
}
/// Get all playable channel names.
pub fn get_playable_chan_names(card_name: String) -> Vec<String> {
let card = try_r!(get_alsa_card_by_name(card_name), Vec::default());
let mixer = try_r!(get_mixer(&card), Vec::default());
return get_playable_selem_names(&mixer);
}

View File

@ -11,7 +11,7 @@ use gtk::prelude::*;
use gtk; use gtk;
use prefs::*; use prefs::*;
use std::rc::Rc; use std::rc::Rc;
use support_alsa::*; use support_audio::*;
@ -374,12 +374,12 @@ fn fill_card_combo(appstate: &AppS) {
let m_cc = appstate.gui.prefs_dialog.borrow(); let m_cc = appstate.gui.prefs_dialog.borrow();
let card_combo = &m_cc.as_ref().unwrap().card_combo; let card_combo = &m_cc.as_ref().unwrap().card_combo;
card_combo.remove_all(); card_combo.remove_all();
let acard = appstate.audio.acard.borrow(); let audio = &appstate.audio;
/* set card combo */ /* set card combo */
let cur_card_name = try_w!(acard.card_name(), let cur_card_name = try_w!(audio.card_name(),
"Can't get current card name!"); "Can't get current card name!");
let available_card_names = get_playable_alsa_card_names(); let available_card_names = get_playable_card_names();
/* set_active_id doesn't work, so save the index */ /* set_active_id doesn't work, so save the index */
let mut c_index: i32 = -1; let mut c_index: i32 = -1;
@ -402,16 +402,14 @@ fn fill_chan_combo(appstate: &AppS, cardname: Option<String>) {
let chan_combo = &m_cc.as_ref().unwrap().chan_combo; let chan_combo = &m_cc.as_ref().unwrap().chan_combo;
chan_combo.remove_all(); chan_combo.remove_all();
let cur_acard = appstate.audio.acard.borrow(); let audio = &appstate.audio;
let card = match cardname { let available_chan_names = match cardname {
Some(name) => try_w!(get_alsa_card_by_name(name).from_err()), Some(name) => get_playable_chan_names(name),
None => cur_acard.as_ref().card, None => audio.playable_chan_names(),
}; };
/* set chan combo */ /* set chan combo */
let cur_chan_name = try_w!(cur_acard.chan_name()); let cur_chan_name = try_w!(audio.chan_name());
let mixer = try_w!(get_mixer(&card));
let available_chan_names = get_playable_selem_names(&mixer);
/* set_active_id doesn't work, so save the index */ /* set_active_id doesn't work, so save the index */
let mut c_index: i32 = -1; let mut c_index: i32 = -1;