diff --git a/edn/src/edn_item.rs b/edn/src/edn_item.rs index d766f08f..831df995 100644 --- a/edn/src/edn_item.rs +++ b/edn/src/edn_item.rs @@ -41,14 +41,20 @@ impl PartialEq for EdnItem { impl + PartialEq + Default + Clone + std::fmt::Debug> EdnItem { pub fn to_ref (&self) -> EdnItem<&str> { match self { + Self::Nil => EdnItem::Nil, + Self::Num(x) => EdnItem::Num(*x), Self::Key(x) => EdnItem::Key(x.as_ref()), - _ => todo!() + Self::Sym(x) => EdnItem::Sym(x.as_ref()), + Self::Exp(x) => EdnItem::Exp(x.iter().map(|x|x.to_ref()).collect::>()), } } pub fn to_str (&self) -> &str { match self { + Self::Nil => "", + Self::Num(_) => "", Self::Key(x) => x.as_ref(), - _ => todo!() + Self::Sym(x) => x.as_ref(), + Self::Exp(_) => "", } } pub fn symbols <'a> (&'a self) -> EdnIterator<'a, T> { diff --git a/edn/src/edn_view.rs b/edn/src/edn_view.rs index cf9d91b6..93d9f71c 100644 --- a/edn/src/edn_view.rs +++ b/edn/src/edn_view.rs @@ -10,10 +10,10 @@ pub type EdnRenderCallback<'a, Engine, State> = Box>; pub trait EdnViewData { - fn get_bool (&self, _sym: &str) -> bool { false } - fn get_unit (&self, _sym: &str) -> E::Unit { 0.into() } - fn get_usize (&self, _sym: &str) -> usize { 0 } - fn get_content <'a> (&'a self, _sym: &'a str) -> RenderBox<'a, E> { Box::new(()) } + fn get_bool (&self, _sym: EdnItem<&str>) -> bool { false } + fn get_unit (&self, _sym: EdnItem<&str>) -> E::Unit { 0.into() } + fn get_usize (&self, _sym: EdnItem<&str>) -> usize { 0 } + fn get_content <'a> (&'a self, _sym: EdnItem<&str>) -> RenderBox<'a, E> { Box::new(()) } } /// Renders from EDN source and context. @@ -36,18 +36,15 @@ impl + Send + Sync> Content for EdnView { use EdnItem::*; match &self.layout { Nil => ().boxed(), - Sym(t) => self.context.get_content(t.as_str()).boxed(), + Sym(t) => self.context.get_content(Sym(t.as_str())).boxed(), Key(t) => panic!("todo: add error handling to content() chain. unexpected key {t}"), Num(n) => panic!("todo: add error handling to content() chain. unexpected num {n}"), Exp(e) => if let [head, tail @ ..] = e.as_slice() { let head = &head.to_ref(); + let state = &self.context; match (head, tail) { - (Key("when"), [Sym(c), Sym(a)]) => When( - self.context.get_bool(c.as_str()), - self.context.get_content(a.as_str())).boxed(), - (Key("bsp/s"), [Sym(a), Sym(b)]) => Bsp::s( - self.context.get_content(a.as_str()), - self.context.get_content(b.as_str())).boxed(), + (Key("when"), [c, a]) => When(state.get_bool(c.to_ref()), state.get_content(a.to_ref())).boxed(), + (Key("bsp/s"), [a, b]) => Bsp::s(state.get_content(a.to_ref()), state.get_content(b.to_ref()),).boxed(), _ => todo!("{:?} {:?}", &head, &tail) } } else { diff --git a/src/groovebox.rs b/src/groovebox.rs index ce865ae6..887bdbef 100644 --- a/src/groovebox.rs +++ b/src/groovebox.rs @@ -61,11 +61,11 @@ impl Groovebox { has_clock!(|self: Groovebox|self.player.clock()); -impl EdnViewData for Groovebox { - fn get_bool (&self, item: &str) -> bool { todo!() } - fn get_unit (&self, item: &str) -> u16 { +impl EdnViewData for &Groovebox { + fn get_bool (&self, item: EdnItem<&str>) -> bool { todo!() } + fn get_unit (&self, item: EdnItem<&str>) -> u16 { use EdnItem::*; - match item { + match item.to_str() { ":sample-h" => if self.compact { 0 } else { 5 }, ":samples-w" => if self.compact { 4 } else { 11 }, ":samples-y" => if self.compact { 1 } else { 0 }, @@ -76,9 +76,9 @@ impl EdnViewData for Groovebox { _ => 0 } } - fn get_content <'a> (&'a self, item: &str) -> RenderBox<'a, Tui> { + fn get_content <'a> (&'a self, item: EdnItem<&str>) -> RenderBox<'a, Tui> { use EdnItem::*; - match item { + match item.to_str() { ":input-meter-l" => Box::new(Meter("L/", self.sampler.input_meter[0])), ":input-meter-r" => Box::new(Meter("R/", self.sampler.input_meter[1])), diff --git a/src/groovebox/groovebox.edn b/src/groovebox/groovebox.edn index afca85a5..3682005a 100644 --- a/src/groovebox/groovebox.edn +++ b/src/groovebox/groovebox.edn @@ -1,12 +1,16 @@ -(sized - (bsp/s (fill/x (fixed/y 2 (lay +(bsp/s + (fill/x (fixed/y 2 (lay (align/w :input-meter-l) (align/e :input-meter-r) (align/x :transport)))) - (bsp/n (row :clip-play :clip-next :clip-edit :edit-stat) - (bsp/n (max/y :sample-h (fill/xy :sample-view)) - (bsp/n (align/w (fixed/y 1 :sample-stat)) - (bsp/n (fixed/x :pool-w :pool-view) - (fill/xy (bsp/e - (fixed/x :samples-w (push/y :samples-y :samples-view)) - :midi-view)))))))) + (bsp/n + (row :clip-play :clip-next :clip-edit :edit-stat) + (bsp/n + (max/y :sample-h (fill/xy :sample-view)) + (bsp/n + (align/w (fixed/y 1 :sample-stat)) + (bsp/n + (fixed/x :pool-w :pool-view) + (fill/xy (bsp/e + (fixed/x :samples-w (push/y :samples-y :samples-view)) + :midi-view))))))) diff --git a/src/groovebox/groovebox_tui.rs b/src/groovebox/groovebox_tui.rs index 333a1e46..9f29c86a 100644 --- a/src/groovebox/groovebox_tui.rs +++ b/src/groovebox/groovebox_tui.rs @@ -4,6 +4,14 @@ use std::marker::ConstParamTy; use tek_engine::Render; use EdnItem::*; +const EDN: &'static str = include_str!("groovebox.edn"); + +//impl Content for Groovebox { + //fn content (&self) -> impl Render { + //self.size.of(EdnView::new(self, EDN).expect("failed to build view")) + //} +//} + render!(Tui: (self: Groovebox) => self.size.of( Bsp::s(self.toolbar_view(), Bsp::n(self.selector_view(),