mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 03:36:41 +01:00
353 lines
18 KiB
Rust
353 lines
18 KiB
Rust
use crate::*;
|
|
|
|
pub type Views = Arc<RwLock<BTreeMap<Arc<str>, Arc<str>>>>;
|
|
|
|
impl Draw<TuiOut> for App {
|
|
fn draw (&self, to: &mut TuiOut) {
|
|
for (index, dsl) in self.mode.view.iter().enumerate() {
|
|
if let Err(e) = self.view(to, dsl) {
|
|
panic!("render #{index} failed ({e}): {dsl}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl View<TuiOut, ()> for App {
|
|
fn view_expr <'a> (&'a self, to: &mut TuiOut, expr: &'a impl DslExpr) -> Usually<()> {
|
|
if evaluate_output_expression(self, to, expr)?
|
|
|| evaluate_output_expression_tui(self, to, expr)? {
|
|
Ok(())
|
|
} else {
|
|
Err(format!("App::view_expr: unexpected: {expr:?}").into())
|
|
}
|
|
}
|
|
fn view_word <'a> (&'a self, to: &mut TuiOut, dsl: &'a impl DslExpr) -> Usually<()> {
|
|
let mut frags = dsl.src()?.unwrap().split("/");
|
|
match frags.next() {
|
|
Some(":logo") => to.place(&view_logo()),
|
|
Some(":status") => to.place(&Fixed::Y(1, "TODO: Status Bar")),
|
|
Some(":meters") => match frags.next() {
|
|
Some("input") => to.place(&Tui::bg(Rgb(30, 30, 30), Fill::Y(Align::s("Input Meters")))),
|
|
Some("output") => to.place(&Tui::bg(Rgb(30, 30, 30), Fill::Y(Align::s("Output Meters")))),
|
|
_ => panic!()
|
|
},
|
|
Some(":tracks") => match frags.next() {
|
|
None => to.place(&"TODO tracks"),
|
|
Some("names") => to.place(&self.project.view_track_names(self.color.clone())),//Tui::bg(Rgb(40, 40, 40), Fill::X(Align::w("Track Names")))),
|
|
Some("inputs") => to.place(&Tui::bg(Rgb(40, 40, 40), Fill::X(Align::w("Track Inputs")))),
|
|
Some("devices") => to.place(&Tui::bg(Rgb(40, 40, 40), Fill::X(Align::w("Track Devices")))),
|
|
Some("outputs") => to.place(&Tui::bg(Rgb(40, 40, 40), Fill::X(Align::w("Track Outputs")))),
|
|
_ => panic!()
|
|
},
|
|
Some(":scenes") => match frags.next() {
|
|
None => to.place(&"TODO scenes"),
|
|
Some(":scenes/names") => to.place(&"TODO Scene Names"),
|
|
_ => panic!()
|
|
},
|
|
Some(":editor") => to.place(&"TODO Editor"),
|
|
Some(":dialog") => match frags.next() {
|
|
Some("menu") => to.place(&if let Dialog::Menu(selected, items) = &self.dialog {
|
|
let items = items.clone();
|
|
let selected = selected;
|
|
Some(Fill::XY(Thunk::new(move|to: &mut TuiOut|{
|
|
for (index, MenuItem(item, _)) in items.0.iter().enumerate() {
|
|
to.place(&Push::y((2 * index) as u16,
|
|
Tui::fg_bg(
|
|
if *selected == index { Rgb(240,200,180) } else { Rgb(200, 200, 200) },
|
|
if *selected == index { Rgb(80, 80, 50) } else { Rgb(30, 30, 30) },
|
|
Fixed::Y(2, Align::n(Fill::X(item)))
|
|
)));
|
|
}
|
|
})))
|
|
} else {
|
|
None
|
|
}),
|
|
_ => unimplemented!("App::view_word: {dsl:?} ({frags:?})"),
|
|
},
|
|
Some(":templates") => to.place(&{
|
|
let modes = self.config.modes.clone();
|
|
let height = (modes.read().unwrap().len() * 2) as u16;
|
|
Fixed::Y(height, Min::x(30, Thunk::new(move |to: &mut TuiOut|{
|
|
for (index, (id, profile)) in modes.read().unwrap().iter().enumerate() {
|
|
let bg = if index == 0 { Rgb(70,70,70) } else { Rgb(50,50,50) };
|
|
let name = profile.name.get(0).map(|x|x.as_ref()).unwrap_or("<no name>");
|
|
let info = profile.info.get(0).map(|x|x.as_ref()).unwrap_or("<no info>");
|
|
let fg1 = Rgb(224, 192, 128);
|
|
let fg2 = Rgb(224, 128, 32);
|
|
let field_name = Fill::X(Align::w(Tui::fg(fg1, name)));
|
|
let field_id = Fill::X(Align::e(Tui::fg(fg2, id)));
|
|
let field_info = Fill::X(Align::w(info));
|
|
to.place(&Push::y((2 * index) as u16,
|
|
Fixed::Y(2, Fill::X(Tui::bg(bg, Bsp::s(
|
|
Bsp::a(field_name, field_id), field_info))))));
|
|
}
|
|
})))
|
|
}),
|
|
Some(":sessions") => to.place(&Fixed::Y(6, Min::x(30, Thunk::new(|to: &mut TuiOut|{
|
|
let fg = Rgb(224, 192, 128);
|
|
for (index, name) in ["session1", "session2", "session3"].iter().enumerate() {
|
|
let bg = if index == 0 { Rgb(50,50,50) } else { Rgb(40,40,40) };
|
|
to.place(&Push::y((2 * index) as u16,
|
|
&Fixed::Y(2, Fill::X(Tui::bg(bg, Align::w(Tui::fg(fg, name)))))));
|
|
}
|
|
})))),
|
|
Some(":browse/title") => to.place(&Fill::X(Align::w(FieldV(Default::default(),
|
|
match self.dialog.browser_target().unwrap() {
|
|
BrowseTarget::SaveProject => "Save project:",
|
|
BrowseTarget::LoadProject => "Load project:",
|
|
BrowseTarget::ImportSample(_) => "Import sample:",
|
|
BrowseTarget::ExportSample(_) => "Export sample:",
|
|
BrowseTarget::ImportClip(_) => "Import clip:",
|
|
BrowseTarget::ExportClip(_) => "Export clip:",
|
|
}, Shrink::x(3, Fixed::Y(1, Tui::fg(Tui::g(96), RepeatH("🭻")))))))),
|
|
Some(":device") => {
|
|
let selected = self.dialog.device_kind().unwrap();
|
|
to.place(&Bsp::s(Tui::bold(true, "Add device"), Map::south(1,
|
|
move||device_kinds().iter(),
|
|
move|_label: &&'static str, i|{
|
|
let bg = if i == selected { Rgb(64,128,32) } else { Rgb(0,0,0) };
|
|
let lb = if i == selected { "[ " } else { " " };
|
|
let rb = if i == selected { " ]" } else { " " };
|
|
Fill::X(Tui::bg(bg, Bsp::e(lb, Bsp::w(rb, "FIXME device name")))) })))
|
|
},
|
|
Some(":debug") => to.place(&Fixed::Y(1, format!("[{:?}]", to.area()))),
|
|
Some(_) => {
|
|
let views = self.config.views.read().unwrap();
|
|
if let Some(dsl) = views.get(dsl.src()?.unwrap()) {
|
|
let dsl = dsl.clone();
|
|
std::mem::drop(views);
|
|
self.view(to, &dsl)?
|
|
} else {
|
|
unimplemented!("{dsl:?}");
|
|
}
|
|
},
|
|
_ => unreachable!()
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
fn view_logo () -> impl Content<TuiOut> {
|
|
Fixed::XY(32, 7, Tui::bold(true, Tui::fg(Rgb(240,200,180), col!{
|
|
Fixed::Y(1, ""),
|
|
Fixed::Y(1, ""),
|
|
Fixed::Y(1, "~~ ╓─╥─╖ ╓──╖ ╥ ╖ ~~~~~~~~~~~~"),
|
|
Fixed::Y(1, Bsp::e("~~~~ ║ ~ ╟─╌ ~╟─< ~~ ", Bsp::e(Tui::fg(Rgb(230,100,40), "v0.3.0"), " ~~"))),
|
|
Fixed::Y(1, "~~~~ ╨ ~ ╙──╜ ╨ ╜ ~~~~~~~~~~~~"),
|
|
})))
|
|
}
|
|
|
|
//pub fn view_nil (_: &App) -> TuiCb {
|
|
//|to|to.place(&Fill::XY("·"))
|
|
//}
|
|
|
|
//Bsp::s("",
|
|
//Map::south(1,
|
|
//move||app.config.binds.layers.iter()
|
|
//.filter_map(|a|(a.0)(app).then_some(a.1))
|
|
//.flat_map(|a|a)
|
|
//.filter_map(|x|if let Value::Exp(_, iter)=x.value{ Some(iter) } else { None })
|
|
//.skip(offset)
|
|
//.take(20),
|
|
//|mut b,i|Fixed::x(60, Align::w(Bsp::e("(", Bsp::e(
|
|
//b.next().map(|t|Fixed::x(16, Align::w(Tui::fg(Rgb(64,224,0), format!("{}", t.value))))),
|
|
//Bsp::e(" ", Align::w(format!("{}", b.0.0.trim()))))))))))),
|
|
|
|
//Dialog::Browse(BrowseTarget::Load, browser) => {
|
|
//"bobcat".boxed()
|
|
////Bsp::s(
|
|
////Fill::X(Align::w(Margin::XY(1, 1, Bsp::e(
|
|
////Tui::bold(true, " Load project: "),
|
|
////Shrink::x(3, Fixed::Y(1, RepeatH("🭻"))))))),
|
|
////Outer(true, Style::default().fg(Tui::g(96)))
|
|
////.enclose(Fill::XY(browser)))
|
|
//},
|
|
//Dialog::Browse(BrowseTarget::Export, browser) => {
|
|
//"bobcat".boxed()
|
|
////Bsp::s(
|
|
////Fill::X(Align::w(Margin::XY(1, 1, Bsp::e(
|
|
////Tui::bold(true, " Export: "),
|
|
////Shrink::x(3, Fixed::Y(1, RepeatH("🭻"))))))),
|
|
////Outer(true, Style::default().fg(Tui::g(96)))
|
|
////.enclose(Fill::XY(browser)))
|
|
//},
|
|
//Dialog::Browse(BrowseTarget::Import, browser) => {
|
|
//"bobcat".boxed()
|
|
////Bsp::s(
|
|
////Fill::X(Align::w(Margin::XY(1, 1, Bsp::e(
|
|
////Tui::bold(true, " Import: "),
|
|
////Shrink::x(3, Fixed::Y(1, RepeatH("🭻"))))))),
|
|
////Outer(true, Style::default().fg(Tui::g(96)))
|
|
////.enclose(Fill::XY(browser)))
|
|
//},
|
|
//
|
|
//pub fn view_history (&self) -> impl Content<TuiOut> {
|
|
//Fixed::Y(1, Fill::X(Align::w(FieldH(self.color,
|
|
//format!("History ({})", self.history.len()),
|
|
//self.history.last().map(|last|Fill::X(Align::w(format!("{:?}", last.0))))))))
|
|
//}
|
|
//pub fn view_status_h2 (&self) -> impl Content<TuiOut> {
|
|
//self.update_clock();
|
|
//let theme = self.color;
|
|
//let clock = self.clock();
|
|
//let playing = clock.is_rolling();
|
|
//let cache = clock.view_cache.clone();
|
|
////let selection = self.selection().describe(self.tracks(), self.scenes());
|
|
//let hist_len = self.history.len();
|
|
//let hist_last = self.history.last();
|
|
//Fixed::Y(2, Stack::east(move|add: &mut dyn FnMut(&dyn Draw<TuiOut>)|{
|
|
//add(&Fixed::x(5, Tui::bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) },
|
|
//Either::new(false, // TODO
|
|
//Thunk::new(move||Fixed::x(9, Either::new(playing,
|
|
//Tui::fg(Rgb(0, 255, 0), " PLAYING "),
|
|
//Tui::fg(Rgb(255, 128, 0), " STOPPED ")))
|
|
//),
|
|
//Thunk::new(move||Fixed::x(5, Either::new(playing,
|
|
//Tui::fg(Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)),
|
|
//Tui::fg(Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",))))
|
|
//)
|
|
//)
|
|
//)));
|
|
//add(&" ");
|
|
//{
|
|
//let cache = cache.read().unwrap();
|
|
//add(&Fixed::x(15, Align::w(Bsp::s(
|
|
//FieldH(theme, "Beat", cache.beat.view.clone()),
|
|
//FieldH(theme, "Time", cache.time.view.clone()),
|
|
//))));
|
|
//add(&Fixed::x(13, Align::w(Bsp::s(
|
|
//Fill::X(Align::w(FieldH(theme, "BPM", cache.bpm.view.clone()))),
|
|
//Fill::X(Align::w(FieldH(theme, "SR ", cache.sr.view.clone()))),
|
|
//))));
|
|
//add(&Fixed::x(12, Align::w(Bsp::s(
|
|
//Fill::X(Align::w(FieldH(theme, "Buf", cache.buf.view.clone()))),
|
|
//Fill::X(Align::w(FieldH(theme, "Lat", cache.lat.view.clone()))),
|
|
//))));
|
|
////add(&Bsp::s(
|
|
//////Fill::X(Align::w(FieldH(theme, "Selected", Align::w(selection)))),
|
|
////Fill::X(Align::w(FieldH(theme, format!("History ({})", hist_len),
|
|
////hist_last.map(|last|Fill::X(Align::w(format!("{:?}", last.0))))))),
|
|
////""
|
|
////));
|
|
//////if let Some(last) = self.history.last() {
|
|
//////add(&FieldV(theme, format!("History ({})", self.history.len()),
|
|
//////Fill::X(Align::w(format!("{:?}", last.0)))));
|
|
//////}
|
|
//}
|
|
//}))
|
|
//}
|
|
//pub fn view_status_v (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.update_clock();
|
|
//let cache = self.project.clock.view_cache.read().unwrap();
|
|
//let theme = self.color;
|
|
//let playing = self.clock().is_rolling();
|
|
//Tui::bg(theme.darker.rgb, Fixed::XY(20, 5, Outer(true, Style::default().fg(Tui::g(96))).enclose(
|
|
//col!(
|
|
//Fill::X(Align::w(Bsp::e(
|
|
//Align::w(Tui::bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) },
|
|
//Either::new(false, // TODO
|
|
//Thunk::new(move||Fixed::x(9, Either::new(playing,
|
|
//Tui::fg(Rgb(0, 255, 0), " PLAYING "),
|
|
//Tui::fg(Rgb(255, 128, 0), " STOPPED ")))
|
|
//),
|
|
//Thunk::new(move||Fixed::x(5, Either::new(playing,
|
|
//Tui::fg(Rgb(0, 255, 0), Bsp::s(" 🭍🭑🬽 ", " 🭞🭜🭘 ",)),
|
|
//Tui::fg(Rgb(255, 128, 0), Bsp::s(" ▗▄▖ ", " ▝▀▘ ",))))
|
|
//)
|
|
//)
|
|
//)),
|
|
//Bsp::s(
|
|
//FieldH(theme, "Beat", cache.beat.view.clone()),
|
|
//FieldH(theme, "Time", cache.time.view.clone()),
|
|
//),
|
|
//))),
|
|
//Fill::X(Align::w(FieldH(theme, "BPM", cache.bpm.view.clone()))),
|
|
//Fill::X(Align::w(FieldH(theme, "SR ", cache.sr.view.clone()))),
|
|
//Fill::X(Align::w(FieldH(theme, "Buf", Bsp::e(cache.buf.view.clone(), Bsp::e(" = ", cache.lat.view.clone()))))),
|
|
//))))
|
|
//}
|
|
//pub fn view_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.update_clock();
|
|
//let cache = self.project.clock.view_cache.read().unwrap();
|
|
//view_status(Some(self.project.selection.describe(self.tracks(), self.scenes())),
|
|
//cache.sr.view.clone(), cache.buf.view.clone(), cache.lat.view.clone())
|
|
//}
|
|
//pub fn view_transport (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.update_clock();
|
|
//let cache = self.project.clock.view_cache.read().unwrap();
|
|
//view_transport(self.project.clock.is_rolling(),
|
|
//cache.bpm.view.clone(), cache.beat.view.clone(), cache.time.view.clone())
|
|
//}
|
|
//pub fn view_editor (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//let bg = self.editor()
|
|
//.and_then(|editor|editor.clip().clone())
|
|
//.map(|clip|clip.read().unwrap().color.darker)
|
|
//.unwrap_or(self.color.darker);
|
|
//Fill::XY(Tui::bg(bg.rgb, self.editor()))
|
|
//}
|
|
//pub fn view_editor_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.editor().map(|e|Fixed::x(20, Outer(true, Style::default().fg(Tui::g(96))).enclose(
|
|
//Fill::Y(Align::n(Bsp::s(e.clip_status(), e.edit_status()))))))
|
|
//}
|
|
//pub fn view_midi_ins_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.view_midi_ins_status(self.color)
|
|
//}
|
|
//pub fn view_midi_outs_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.view_midi_outs_status(self.color)
|
|
//}
|
|
//pub fn view_audio_ins_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.view_audio_ins_status(self.color)
|
|
//}
|
|
//pub fn view_audio_outs_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.view_audio_outs_status(self.color)
|
|
//}
|
|
//pub fn view_scenes (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//Bsp::e(
|
|
//Fixed::x(20, Align::nw(self.project.view_scenes_names())),
|
|
//self.project.view_scenes_clips(),
|
|
//)
|
|
//}
|
|
//pub fn view_scenes_names (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.view_scenes_names()
|
|
//}
|
|
//pub fn view_scenes_clips (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.view_scenes_clips()
|
|
//}
|
|
//pub fn view_tracks_inputs <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
|
//Fixed::Y(1 + self.project.midi_ins.len() as u16,
|
|
//self.project.view_inputs(self.color))
|
|
//}
|
|
//pub fn view_tracks_outputs <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
|
//self.project.view_outputs(self.color)
|
|
//}
|
|
//pub fn view_tracks_devices <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
|
//Fixed::Y(4, self.project.view_track_devices(self.color))
|
|
//}
|
|
//pub fn view_tracks_names <'a> (&'a self) -> impl Content<TuiOut> + use<'a> {
|
|
//Fixed::Y(2, self.project.view_track_names(self.color))
|
|
//}
|
|
//pub fn view_pool (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//Fixed::x(20, Bsp::s(
|
|
//Fill::X(Align::w(FieldH(self.color, "Clip pool:", ""))),
|
|
//Fill::Y(Align::n(Tui::bg(Rgb(0, 0, 0), Outer(true, Style::default().fg(Tui::g(96)))
|
|
//.enclose(PoolView(&self.pool)))))))
|
|
//}
|
|
//pub fn view_samples_keys (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.sampler().map(|s|s.view_list(true, self.editor().unwrap()))
|
|
//}
|
|
//pub fn view_samples_grid (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.sampler().map(|s|s.view_grid())
|
|
//}
|
|
//pub fn view_sample_viewer (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.sampler().map(|s|s.view_sample(self.editor().unwrap().get_note_pos()))
|
|
//}
|
|
//pub fn view_sample_info (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.sampler().map(|s|s.view_sample_info(self.editor().unwrap().get_note_pos()))
|
|
//}
|
|
//pub fn view_sample_status (&self) -> impl Content<TuiOut> + use<'_> {
|
|
//self.project.sampler().map(|s|Outer(true, Style::default().fg(Tui::g(96))).enclose(
|
|
//Fill::Y(Align::n(s.view_sample_status(self.editor().unwrap().get_note_pos())))))
|
|
//}
|
|
////let options = ||["Projects", "Settings", "Help", "Quit"].iter();
|
|
////let option = |a,i|Tui::fg(Rgb(255,255,255), format!("{}", a));
|
|
////Bsp::s(Tui::bold(true, "tek!"), Bsp::s("", Map::south(1, options, option)))
|