mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
jack device mutex -> rwlock
This commit is contained in:
parent
52ea78a466
commit
33de8bbf1d
4 changed files with 17 additions and 13 deletions
|
|
@ -5,7 +5,7 @@ pub struct JackDevice {
|
|||
/// The active JACK client of this device.
|
||||
pub client: DynamicAsyncClient,
|
||||
/// The device state, encapsulated for sharing between threads.
|
||||
pub state: Arc<Mutex<Box<dyn Device>>>,
|
||||
pub state: Arc<RwLock<Box<dyn Device>>>,
|
||||
/// Unowned copies of the device's JACK ports, for connecting to the device.
|
||||
/// The "real" readable/writable `Port`s are owned by the `state`.
|
||||
pub ports: UnownedJackPorts,
|
||||
|
|
@ -22,8 +22,12 @@ ports!(JackDevice {
|
|||
});
|
||||
impl JackDevice {
|
||||
/// Returns a locked mutex of the state's contents.
|
||||
pub fn state (&self) -> MutexGuard<Box<dyn Device>> {
|
||||
self.state.lock().unwrap()
|
||||
pub fn state (&self) -> LockResult<RwLockReadGuard<Box<dyn Device>>> {
|
||||
self.state.read()
|
||||
}
|
||||
/// Returns a locked mutex of the state's contents.
|
||||
pub fn state_mut (&self) -> LockResult<RwLockWriteGuard<Box<dyn Device>>> {
|
||||
self.state.write()
|
||||
}
|
||||
pub fn connect_midi_in (&self, index: usize, port: &Port<Unowned>) -> Usually<()> {
|
||||
Ok(self.client.as_client().connect_ports(port, self.midi_ins()?[index])?)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ impl Jack {
|
|||
.map(|p|Ok(p.name()?)).collect::<Usually<Vec<_>>>()?;
|
||||
let audio_ins = owned_ports.audio_ins.values()
|
||||
.map(|p|Ok(p.name()?)).collect::<Usually<Vec<_>>>()?;
|
||||
let state = Arc::new(Mutex::new(state(owned_ports) as Box<dyn Device>));
|
||||
let state = Arc::new(RwLock::new(state(owned_ports) as Box<dyn Device>));
|
||||
let client = self.client.activate_async(
|
||||
Notifications(Box::new({
|
||||
let _state = state.clone();
|
||||
|
|
@ -53,7 +53,7 @@ impl Jack {
|
|||
ClosureProcessHandler::new(Box::new({
|
||||
let state = state.clone();
|
||||
move|c: &Client, s: &ProcessScope|{
|
||||
state.lock().unwrap().process(c, s)
|
||||
state.write().unwrap().process(c, s)
|
||||
}
|
||||
}) as BoxedProcessHandler)
|
||||
)?;
|
||||
|
|
|
|||
|
|
@ -53,17 +53,17 @@ impl Track {
|
|||
device: 0,
|
||||
})
|
||||
}
|
||||
pub fn device (&self) -> Option<MutexGuard<Box<dyn Device>>> {
|
||||
pub fn device (&self) -> Option<RwLockReadGuard<Box<dyn Device>>> {
|
||||
self.get_device(self.device)
|
||||
}
|
||||
pub fn first_device (&self) -> Option<MutexGuard<Box<dyn Device>>> {
|
||||
pub fn first_device (&self) -> Option<RwLockReadGuard<Box<dyn Device>>> {
|
||||
self.get_device(0)
|
||||
}
|
||||
pub fn last_device (&self) -> Option<MutexGuard<Box<dyn Device>>> {
|
||||
pub fn last_device (&self) -> Option<RwLockReadGuard<Box<dyn Device>>> {
|
||||
self.get_device(self.devices.len().saturating_sub(1))
|
||||
}
|
||||
pub fn get_device (&self, i: usize) -> Option<MutexGuard<Box<dyn Device>>> {
|
||||
self.devices.get(i).map(|d|d.state.lock().unwrap())
|
||||
pub fn get_device (&self, i: usize) -> Option<RwLockReadGuard<Box<dyn Device>>> {
|
||||
self.devices.get(i).map(|d|d.state.read().unwrap())
|
||||
}
|
||||
pub fn add_device (&mut self, device: JackDevice) -> Usually<&mut JackDevice> {
|
||||
self.devices.push(device);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ impl<'a> ChainView<'a> {
|
|||
//y2 = y2 + 1;
|
||||
//}
|
||||
let width = width.saturating_sub(x).saturating_sub(x2);
|
||||
let frame = device.state.lock().unwrap()
|
||||
let frame = device.state.read().unwrap()
|
||||
.render(buf, Rect { x: x + x2, y, width, height })?;
|
||||
let style = if i == track.device {
|
||||
Some(if self.focused {
|
||||
|
|
@ -103,12 +103,12 @@ impl<'a> ChainView<'a> {
|
|||
let mut w = 0u16;
|
||||
let mut frames = vec![];
|
||||
let track = self.track.as_ref().unwrap();
|
||||
for (i, device) in track.devices.iter().enumerate() {
|
||||
for (_i, device) in track.devices.iter().enumerate() {
|
||||
//let midi_ins = device.midi_ins()?;
|
||||
//let midi_outs = device.midi_outs()?;
|
||||
//let audio_ins = device.audio_ins()?;
|
||||
//let audio_outs = device.audio_outs()?;
|
||||
let device = device.state.lock().unwrap();
|
||||
let device = device.state.read().unwrap();
|
||||
//let style_midi = Style::default().black().bold().on_green();
|
||||
//let style_audio = Style::default().black().bold().on_red();
|
||||
//y = y + midi_ins.len() as u16;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue