replace impls with edn_command macro invocations

This commit is contained in:
🪞👃🪞 2025-01-12 23:59:06 +01:00
parent 2afae4b6aa
commit 0d7f78e74f

View file

@ -13,19 +13,26 @@ command!(|self: TrackCommand, state: App|match self { _ => todo!("track command"
SetLoop(usize, usize, bool), SetLoop(usize, usize, bool),
SetColor(usize, usize, ItemPalette), SetColor(usize, usize, ItemPalette),
} }
impl EdnCommand<App> for ClipCommand { edn_command!(ClipCommand: |state: App| {
fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self { ("get" [a: usize
match (head, tail) { ,b: usize] Self::Get(a.unwrap(), b.unwrap()))
(Sym("get"), [a, b ]) => Self::Get(0, 0),
(Sym("put"), [a, b, c ]) => Self::Put(0, 0, None), ("put" [a: usize
(Sym("enqueue"), [a, b ]) => Self::Enqueue(0, 0), ,b: usize
(Sym("edit"), [a ]) => Self::Edit(None), ,c: Option<Arc<RwLock<MidiClip>>>] Self::Put(a, b, c))
(Sym("loop"), [a, b, c ]) => Self::SetLoop(0, 0, true),
(Sym("color"), [a, b, c ]) => Self::SetColor(0, 0, ItemPalette::random()), ("enqueue" [a: usize
_ => panic!(), ,b: usize] Self::Enqueue(a, b))
}
} ("edit" [a: Option<Arc<RwLock<MidiClip>>>] Self::Edit(a))
}
("loop" [a: usize
,b: usize
,c: bool] Self::SetLoop(a, b, c))
("color" [a: usize
,b: usize] Self::SetColor(a, b, ItemPalette::random()))
});
#[derive(Clone, Debug)] pub enum SceneCommand { #[derive(Clone, Debug)] pub enum SceneCommand {
Add, Add,
Del(usize), Del(usize),
@ -35,20 +42,14 @@ impl EdnCommand<App> for ClipCommand {
SetColor(usize, ItemPalette), SetColor(usize, ItemPalette),
Enqueue(usize), Enqueue(usize),
} }
impl EdnCommand<App> for SceneCommand { edn_command!(SceneCommand: |state: App| {
fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self { ("add" [] Self::Add)
match (head, tail) { ("del" [a: usize] Self::Del(0))
(Sym("add"), [ ]) => Self::Add, ("zoom" [a: usize] Self::SetZoom(a))
(Sym("del"), [a ]) => Self::Del(0), ("color" [a: usize] Self::SetColor(a, ItemPalette::random()))
(Sym("swap"), [a, b ]) => Self::Swap(0, 0), ("enqueue" [a: usize] Self::Enqueue(a))
(Sym("size"), [a ]) => Self::SetSize(0), ("swap" [a: usize, b: usize] Self::Swap(a, b))
(Sym("zoom"), [a, ]) => Self::SetZoom(0), });
(Sym("color"), [a, b, ]) => Self::SetColor(0, ItemPalette::random()),
(Sym("enqueue"), [a, ]) => Self::Enqueue(0),
_ => panic!(),
}
}
}
#[derive(Clone, Debug)] pub enum TrackCommand { #[derive(Clone, Debug)] pub enum TrackCommand {
Add, Add,
Del(usize), Del(usize),
@ -58,20 +59,15 @@ impl EdnCommand<App> for SceneCommand {
SetZoom(usize), SetZoom(usize),
SetColor(usize, ItemPalette), SetColor(usize, ItemPalette),
} }
impl EdnCommand<App> for TrackCommand { edn_command!(TrackCommand: |state: App| {
fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self { ("add" [] Self::Add)
match (head, tail) { ("size" [a: usize] Self::SetSize(a))
(Sym("add"), [ ]) => Self::Add, ("zoom" [a: usize] Self::SetZoom(a))
(Sym("del"), [a ]) => Self::Del(0), ("color" [a: usize] Self::SetColor(a, ItemPalette::random()))
(Sym("stop"), [a ]) => Self::Stop(0), ("del" [a: usize] Self::Del(a))
(Sym("swap"), [a, b ]) => Self::Swap(0, 0), ("stop" [a: usize] Self::Stop(a))
(Sym("size"), [a ]) => Self::SetSize(0), ("swap" [a: usize, b: usize] Self::Swap(a, b))
(Sym("zoom"), [a, ]) => Self::SetZoom(0), });
(Sym("color"), [a, b, ]) => Self::SetColor(0, ItemPalette::random()),
_ => panic!(),
}
}
}
pub trait Arrangement: HasClock + HasJack { pub trait Arrangement: HasClock + HasJack {
fn tracks (&self) -> &Vec<ArrangerTrack>; fn tracks (&self) -> &Vec<ArrangerTrack>;
fn tracks_mut (&mut self) -> &mut Vec<ArrangerTrack>; fn tracks_mut (&mut self) -> &mut Vec<ArrangerTrack>;