From 0d7f78e74fa31b5d9f7c87be7abdac0899e2cfb9 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sun, 12 Jan 2025 23:59:06 +0100 Subject: [PATCH] replace impls with edn_command macro invocations --- tek/src/arranger.rs | 78 +++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/tek/src/arranger.rs b/tek/src/arranger.rs index b83736a6..2ec16aae 100644 --- a/tek/src/arranger.rs +++ b/tek/src/arranger.rs @@ -13,19 +13,26 @@ command!(|self: TrackCommand, state: App|match self { _ => todo!("track command" SetLoop(usize, usize, bool), SetColor(usize, usize, ItemPalette), } -impl EdnCommand for ClipCommand { - fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem]) -> Self { - match (head, tail) { - (Sym("get"), [a, b ]) => Self::Get(0, 0), - (Sym("put"), [a, b, c ]) => Self::Put(0, 0, None), - (Sym("enqueue"), [a, b ]) => Self::Enqueue(0, 0), - (Sym("edit"), [a ]) => Self::Edit(None), - (Sym("loop"), [a, b, c ]) => Self::SetLoop(0, 0, true), - (Sym("color"), [a, b, c ]) => Self::SetColor(0, 0, ItemPalette::random()), - _ => panic!(), - } - } -} +edn_command!(ClipCommand: |state: App| { + ("get" [a: usize + ,b: usize] Self::Get(a.unwrap(), b.unwrap())) + + ("put" [a: usize + ,b: usize + ,c: Option>>] Self::Put(a, b, c)) + + ("enqueue" [a: usize + ,b: usize] Self::Enqueue(a, b)) + + ("edit" [a: Option>>] 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 { Add, Del(usize), @@ -35,20 +42,14 @@ impl EdnCommand for ClipCommand { SetColor(usize, ItemPalette), Enqueue(usize), } -impl EdnCommand for SceneCommand { - fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem]) -> Self { - match (head, tail) { - (Sym("add"), [ ]) => Self::Add, - (Sym("del"), [a ]) => Self::Del(0), - (Sym("swap"), [a, b ]) => Self::Swap(0, 0), - (Sym("size"), [a ]) => Self::SetSize(0), - (Sym("zoom"), [a, ]) => Self::SetZoom(0), - (Sym("color"), [a, b, ]) => Self::SetColor(0, ItemPalette::random()), - (Sym("enqueue"), [a, ]) => Self::Enqueue(0), - _ => panic!(), - } - } -} +edn_command!(SceneCommand: |state: App| { + ("add" [] Self::Add) + ("del" [a: usize] Self::Del(0)) + ("zoom" [a: usize] Self::SetZoom(a)) + ("color" [a: usize] Self::SetColor(a, ItemPalette::random())) + ("enqueue" [a: usize] Self::Enqueue(a)) + ("swap" [a: usize, b: usize] Self::Swap(a, b)) +}); #[derive(Clone, Debug)] pub enum TrackCommand { Add, Del(usize), @@ -58,20 +59,15 @@ impl EdnCommand for SceneCommand { SetZoom(usize), SetColor(usize, ItemPalette), } -impl EdnCommand for TrackCommand { - fn from_edn <'a> (state: &App, head: &EdnItem<&str>, tail: &'a [EdnItem]) -> Self { - match (head, tail) { - (Sym("add"), [ ]) => Self::Add, - (Sym("del"), [a ]) => Self::Del(0), - (Sym("stop"), [a ]) => Self::Stop(0), - (Sym("swap"), [a, b ]) => Self::Swap(0, 0), - (Sym("size"), [a ]) => Self::SetSize(0), - (Sym("zoom"), [a, ]) => Self::SetZoom(0), - (Sym("color"), [a, b, ]) => Self::SetColor(0, ItemPalette::random()), - _ => panic!(), - } - } -} +edn_command!(TrackCommand: |state: App| { + ("add" [] Self::Add) + ("size" [a: usize] Self::SetSize(a)) + ("zoom" [a: usize] Self::SetZoom(a)) + ("color" [a: usize] Self::SetColor(a, ItemPalette::random())) + ("del" [a: usize] Self::Del(a)) + ("stop" [a: usize] Self::Stop(a)) + ("swap" [a: usize, b: usize] Self::Swap(a, b)) +}); pub trait Arrangement: HasClock + HasJack { fn tracks (&self) -> &Vec; fn tracks_mut (&mut self) -> &mut Vec;