add Gettable, Mutable, InteriorMutable

This commit is contained in:
🪞👃🪞 2024-12-21 00:00:33 +01:00
parent 598319af35
commit 53f786543d
3 changed files with 58 additions and 54 deletions

View file

@ -1,3 +1,5 @@
pub(crate) use std::error::Error;
pub(crate) mod color; pub(crate) use color::*;
pub(crate) mod command; pub(crate) use command::*;
pub(crate) mod engine; pub(crate) use engine::*;
@ -20,3 +22,26 @@ pub use self::{
}
};
}
pub trait Gettable<T> {
fn get (&self) -> T;
}
pub trait Mutable<T>: Gettable<T> {
fn set (&mut self, value: T);
}
pub trait InteriorMutable<T>: Gettable<T> {
fn set (&self, value: T);
}
/// Standard result type.
pub type Usually<T> = Result<T, Box<dyn Error>>;
/// Standard optional result type.
pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
/// Define test modules.
#[macro_export] macro_rules! testmod {
($($name:ident)*) => { $(#[cfg(test)] mod $name;)* };
}

View file

@ -8,29 +8,6 @@ pub mod midi; pub(crate) use self::midi::*;
pub mod audio; pub(crate) use self::audio::*;
//pub mod plugin; pub(crate) use self::plugin::*;
/// Standard result type.
pub type Usually<T> = Result<T, Box<dyn Error>>;
/// Standard optional result type.
pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
/// Define and reexport submodules.
#[macro_export] macro_rules! submod {
($($name:ident)*) => { $(mod $name; pub use self::$name::*;)* };
}
/// Define public modules.
#[macro_export] macro_rules! pubmod {
($($name:ident)*) => { $(pub mod $name;)* };
}
/// Define test modules.
#[macro_export] macro_rules! testmod {
($($name:ident)*) => { $(#[cfg(test)] mod $name;)* };
}
testmod! { test }
pub(crate) use clap::{self, Parser};
pub use ::better_panic;
@ -48,7 +25,6 @@ pub(crate) use std::path::PathBuf;
pub(crate) use std::ffi::OsString;
pub(crate) use std::time::Duration;
pub(crate) use std::io::{Stdout, stdout};
pub(crate) use std::error::Error;
pub(crate) use std::ops::{Add, Sub, Mul, Div, Rem};
pub(crate) use std::cmp::{Ord, Eq, PartialEq};
pub(crate) use std::fmt::{Debug, Display};
@ -80,3 +56,5 @@ pub(crate) use ::palette::{
convert::*,
okhsl::*
};
testmod! { test }

View file

@ -1,6 +1,37 @@
use crate::*;
use KeyCode::{Char, Delete};
#[derive(Debug)] pub struct ArrangerTrack {
/// Name of track
pub(crate) name: Arc<RwLock<String>>,
/// Preferred width of track column
pub(crate) width: usize,
/// Identifying color of track
pub(crate) color: ItemPalette,
/// MIDI player state
pub(crate) player: PhrasePlayerModel,
}
has_clock!(|self:ArrangerTrack|self.player.clock());
has_player!(|self:ArrangerTrack|self.player);
impl ArrangerTrackApi for ArrangerTrack {
/// Name of track
fn name (&self) -> &Arc<RwLock<String>> {
&self.name
}
/// Preferred width of track column
fn width (&self) -> usize {
self.width
}
/// Preferred width of track column
fn width_mut (&mut self) -> &mut usize {
&mut self.width
}
/// Identifying color of track
fn color (&self) -> ItemPalette {
self.color
}
}
pub trait HasTracks<T: ArrangerTrackApi>: Send + Sync {
fn tracks (&self) -> &Vec<T>;
fn tracks_mut (&mut self) -> &mut Vec<T>;
@ -134,33 +165,3 @@ impl ArrangerTracksApi<ArrangerTrack> for ArrangerTui {
}
}
#[derive(Debug)] pub struct ArrangerTrack {
/// Name of track
pub(crate) name: Arc<RwLock<String>>,
/// Preferred width of track column
pub(crate) width: usize,
/// Identifying color of track
pub(crate) color: ItemPalette,
/// MIDI player state
pub(crate) player: PhrasePlayerModel,
}
has_clock!(|self:ArrangerTrack|self.player.clock());
has_player!(|self:ArrangerTrack|self.player);
impl ArrangerTrackApi for ArrangerTrack {
/// Name of track
fn name (&self) -> &Arc<RwLock<String>> {
&self.name
}
/// Preferred width of track column
fn width (&self) -> usize {
self.width
}
/// Preferred width of track column
fn width_mut (&mut self) -> &mut usize {
&mut self.width
}
/// Identifying color of track
fn color (&self) -> ItemPalette {
self.color
}
}