mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: preparing to run groovebox from edn
This commit is contained in:
parent
ce4574ed78
commit
a6efde40f8
5 changed files with 43 additions and 28 deletions
|
|
@ -41,14 +41,20 @@ impl<T: PartialEq> PartialEq for EdnItem<T> {
|
|||
impl<T: AsRef<str> + PartialEq + Default + Clone + std::fmt::Debug> EdnItem<T> {
|
||||
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::<Vec<_>>()),
|
||||
}
|
||||
}
|
||||
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> {
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ pub type EdnRenderCallback<'a, Engine, State> =
|
|||
Box<EdnCallback<'a, Engine, State>>;
|
||||
|
||||
pub trait EdnViewData<E: Engine> {
|
||||
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<E: Engine, T: EdnViewData<E> + Send + Sync> Content<E> for EdnView<E, T> {
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -61,11 +61,11 @@ impl Groovebox {
|
|||
|
||||
has_clock!(|self: Groovebox|self.player.clock());
|
||||
|
||||
impl EdnViewData<Tui> for Groovebox {
|
||||
fn get_bool (&self, item: &str) -> bool { todo!() }
|
||||
fn get_unit (&self, item: &str) -> u16 {
|
||||
impl EdnViewData<Tui> 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<Tui> 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])),
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
(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))))))))
|
||||
:midi-view)))))))
|
||||
|
|
|
|||
|
|
@ -4,6 +4,14 @@ use std::marker::ConstParamTy;
|
|||
use tek_engine::Render;
|
||||
use EdnItem::*;
|
||||
|
||||
const EDN: &'static str = include_str!("groovebox.edn");
|
||||
|
||||
//impl Content<Tui> for Groovebox {
|
||||
//fn content (&self) -> impl Render<Tui> {
|
||||
//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(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue