Update
This commit is contained in:
parent
5ec5a9a151
commit
e28faaa2ed
@ -10,7 +10,7 @@ use libc::c_int;
|
||||
use libc::c_uint;
|
||||
use libc::pollfd;
|
||||
use libc::size_t;
|
||||
use std::cell::RefCell;
|
||||
use std::cell::Cell;
|
||||
use std::iter::Map;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
@ -30,9 +30,9 @@ pub enum AlsaEvent {
|
||||
pub struct AlsaCard {
|
||||
_cannot_construct: (),
|
||||
pub card: Card,
|
||||
pub mixer: Rc<Mixer>,
|
||||
pub mixer: Mixer,
|
||||
pub selem_id: SelemId,
|
||||
pub watch_ids: RefCell<Vec<u32>>,
|
||||
pub watch_ids: Cell<Vec<u32>>,
|
||||
pub cb: Rc<Fn(AlsaEvent)>,
|
||||
}
|
||||
|
||||
@ -48,8 +48,10 @@ impl AlsaCard {
|
||||
None => get_default_alsa_card(),
|
||||
}
|
||||
};
|
||||
let mixer = Rc::new(get_mixer(&card)?);
|
||||
let mixer2 = mixer.clone();
|
||||
let mixer = get_mixer(&card)?;
|
||||
|
||||
let vec_pollfd = PollDescriptors::get(&mixer)?;
|
||||
|
||||
let selem_id =
|
||||
get_selem_by_name(&mixer,
|
||||
elem_name.unwrap_or(String::from("Master")))
|
||||
@ -61,17 +63,16 @@ impl AlsaCard {
|
||||
card: card,
|
||||
mixer: mixer,
|
||||
selem_id: selem_id,
|
||||
watch_ids: RefCell::new(vec![]),
|
||||
watch_ids: Cell::new(vec![]),
|
||||
cb: cb,
|
||||
});
|
||||
|
||||
let vec_pollfd = PollDescriptors::get(mixer2.as_ref())?;
|
||||
/* TODO: callback is registered here, which must be unregistered
|
||||
* when the card is destroyed!!
|
||||
* poll descriptors must be unwatched too */
|
||||
let watch_ids = AlsaCard::watch_poll_descriptors(vec_pollfd,
|
||||
acard.as_ref());
|
||||
*acard.watch_ids.borrow_mut() = watch_ids;
|
||||
acard.watch_ids.set(watch_ids);
|
||||
|
||||
return Ok(acard);
|
||||
}
|
||||
@ -167,6 +168,7 @@ impl AlsaCard {
|
||||
}
|
||||
|
||||
|
||||
// TODO: test that this is actually triggered when switching cards
|
||||
impl Drop for AlsaCard {
|
||||
// call Box::new(x), transmute the Box into a raw pointer, and then
|
||||
// std::mem::forget
|
||||
@ -182,15 +184,12 @@ impl Drop for AlsaCard {
|
||||
// callback and frees the Box, by simply transmuting the
|
||||
// raw pointer to a Box<T>
|
||||
fn drop(&mut self) {
|
||||
debug!("Destructing watch_ids: {:?}", self.watch_ids);
|
||||
AlsaCard::unwatch_poll_descriptors(&self.watch_ids.borrow());
|
||||
debug!("Destructing watch_ids: {:?}", self.watch_ids.get_mut());
|
||||
AlsaCard::unwatch_poll_descriptors(&self.watch_ids.get_mut());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C" fn watch_cb(chan: *mut glib_sys::GIOChannel,
|
||||
cond: glib_sys::GIOCondition,
|
||||
data: glib_sys::gpointer)
|
||||
|
19
src/audio.rs
19
src/audio.rs
@ -1,5 +1,6 @@
|
||||
use errors::*;
|
||||
use glib;
|
||||
use std::cell::Cell;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::f64;
|
||||
@ -32,7 +33,7 @@ pub struct Audio {
|
||||
pub acard: RefCell<Box<AlsaCard>>,
|
||||
pub last_action_timestamp: RefCell<i64>,
|
||||
pub handlers: Rc<RefCell<Vec<Box<Fn(AudioSignal, AudioUser)>>>>,
|
||||
pub scroll_step: RefCell<u32>,
|
||||
pub scroll_step: Cell<u32>,
|
||||
}
|
||||
|
||||
|
||||
@ -57,7 +58,7 @@ impl Audio {
|
||||
acard: RefCell::new(AlsaCard::new(card_name, elem_name, cb)?),
|
||||
last_action_timestamp: last_action_timestamp.clone(),
|
||||
handlers: handlers.clone(),
|
||||
scroll_step: RefCell::new(5),
|
||||
scroll_step: Cell::new(5),
|
||||
};
|
||||
|
||||
return Ok(audio);
|
||||
@ -68,12 +69,12 @@ impl Audio {
|
||||
card_name: Option<String>,
|
||||
elem_name: Option<String>)
|
||||
-> Result<()> {
|
||||
debug!("Switching cards");
|
||||
let cb = self.acard.borrow().cb.clone();
|
||||
let mut ac = self.acard.borrow_mut();
|
||||
let cb = self.acard
|
||||
.borrow()
|
||||
.cb
|
||||
.clone();
|
||||
*ac = AlsaCard::new(card_name, elem_name, cb)?;
|
||||
*ac = AlsaCard::new(card_name,
|
||||
elem_name,
|
||||
cb)?;
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
@ -102,7 +103,7 @@ impl Audio {
|
||||
*rc = glib::get_monotonic_time();
|
||||
}
|
||||
let old_vol = self.vol()?;
|
||||
let new_vol = f64::ceil(old_vol + (*self.scroll_step.borrow() as f64));
|
||||
let new_vol = f64::ceil(old_vol + (self.scroll_step.get() as f64));
|
||||
|
||||
debug!("Increase vol by {:?} to {:?}", (new_vol - old_vol), new_vol);
|
||||
|
||||
@ -116,7 +117,7 @@ impl Audio {
|
||||
*rc = glib::get_monotonic_time();
|
||||
}
|
||||
let old_vol = self.vol()?;
|
||||
let new_vol = old_vol - (*self.scroll_step.borrow() as f64);
|
||||
let new_vol = old_vol - (self.scroll_step.get() as f64);
|
||||
|
||||
debug!("Decrease vol by {:?} to {:?}", (new_vol - old_vol), new_vol);
|
||||
|
||||
|
@ -43,14 +43,14 @@ use app_state::*;
|
||||
fn main() {
|
||||
gtk::init().unwrap();
|
||||
|
||||
let apps = Rc::new(AppS::new());
|
||||
|
||||
flexi_logger::LogOptions::new()
|
||||
.log_to_file(false)
|
||||
// ... your configuration options go here ...
|
||||
.init(Some("pnmixer=debug".to_string()))
|
||||
.unwrap_or_else(|e| panic!("Logger initialization failed with {}", e));
|
||||
|
||||
let apps = Rc::new(AppS::new());
|
||||
|
||||
ui_entry::init(apps);
|
||||
|
||||
gtk::main();
|
||||
|
Loading…
Reference in New Issue
Block a user