trait Run

This commit is contained in:
🪞👃🪞 2024-07-02 22:25:33 +03:00
parent cc2b59d772
commit 3ae2467acc
11 changed files with 212 additions and 141 deletions

View file

@ -25,65 +25,3 @@ pub enum AppEvent {
/// JACK notification
Jack(JackEvent)
}
#[derive(Debug)]
pub enum JackEvent {
ThreadInit,
Shutdown(ClientStatus, String),
Freewheel(bool),
SampleRate(Frames),
ClientRegistration(String, bool),
PortRegistration(PortId, bool),
PortRename(PortId, String, String),
PortsConnected(PortId, PortId, bool),
GraphReorder,
XRun,
}
pub struct Notifications<T: Fn(AppEvent) + Send>(pub T);
impl<T: Fn(AppEvent) + Send> NotificationHandler for Notifications<T> {
fn thread_init (&self, _: &Client) {
self.0(AppEvent::Jack(JackEvent::ThreadInit));
}
fn shutdown (&mut self, status: ClientStatus, reason: &str) {
self.0(AppEvent::Jack(JackEvent::Shutdown(status, reason.into())));
}
fn freewheel (&mut self, _: &Client, enabled: bool) {
self.0(AppEvent::Jack(JackEvent::Freewheel(enabled)));
}
fn sample_rate (&mut self, _: &Client, frames: Frames) -> Control {
self.0(AppEvent::Jack(JackEvent::SampleRate(frames)));
Control::Quit
}
fn client_registration (&mut self, _: &Client, name: &str, reg: bool) {
self.0(AppEvent::Jack(JackEvent::ClientRegistration(name.into(), reg)));
}
fn port_registration (&mut self, _: &Client, id: PortId, reg: bool) {
self.0(AppEvent::Jack(JackEvent::PortRegistration(id, reg)));
}
fn port_rename (&mut self, _: &Client, id: PortId, old: &str, new: &str) -> Control {
self.0(AppEvent::Jack(JackEvent::PortRename(id, old.into(), new.into())));
Control::Continue
}
fn ports_connected (&mut self, _: &Client, a: PortId, b: PortId, are: bool) {
self.0(AppEvent::Jack(JackEvent::PortsConnected(a, b, are)));
}
fn graph_reorder (&mut self, _: &Client) -> Control {
self.0(AppEvent::Jack(JackEvent::GraphReorder));
Control::Continue
}
fn xrun (&mut self, _: &Client) -> Control {
self.0(AppEvent::Jack(JackEvent::XRun));
Control::Continue
}
}