Compare commits

..

No commits in common. "3dada45ea923c82611fabd65b0b4e7142e15e2df" and "50728729b7378d9c50c6a7c3769b5cc435801243" have entirely different histories.

6 changed files with 120 additions and 121 deletions

View file

@ -109,64 +109,83 @@ impl Config {
return Err(format!("{path}: not found").into()) return Err(format!("{path}: not found").into())
}) })
} }
pub fn load_defs (&mut self, dsl: impl Dsl) -> Usually<()> { pub fn load_defs <D: Dsl> (&mut self, dsl: D) -> Usually<()> {
dsl.each(|item|{ dsl.each(|item|{
println!("{item:?}"); println!("{item:?}");
match item.exp().head() { Ok(match item.exp().head() {
Ok(Some("keys")) if let Some(id) = item.exp().tail().head()? => Ok(Some("keys")) if let Some(id) = item.exp().tail().head()? => {
self.load_bind(id.into(), item), self.binds.write().unwrap().insert(id.into(), {
Ok(Some("mode")) if let Some(id) = item.exp().tail().head()? => let mut map = EventMap::new();
self.load_mode(id.into(), item), item.exp().tail().tail()?.each(|item|Ok({
_ => return Err(format!("load_defs: unexpected: {item:?}").into()) if let Ok(Some(sym)) = item.exp().head().sym() {
} map.add(TuiEvent::from_dsl(item.exp()?.head()?)?, Binding {
}) command: item.exp()?.tail()?.unwrap_or_default().into(),
} condition: None,
pub fn load_bind (&mut self, id: Arc<str>, item: impl Dsl) -> Usually<()> { description: None,
let mut map = EventMap::new(); source: None
item.exp().tail().tail()?.each(|item|Self::load_bind_one(&mut map, item))?; });
self.binds.write().unwrap().insert(id, map); } else if item.exp().head() == Ok(Some("see")) {
Ok(()) // TODO
} } else {
fn load_bind_one (map: &mut EventMap<Option<TuiEvent>, Arc<str>>, item: impl Dsl) -> Usually<()> { return Err(format!("load_defs: unexpected: {item:?}").into())
if let Ok(Some(sym)) = item.exp().head().sym() { }
map.add(TuiEvent::from_dsl(item.exp()?.head()?)?, Binding { }))?;
command: item.exp()?.tail()?.unwrap_or_default().into(), map
condition: None, });
description: None,
source: None
});
} else if item.exp().head() == Ok(Some("see")) {
// TODO
} else {
return Err(format!("load_defs: unexpected: {item:?}").into())
}
Ok(())
}
pub fn load_mode (&mut self, id: Arc<str>, item: impl Dsl) -> Usually<()> {
let mut mode = Mode::default();
item.exp().tail().tail()?.each(|item|Self::load_mode_one(&mut mode, item))?;
self.modes.write().unwrap().insert(id.into(), Arc::new(mode));
Ok(())
}
pub fn load_mode_one (mode: &mut Mode<Arc<str>>, item: impl Dsl) -> Usually<()> {
Ok(if let Ok(Some(key)) = item.exp().head() {
match key {
"name" => mode.name.push(item.exp()?.tail()?.map(|x|x.trim()).unwrap_or("").into()),
"info" => mode.info.push(item.exp()?.tail()?.map(|x|x.trim()).unwrap_or("").into()),
"keys" => mode.keys.push(item.exp()?.tail()?.map(|x|x.trim()).unwrap_or("").into()),
"mode" => if let Some(id) = item.exp()?.tail()?.head()? {
let mut submode = Mode::default();
Self::load_mode_one(&mut submode, item.exp()?.tail()?.tail()?)?;
mode.modes.insert(id.into(), submode);
} else {
return Err(format!("load_mode_one: incomplete: {item:?}").into());
}, },
_ => mode.view.push(item.exp()?.unwrap().into()), Ok(Some("mode")) if let Some(id) = item.exp().tail().head()? => {
} self.modes.write().unwrap().insert(id.into(), {
} else if let Ok(Some(sym)) = item.sym() { let mut mode = Mode::default();
mode.view.push(sym.into()); item.exp().tail().tail()?.each(|item|Ok(if let Ok(Some(exp)) = item.exp() {
} else { match exp.head()? {
return Err(format!("load_mode_one: unexpected: {item:?}").into()); Some("name") => mode.name.push(
exp.tail()?.map(|x|x.trim()).unwrap_or("").into()
),
Some("info") => mode.info.push(
exp.tail()?.map(|x|x.trim()).unwrap_or("").into()
),
Some("keys") => if let Some(tail) = exp.tail()? {
tail.each(|keys|Ok(mode.keys.push(keys.trim().into())))?;
} else {
return Err(format!("load_view: empty keys: {exp}").into())
},
Some("mode") => if let (Some(name), Some(tail)) = (
exp.tail()?.head()?, exp.tail()?.tail()?,
) {
let mut submode: Mode<Arc<str>> = Default::default();
tail.each(|item|Ok(if let Ok(Some(exp)) = item.exp() {
match exp.head()? {
Some("keys") => if let Some(tail) = exp.tail()? {
tail.each(|keys|Ok(mode.keys.push(keys.trim().into())))?;
} else {
return Err(format!("load_view: empty keys: {exp}").into())
},
_ => {
return Err(format!("load_view: unexpected in mode {name}: {item:?}").into())
}
}
} else if let Ok(Some(sym)) = item.sym() {
// TODO
} else {
return Err(format!("load_view: unexpected in mode {name}: {item:?}").into())
}))?;
mode.modes.insert(name.trim().into(), submode);
} else {
return Err(format!("load_view: empty mode: {exp}").into())
},
Some(_) => mode.view.push(exp.into()),
None => return Err(format!("load_view: empty: {exp}").into())
}
} else if let Ok(Some(sym)) = item.sym() {
mode.view.push(sym.into());
} else {
return Err(format!("load_view: unexpected: {dsl:?}").into())
}))?;
mode.into()
});
},
_ => return Err(format!("load_defs: unexpected: {item:?}").into())
})
}) })
} }
} }

