mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
turn Plugin keymap to match statement
This commit is contained in:
parent
cd8a808c21
commit
39407c9760
8 changed files with 124 additions and 129 deletions
|
|
@ -25,15 +25,15 @@ pub trait Ports {
|
|||
}
|
||||
|
||||
/// A UI component that may be associated with a JACK client by the `Jack` factory.
|
||||
pub trait Device<E: Engine>: Component<E> + Audio {
|
||||
pub trait AudioComponent<E: Engine>: Component<E> + Audio {
|
||||
/// Perform type erasure for collecting heterogeneous devices.
|
||||
fn boxed (self) -> Box<dyn Device<E>> where Self: Sized + 'static {
|
||||
fn boxed (self) -> Box<dyn AudioComponent<E>> where Self: Sized + 'static {
|
||||
Box::new(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// All things that implement the required traits can be treated as `Device`.
|
||||
impl<E: Engine, W: Component<E> + Audio> Device<E> for W {}
|
||||
/// All things that implement the required traits can be treated as `AudioComponent`.
|
||||
impl<E: Engine, W: Component<E> + Audio> AudioComponent<E> for W {}
|
||||
|
||||
/// Wraps [Client] or [DynamicAsyncClient] in place.
|
||||
pub enum JackClient {
|
||||
|
|
@ -112,7 +112,7 @@ pub fn jack_run <T, E: Engine> (name: &str, app: &Arc<RwLock<T>>) -> Usually<Dyn
|
|||
}
|
||||
|
||||
/// `JackDevice` factory. Creates JACK `Client`s, performs port registration
|
||||
/// and activation, and encapsulates a `Device` into a `JackDevice`.
|
||||
/// and activation, and encapsulates a `AudioComponent` into a `JackDevice`.
|
||||
pub struct Jack {
|
||||
pub client: Client,
|
||||
pub midi_ins: Vec<String>,
|
||||
|
|
@ -137,7 +137,7 @@ impl Jack {
|
|||
pub fn run <'a: 'static, D, E> (
|
||||
self, state: impl FnOnce(JackPorts)->Box<D>
|
||||
) -> Usually<JackDevice<E>>
|
||||
where D: Device<E> + Sized + 'static,
|
||||
where D: AudioComponent<E> + Sized + 'static,
|
||||
E: Engine + 'static,
|
||||
{
|
||||
let owned_ports = JackPorts {
|
||||
|
|
@ -154,7 +154,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(RwLock::new(state(owned_ports) as Box<dyn Device<E>>));
|
||||
let state = Arc::new(RwLock::new(state(owned_ports) as Box<dyn AudioComponent<E>>));
|
||||
let client = self.client.activate_async(
|
||||
Notifications(Box::new({
|
||||
let _state = state.clone();
|
||||
|
|
@ -288,12 +288,12 @@ impl<T: Fn(JackEvent) + Send> NotificationHandler for Notifications<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// A [Device] bound to a JACK client and a set of ports.
|
||||
/// A [AudioComponent] bound to a JACK client and a set of ports.
|
||||
pub struct JackDevice<E: Engine> {
|
||||
/// The active JACK client of this device.
|
||||
pub client: DynamicAsyncClient,
|
||||
/// The device state, encapsulated for sharing between threads.
|
||||
pub state: Arc<RwLock<Box<dyn Device<E>>>>,
|
||||
pub state: Arc<RwLock<Box<dyn AudioComponent<E>>>>,
|
||||
/// 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,
|
||||
|
|
@ -338,11 +338,11 @@ impl<E: Engine> Ports for JackDevice<E> {
|
|||
|
||||
impl<E: Engine> JackDevice<E> {
|
||||
/// Returns a locked mutex of the state's contents.
|
||||
pub fn state (&self) -> LockResult<RwLockReadGuard<Box<dyn Device<E>>>> {
|
||||
pub fn state (&self) -> LockResult<RwLockReadGuard<Box<dyn AudioComponent<E>>>> {
|
||||
self.state.read()
|
||||
}
|
||||
/// Returns a locked mutex of the state's contents.
|
||||
pub fn state_mut (&self) -> LockResult<RwLockWriteGuard<Box<dyn Device<E>>>> {
|
||||
pub fn state_mut (&self) -> LockResult<RwLockWriteGuard<Box<dyn AudioComponent<E>>>> {
|
||||
self.state.write()
|
||||
}
|
||||
pub fn connect_midi_in (&self, index: usize, port: &Port<Unowned>) -> Usually<()> {
|
||||
|
|
|
|||
|
|
@ -31,9 +31,6 @@ pub struct FillBg(pub Color);
|
|||
|
||||
impl Widget for FillBg {
|
||||
type Engine = Tui;
|
||||
fn layout (&self, area: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
Ok(Some(area))
|
||||
}
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
to.fill_bg(to.area(), self.0);
|
||||
Ok(Some(to.area))
|
||||
|
|
|
|||
|
|
@ -59,12 +59,8 @@ where
|
|||
{
|
||||
type Engine = Tui;
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
let area = to.area();
|
||||
to.blit(&format!("L1 {area:?}"), 10, 10, None)?;
|
||||
let area = self.layout(to.area())?;
|
||||
to.blit(&format!("L2 {area:?}"), 10, 11, None)?;
|
||||
area.map(|area|(self.0)(&mut |layer| {
|
||||
to.blit(&format!("L3 {area:?}"), 10, 12, None)?;
|
||||
self.layout(to.area())?
|
||||
.map(|area|(self.0)(&mut |layer| {
|
||||
to.render_in(area, &layer)?;
|
||||
Ok(())
|
||||
}).map(|_|area))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue