#![feature(type_alias_impl_trait)] //macro_rules! impl_port { //($Name:ident : $Spec:ident -> $Pair:ident |$jack:ident, $name:ident|$port:expr) => { //#[derive(Debug)] pub struct $Name { ///// Handle to JACK client, for receiving reconnect events. //jack: Jack<'static>, ///// Port name //name: Arc, ///// Port handle. //port: Port<$Spec>, ///// List of ports to connect to. //conn: Vec //} //impl AsRef> for $Name { //fn as_ref (&self) -> &Port<$Spec> { &self.port } //} //impl $Name { //pub fn new ($jack: &Jack, name: impl AsRef, connect: &[PortConnect]) //-> Usually //{ //let $name = name.as_ref(); //let jack = $jack.clone(); //let port = $port?; //let name = $name.into(); //let conn = connect.to_vec(); //let port = Self { jack, port, name, conn }; //port.connect_to_matching()?; //Ok(port) //} //pub fn name (&self) -> &Arc { &self.name } //pub fn port (&self) -> &Port<$Spec> { &self.port } //pub fn port_mut (&mut self) -> &mut Port<$Spec> { &mut self.port } //pub fn into_port (self) -> Port<$Spec> { self.port } //pub fn close (self) -> Usually<()> { //let Self { jack, port, .. } = self; //Ok(jack.with_client(|client|client.unregister_port(port))?) //} //} //impl HasJack<'static> for $Name { //fn jack (&self) -> &'static Jack<'static> { &self.jack } //} //impl JackPort<'static> for $Name { //type Port = $Spec; //type Pair = $Pair; //fn port (&self) -> &Port<$Spec> { &self.port } //} //impl ConnectTo<'static, &str> for $Name { //fn connect_to (&self, to: &str) -> Usually { //self.with_client(|c|if let Some(ref port) = c.port_by_name(to.as_ref()) { //self.connect_to(port) //} else { //Ok(Missing) //}) //} //} //impl ConnectTo<'static, &Port> for $Name { //fn connect_to (&self, port: &Port) -> Usually { //self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) { //Connected //} else if let Ok(_) = c.connect_ports(port, &self.port) { //Connected //} else { //Mismatch //})) //} //} //impl ConnectTo<'static, &Port<$Pair>> for $Name { //fn connect_to (&self, port: &Port<$Pair>) -> Usually { //self.with_client(|c|Ok(if let Ok(_) = c.connect_ports(&self.port, port) { //Connected //} else if let Ok(_) = c.connect_ports(port, &self.port) { //Connected //} else { //Mismatch //})) //} //} //impl ConnectAuto<'static> for $Name { //fn connections (&self) -> &[PortConnect] { //&self.conn //} //} //}; //} mod time; pub use self::time::*; mod note; pub use self::note::*; pub mod jack; pub use self::jack::*; pub mod midi; pub use self::midi::*; pub(crate) use std::sync::{Arc, RwLock, atomic::{AtomicUsize, AtomicBool, Ordering::Relaxed}}; pub(crate) use std::fmt::Debug; pub(crate) use std::ops::{Add, Sub, Mul, Div, Rem}; pub(crate) use ::tengri::{from, Usually, Perhaps, Has, has, maybe_has, tui::*, dsl::*}; pub use ::atomic_float; pub(crate) use atomic_float::*; //pub trait MaybeHas: Send + Sync { //fn get (&self) -> Option<&T>; //} //impl>> MaybeHas for U { //fn get (&self) -> Option<&T> { //Has::>::get(self).as_ref() //} //} #[macro_export] macro_rules! as_ref { ($T:ty: |$self:ident : $S:ty| $x:expr) => { impl AsRef<$T> for $S { fn as_ref (&$self) -> &$T { &$x } } }; } pub trait HasN: Send + Sync { fn get_nth (&self, key: usize) -> &T; fn get_nth_mut (&mut self, key: usize) -> &mut T; } pub trait Gettable { /// Returns current value fn get (&self) -> T; } pub trait Mutable: Gettable { /// Sets new value, returns old fn set (&mut self, value: T) -> T; } pub trait InteriorMutable: Gettable { /// Sets new value, returns old fn set (&self, value: T) -> T; } impl Gettable for AtomicBool { fn get (&self) -> bool { self.load(Relaxed) } } impl InteriorMutable for AtomicBool { fn set (&self, value: bool) -> bool { self.swap(value, Relaxed) } } impl Gettable for AtomicUsize { fn get (&self) -> usize { self.load(Relaxed) } } impl InteriorMutable for AtomicUsize { fn set (&self, value: usize) -> usize { self.swap(value, Relaxed) } } #[cfg(test)] #[test] fn test_time () -> Usually<()> { // TODO! Ok(()) } #[cfg(test)] #[test] fn test_midi_range () { let model = MidiRangeModel::from((1, false)); let _ = model.get_time_len(); let _ = model.get_time_zoom(); let _ = model.get_time_lock(); let _ = model.get_time_start(); let _ = model.get_time_axis(); let _ = model.get_time_end(); let _ = model.get_note_lo(); let _ = model.get_note_axis(); let _ = model.get_note_hi(); }