View file

@ -1,4 +1,6 @@
use crate::*; use crate::*;
#[derive(Debug)]
pub enum AppCommand {}
handle!(TuiIn:|self: App, input|{ handle!(TuiIn:|self: App, input|{
panic!("wat: {:?}", self.mode); panic!("wat: {:?}", self.mode);
for keys in self.mode.keys.iter() { for keys in self.mode.keys.iter() {
@ -89,9 +91,6 @@ dsl_sym!(|app: App| -> Option<Arc<RwLock<MidiClip>>> {
None None
} }
}); });
#[derive(Debug)]
pub enum AppCommand {
}
dsl_exp!(|app: App| -> AppCommand { dsl_exp!(|app: App| -> AppCommand {
["stop-all"] => app.project.stop_all(), ["stop-all"] => app.project.stop_all(),
["enqueue", clip?: Option<Arc<RwLock<MidiClip>>>] => todo!(), ["enqueue", clip?: Option<Arc<RwLock<MidiClip>>>] => todo!(),

View file

@ -5,10 +5,10 @@ pub struct DslNs<'t, T: 't>(pub &'t [(&'t str, T)]);
/// Namespace where keys are symbols. /// Namespace where keys are symbols.
pub trait DslSymNs<'t, T: 't>: 't { pub trait DslSymNs<'t, T: 't>: 't {
const SYMS: DslNs<'t, fn (&'t Self)->T>; const NS: DslNs<'t, fn (&'t Self)->T>;
fn from_sym <D: Dsl> (&'t self, dsl: D) -> Usually<T> { fn from_sym <D: Dsl> (&'t self, dsl: D) -> Usually<T> {
if let Some(dsl) = dsl.sym()? { if let Some(dsl) = dsl.sym()? {
for (sym, get) in Self::SYMS.0 { for (sym, get) in Self::NS.0 {
if dsl == *sym { if dsl == *sym {
return Ok(get(self)) return Ok(get(self))
} }
@ -21,22 +21,19 @@ pub trait DslSymNs<'t, T: 't>: 't {
#[macro_export] macro_rules! dsl_sym ( #[macro_export] macro_rules! dsl_sym (
(|$state:ident:$State:ty| -> $type:ty {$($lit:literal => $exp:expr),* $(,)?})=>{ (|$state:ident:$State:ty| -> $type:ty {$($lit:literal => $exp:expr),* $(,)?})=>{
impl<'t> DslSymNs<'t, $type> for $State { impl<'t> DslSymNs<'t, $type> for $State {
const SYMS: DslNs<'t, fn (&'t $State)->$type> = const NS: DslNs<'t, fn (&'t $State)->$type> =
DslNs(&[$(($lit, |$state: &$State|$exp)),*]); } }); DslNs(&[$(($lit, |$state: &$State|$exp)),*]); } });
pub trait DslExpNs<'t, T: 't>: 't { pub trait DslExpNs<'t, T: 't>: 't { const NS: DslNs<'t, fn (&'t Self, &str)->T>; }
const EXPS: DslNs<'t, fn (&'t Self, &str)->T>;
}
#[macro_export] macro_rules! dsl_exp ( #[macro_export] macro_rules! dsl_exp (
(|$state:ident:$State:ty|->$type:ty { $( (|$state:ident:$State:ty|->$type:ty { $(
[$key:literal $(/ $sub:ident: $Sub:ty)? $(, $arg:ident $(?)? :$argtype:ty)*] => $body:expr [$key:literal $(/ $sub:ident: $Sub:ty)? $(, $arg:ident $(?)? :$argtype:ty)*] => $body:expr
),* $(,)? }) => { ),* $(,)? }) => {
impl<'t> DslExpNs<'t, $type> for $State { impl<'t> DslExpNs<'t, $type> for $State {
const EXPS: DslNs<'t, fn (&'t $State, &str)->$type> = const NS: DslNs<'t, fn (&'t $State, &str)->$type> =
DslNs(&[]); } }); DslNs(&[]); } });
pub type DslCb = fn (&App) -> Box<dyn Render<TuiOut>>; pub type DslCb = fn (&App) -> Box<dyn Render<TuiOut>>;
impl<'t, D: Dsl> std::ops::Index<D> for DslNs<'t, DslCb> { impl<'t, D: Dsl> std::ops::Index<D> for DslNs<'t, DslCb> {
type Output = DslCb; type Output = DslCb;
fn index (&self, index: D) -> &Self::Output { fn index (&self, index: D) -> &Self::Output {
@ -50,7 +47,6 @@ impl<'t, D: Dsl> std::ops::Index<D> for DslNs<'t, DslCb> {
&(view_nil as DslCb) &(view_nil as DslCb)
} }
} }
fn view_nil (_: &App) -> Box<dyn Render<TuiOut>> {
pub fn view_nil (_: &App) -> Box<dyn Render<TuiOut>> {
Box::new(Fill::xy("·")) Box::new(Fill::xy("·"))
} }

View file

@ -1,37 +1,22 @@
use crate::*; use crate::*;
content!(TuiOut:|self: App|Stack::above(|add|{ content!(TuiOut:|self: App|VIEW[":view"](self));//if let Ok(Some(view)) = VIEW[":view"] { view(self) } else { panic!() });
for dsl in self.mode.view.iter() { add(&self.view(dsl.as_ref())); } pub const VIEW: DslNs<'static, DslCb> = DslNs(&[
})); (":view", |state|VIEW[":view/menu"](state)),
impl App { (":view/menu", |state|{
fn view <D: Dsl> (&self, index: D) -> Box<dyn Render<TuiOut>> { let selected = state.dialog.menu_selected();
if let Ok(Some(symbol)) = index.src() { let outputs = VIEW[":view/ports/outs"](state);
for (key, value) in Self::SYMS.0.iter() { let inputs = VIEW[":view/ports/ins"](state);
if symbol == *key {
return value(self)
}
}
}
view_nil(self)
}
}
dsl_sym!(|app: App| -> Box<dyn Render<TuiOut>> {
":view" => app.view(":view/menu"),
":view/menu" => {
let selected = app.dialog.menu_selected();
let outputs = app.view(":view/ports/outs");
let inputs = app.view(":view/ports/ins");
Box::new(Tui::bg(Rgb(0,0,0), Bsp::s(outputs, Bsp::s( Box::new(Tui::bg(Rgb(0,0,0), Bsp::s(outputs, Bsp::s(
Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Tui::bold(true, "tek 0.3.0-rc0")))), Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Tui::bold(true, "tek 0.3.0-rc0")))),
Bsp::n(inputs, Bsp::n( Bsp::n(inputs, Bsp::n(
Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Bsp::e(Tui::fg(Rgb(255,192,48), "[Enter]"), " new session")))), Fill::x(Fixed::y(3, Tui::bg(Rgb(33,33,33), Bsp::e(Tui::fg(Rgb(255,192,48), "[Enter]"), " new session")))),
Fill::y(Align::n(Fill::x(app.view(":view/profiles")))))))))) Fill::y(Align::n(Fill::x(VIEW[":view/profiles"](state)))))))))) }),
}, (":view/ports/outs", |state|Box::new(Fill::x(Fixed::y(3,
":view/ports/outs" => Box::new(Fill::x(Fixed::y(3, Bsp::a(Fill::x(Align::w(" L AUDIO OUTS")), Bsp::a("MIDI OUT", Fill::x(Align::e("AUDIO OUTS R ")))))))),
Bsp::a(Fill::x(Align::w(" L AUDIO OUTS")), Bsp::a("MIDI OUT", Fill::x(Align::e("AUDIO OUTS R "))))))), (":view/ports/ins", |state|Box::new(Fill::x(Fixed::y(3,
":view/ports/ins" => Box::new(Fill::x(Fixed::y(3, Bsp::a(Fill::x(Align::w(" L AUDIO INS")), Bsp::a("MIDI INS", Fill::x(Align::e("AUDIO INS R ")))))))),
Bsp::a(Fill::x(Align::w(" L AUDIO ISYMS")), Bsp::a("MIDI ISYMS", Fill::x(Align::e("AUDIO ISYMS R "))))))), (":view/profiles", |state: &App|Box::new({
":view/profiles" => Box::new({ let modes = state.config.modes.clone();
let modes = app.config.modes.clone();
Stack::south(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{ Stack::south(move|add: &mut dyn FnMut(&dyn Render<TuiOut>)|{
for (index, (id, profile)) in modes.read().unwrap().iter().enumerate() { for (index, (id, profile)) in modes.read().unwrap().iter().enumerate() {
let bg = if index == 0 { Rgb(64,64,64) } else { Rgb(32,32,32) }; let bg = if index == 0 { Rgb(64,64,64) } else { Rgb(32,32,32) };
@ -41,33 +26,34 @@ dsl_sym!(|app: App| -> Box<dyn Render<TuiOut>> {
Fill::x(Bsp::a( Fill::x(Bsp::a(
Fill::x(Align::w(Tui::fg(Rgb(224,192,128), name))), Fill::x(Align::w(Tui::fg(Rgb(224,192,128), name))),
Fill::x(Align::e(Tui::fg(Rgb(224,128,32), &id))))), Fill::x(Align::e(Tui::fg(Rgb(224,128,32), &id))))),
Fill::x(Align::w(info)))))); } })}), Fill::x(Align::w(info)))))); } })})),
":view/browse" => { (":view/browse", |state: &App|{
let browser = app.dialog.browser().cloned().unwrap(); let browser = state.dialog.browser().cloned().unwrap();
Box::new(Bsp::s(Padding::xy(3, 1, app.view(":view/browse-title")), Box::new(Bsp::s(
Outer(true, Style::default().fg(Tui::g(96))) Padding::xy(3, 1, VIEW[":view/browse-title"](state)),
.enclose(Fill::xy(browser)))) }, Outer(true, Style::default().fg(Tui::g(96)))
":view/browse/title" => { .enclose(Fill::xy(browser)))) }),
let target = app.dialog.browser_target().unwrap(); (":view/browse-title", |state: &App|{
Box::new(Fill::x(Align::w(FieldV(Default::default(), match target { let target = state.dialog.browser_target().unwrap();
BrowserTarget::SaveProject => "Save project:", Box::new(Fill::x(Align::w(FieldV(Default::default(), match target {
BrowserTarget::LoadProject => "Load project:", BrowserTarget::SaveProject => "Save project:",
BrowserTarget::ImportSample(_) => "Import sample:", BrowserTarget::LoadProject => "Load project:",
BrowserTarget::ExportSample(_) => "Export sample:", BrowserTarget::ImportSample(_) => "Import sample:",
BrowserTarget::ImportClip(_) => "Import clip:", BrowserTarget::ExportSample(_) => "Export sample:",
BrowserTarget::ExportClip(_) => "Export clip:", BrowserTarget::ImportClip(_) => "Import clip:",
}, Shrink::x(3, Fixed::y(1, Tui::fg(Tui::g(96), RepeatH("🭻"))))))))}, BrowserTarget::ExportClip(_) => "Export clip:",
":view/device" => { }, Shrink::x(3, Fixed::y(1, Tui::fg(Tui::g(96), RepeatH("🭻"))))))))}),
let selected = app.dialog.device_kind().unwrap(); (":view/device", |state: &App|{
let selected = state.dialog.device_kind().unwrap();
Box::new(Bsp::s(Tui::bold(true, "Add device"), Map::south(1, Box::new(Bsp::s(Tui::bold(true, "Add device"), Map::south(1,
move||device_kinds().iter(), move||device_kinds().iter(),
move|label: &&'static str, i|{ move|label: &&'static str, i|{
let bg = if i == selected { Rgb(64,128,32) } else { Rgb(0,0,0) }; let bg = if i == selected { Rgb(64,128,32) } else { Rgb(0,0,0) };
let lb = if i == selected { "[ " } else { " " }; let lb = if i == selected { "[ " } else { " " };
let rb = if i == selected { " ]" } else { " " }; let rb = if i == selected { " ]" } else { " " };
Fill::x(Tui::bg(bg, Bsp::e(lb, Bsp::w(rb, "FIXME device name")))) }))) }, Fill::x(Tui::bg(bg, Bsp::e(lb, Bsp::w(rb, "FIXME device name")))) }))) }),
//(":view/options", view_options), //(":view/options", view_options),
}); ]);
fn wrap_dialog (dialog: impl Content<TuiOut>) -> impl Content<TuiOut> { fn wrap_dialog (dialog: impl Content<TuiOut>) -> impl Content<TuiOut> {
Fixed::xy(70, 23, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b( Fixed::xy(70, 23, Tui::fg_bg(Rgb(255,255,255), Rgb(16,16,16), Bsp::b(
Repeat(" "), Outer(true, Style::default().fg(Tui::g(96))).enclose(dialog)))) Repeat(" "), Outer(true, Style::default().fg(Tui::g(96))).enclose(dialog))))
@ -86,8 +72,8 @@ impl ScenesView for App {
//Bsp::s("", //Bsp::s("",
//Map::south(1, //Map::south(1,
//move||app.config.binds.layers.iter() //move||state.config.binds.layers.iter()
//.filter_map(|a|(a.0)(app).then_some(a.1)) //.filter_map(|a|(a.0)(state).then_some(a.1))
//.flat_map(|a|a) //.flat_map(|a|a)
//.filter_map(|x|if let Value::Exp(_, iter)=x.value{ Some(iter) } else { None }) //.filter_map(|x|if let Value::Exp(_, iter)=x.value{ Some(iter) } else { None })
//.skip(offset) //.skip(offset)

View file

@ -79,7 +79,6 @@ impl Cli {
config, config,
color: ItemTheme::random(), color: ItemTheme::random(),
dialog: Dialog::Menu(0), dialog: Dialog::Menu(0),
mode: Mode { view: vec![":view/menu".into()], ..Default::default() },
project: Arrangement { project: Arrangement {
name: Default::default(), name: Default::default(),
color: ItemTheme::random(), color: ItemTheme::random(),

2
deps/tengri vendored

@ -1 +1 @@
Subproject commit ab1afa219f520138ff1a089de4223e52298b1d0e Subproject commit 7fd6c91643cbcfece56ebc14500c6a1ab775fc9e