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