diff --git a/src/app.rs b/src/app.rs index 85d60d81..93c3d74a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -59,7 +59,7 @@ impl App { /// Create a new application instance from a backend, project, config, and mode /// /// ``` - /// let jack = tek::tengri::sing::Jack::new(&"test_tek").expect("failed to connect to jack"); + /// let jack = tek::tengri::Jack::new(&"test_tek").expect("failed to connect to jack"); /// let proj = tek::Arrangement::default(); /// let mut conf = tek::Config::default(); /// conf.add("(mode hello)"); diff --git a/src/app/bind.rs b/src/app/bind.rs index a1814ace..01628e03 100644 --- a/src/app/bind.rs +++ b/src/app/bind.rs @@ -50,7 +50,7 @@ pub(crate) fn load_bind (binds: &Binds, name: &impl AsRef, body: &impl Lang /// /// ``` /// let lang = "(@x (nop)) (@y (nop) (nop))"; -/// let bind = tek::Bind::>::load(&lang).unwrap(); +/// let bind = tek::Bind::>::load(&lang).unwrap(); /// assert_eq!(bind.query(&'x'.into()).map(|x|x.len()), Some(1)); /// //assert_eq!(bind.query(&'y'.into()).map(|x|x.len()), Some(2)); /// ``` diff --git a/src/app/draw.rs b/src/app/draw.rs index 35bc6697..dd161ce0 100644 --- a/src/app/draw.rs +++ b/src/app/draw.rs @@ -10,7 +10,7 @@ impl View for App { thunk(|to: &mut Tui|{ let xywh = to.area().into(); if let Some(e) = self.error.read().unwrap().as_ref() { - to.show(Layout::XYWH(xywh, e.as_ref()))?; + to.show(area(xywh, e.as_ref()))?; } for (index, dsl) in self.mode.view.iter().enumerate() { if let Err(e) = self.interpret(to, dsl) { @@ -18,39 +18,31 @@ impl View for App { break; } } - Ok(xywh) + Ok(Some(xywh)) }) } } -impl Interpret> for App { - fn interpret_expr <'a> (&'a self, to: &mut Tui, lang: &'a impl Expression) - -> Usually> - { +impl Interpret>> for App { + fn interpret_expr <'a> (&'a self, to: &mut Tui, lang: &'a impl Expression) -> Drawn { tek_draw_expr(self, to, lang) } - fn interpret_word <'a> (&'a self, to: &mut Tui, lang: &'a impl Expression) - -> Usually> - { + fn interpret_word <'a> (&'a self, to: &mut Tui, lang: &'a impl Expression) -> Drawn { tek_draw_word(self, to, lang) } } -fn tek_draw_expr (state: &App, to: &mut Tui, lang: &impl Expression) - -> Usually> -{ - if let Some(area) = eval_view(state, to, lang)? { - Ok(area) +fn tek_draw_expr (state: &App, to: &mut Tui, lang: &impl Expression) -> Drawn { + Ok(Some(if let Some(area) = eval_view(state, to, lang)? { + area } else if let Some(area) = eval_view_tui(state, to, lang)? { - Ok(area) + area } else { - Err(format!("App::interpret_expr: unexpected: {lang:?}").into()) - } + return Err(format!("App::interpret_expr: unexpected: {lang:?}").into()) + })) } -fn tek_draw_word (state: &App, to: &mut Tui, dsl: &impl Expression) - -> Usually> -{ +fn tek_draw_word (state: &App, to: &mut Tui, dsl: &impl Expression) -> Drawn { let mut frags = dsl.src()?.unwrap().split("/"); match frags.next() { Some(":logo") => view_logo().draw(to), @@ -79,32 +71,26 @@ fn tek_draw_word (state: &App, to: &mut Tui, dsl: &impl Expression) } } -pub fn draw_meter_section (to: &mut Tui, mut frags: std::str::Split<&str>) - -> Usually> -{ +pub fn draw_meter_section (to: &mut Tui, mut frags: std::str::Split<&str>) -> Drawn { match frags.next() { - Some("input") => bg(Rgb(30, 30, 30), h_full(origin_s("Input Meters"))).draw(to), - Some("output") => bg(Rgb(30, 30, 30), h_full(origin_s("Output Meters"))).draw(to), + Some("input") => bg(Rgb(30, 30, 30), h_full(align_s("Input Meters"))).draw(to), + Some("output") => bg(Rgb(30, 30, 30), h_full(align_s("Output Meters"))).draw(to), _ => panic!() } } -pub fn draw_tracks (to: &mut Tui, mut frags: std::str::Split<&str>, state: &App) - -> Usually> -{ +pub fn draw_tracks (to: &mut Tui, mut frags: std::str::Split<&str>, state: &App) -> Drawn { match frags.next() { None => "TODO tracks".draw(to), - Some("names") => state.project.view_track_names(state.color.clone()).draw(to),//bg(Rgb(40, 40, 40), w_full(origin_w("Track Names")))), - Some("inputs") => bg(Rgb(40, 40, 40), w_full(origin_w("Track Inputs"))).draw(to), - Some("devices") => bg(Rgb(40, 40, 40), w_full(origin_w("Track Devices"))).draw(to), - Some("outputs") => bg(Rgb(40, 40, 40), w_full(origin_w("Track Outputs"))).draw(to), + Some("names") => state.project.view_track_names(state.color.clone()).draw(to),//bg(Rgb(40, 40, 40), w_full(align_w("Track Names")))), + Some("inputs") => bg(Rgb(40, 40, 40), w_full(align_w("Track Inputs"))).draw(to), + Some("devices") => bg(Rgb(40, 40, 40), w_full(align_w("Track Devices"))).draw(to), + Some("outputs") => bg(Rgb(40, 40, 40), w_full(align_w("Track Outputs"))).draw(to), _ => panic!() } } -pub fn draw_scenes (to: &mut Tui, mut frags: std::str::Split<&str>) - -> Usually> -{ +pub fn draw_scenes (to: &mut Tui, mut frags: std::str::Split<&str>) -> Drawn { match frags.next() { None => "TODO Scenes".draw(to), Some(":scenes/names") => "TODO Scene Names".draw(to), @@ -113,8 +99,7 @@ pub fn draw_scenes (to: &mut Tui, mut frags: std::str::Split<&str>) } pub fn draw_dialog ( - to: &mut Tui, mut frags: std::str::Split<&str>, state: &App, dsl: &impl Expression -) -> Usually> { + to: &mut Tui, mut frags: std::str::Split<&str>, state: &App, dsl: &impl Expression) -> Drawn { match frags.next() { Some("menu") => if let Dialog::Menu(selected, items) = &state.dialog { let items = items.clone(); @@ -124,10 +109,10 @@ pub fn draw_dialog ( y_push((2 * index) as u16,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) }, - h_exact(2, origin_n(w_full(item))) + h_exact(2, align_n(w_full(item))) )).draw(to)?; } - Ok(to.area().into()) + Ok(Some(to.area().into())) }))) } else { None @@ -136,9 +121,7 @@ pub fn draw_dialog ( } } -pub fn draw_templates (to: &mut Tui, frags: std::str::Split<&str>, state: &App) - -> Usually> -{ +pub fn draw_templates (to: &mut Tui, frags: std::str::Split<&str>, state: &App) -> Drawn { let height = (state.config.modes.len() * 2) as u16; h_exact(height, w_min(Some(30), thunk(move |to: &mut Tui|{ let mut index = 0; @@ -148,9 +131,9 @@ pub fn draw_templates (to: &mut Tui, frags: std::str::Split<&str>, state: &App) let info = profile.info.get(0).map(|x|x.as_ref()).unwrap_or(""); let fg1 = Rgb(224, 192, 128); let fg2 = Rgb(224, 128, 32); - let field_name = w_full(origin_w(fg(fg1, name))); - let field_id = w_full(origin_e(fg(fg2, id))); - let field_info = w_full(origin_w(info)); + let field_name = w_full(align_w(fg(fg1, name))); + let field_id = w_full(align_e(fg(fg2, id))); + let field_info = w_full(align_w(info)); let _ = y_push((2 * index) as u16, h_exact(2, w_full(bg(b, south( above(field_name, field_id), @@ -158,7 +141,7 @@ pub fn draw_templates (to: &mut Tui, frags: std::str::Split<&str>, state: &App) ))))).draw(to); index += 1; }); - Ok(to.area().into()) + Ok(Some(to.area().into())) }))).draw(to) } @@ -183,8 +166,8 @@ pub fn view_logo () -> impl Draw { pub fn view_transport (play: bool, bpm: &str, beat: &str, time: &str) -> impl Draw { let theme = ItemTheme::G[96]; bg(Black, east!(above( - wh_full(origin_w(button_play_pause(play, false))), - wh_full(origin_e(east!( + wh_full(align_w(button_play_pause(play, false))), + wh_full(align_e(east!( field_h(theme, "BPM", bpm), field_h(theme, "Beat", beat), field_h(theme, "Time", time), @@ -203,8 +186,8 @@ pub fn view_status (sel: Option<&str>, sr: &str, buf: &str, lat: &str) -> impl D let buf = field_h(theme, "Buf", buf); let lat = field_h(theme, "Lat", lat); bg(Black, east!(above( - wh_full(origin_w(sel.map(|sel|field_h(theme, "Selected", sel)))), - wh_full(origin_e(east!(sr, buf, lat))), + wh_full(align_w(sel.map(|sel|field_h(theme, "Selected", sel)))), + wh_full(align_e(east!(sr, buf, lat))), ))) } @@ -235,8 +218,8 @@ pub fn button_play_pause (playing: bool, compact: bool) -> impl Draw { button_add: impl Draw, content: impl Draw, ) -> impl Draw { - west(h_full(w_exact(4, origin_nw(button_add))), - east(w_exact(20, h_full(origin_nw(button))), wh_full(origin_c(content)))) + west(h_full(w_exact(4, align_nw(button_add))), + east(w_exact(20, h_full(align_nw(button))), wh_full(align_c(content)))) } /// ``` @@ -302,12 +285,12 @@ pub fn view_sample_info_v (sample: Option<&Arc>>) -> impl Draw>>) -> impl Draw) -> impl Draw { - w_exact(12, bg(theme.darker.term, w_full(origin_e(content)))) + w_exact(12, bg(theme.darker.term, w_full(align_e(content)))) } pub fn view_ports_status <'a, T: JackPort> (theme: ItemTheme, title: &'a str, ports: &'a [T]) @@ -339,7 +322,7 @@ pub fn view_ports_status <'a, T: JackPort> (theme: ItemTheme, title: &'a str, po let ins = ports.len() as u16; let frame = Outer(true, Style::default().fg(g(96))); let iter = move||ports.iter(); - let names = iter_south(iter, move|port, index|h_full(origin_w(format!(" {index} {}", port.port_name())))); + let names = iter_south(iter, move|port, index|h_full(align_w(format!(" {index} {}", port.port_name())))); let field = field_v(theme, title, names); wh_exact(Some(20), Some(1 + ins), border(true, frame, wh_exact(Some(20), Some(1 + ins), field))) } @@ -350,9 +333,9 @@ pub fn view_io_ports <'a, T: PortsSizes<'a>> ( type Item<'a> = (usize, &'a Arc, &'a [Connect], usize, usize); iter(items, move|(_index, name, connections, y, y2): Item<'a>, _| { y_push(y as u16, h_exact((y2-y) as u16, - south(h_full(bold(true, fg_bg(fg, bg, origin_w(east(" 󰣲 ", name))))), + south(h_full(bold(true, fg_bg(fg, bg, align_w(east(" 󰣲 ", name))))), iter(||connections.iter(), move|connect: &'a Connect, index|y_push( - index as u16, h_exact(1, origin_w(bold(false, fg_bg(fg, bg, &connect.info)))) + index as u16, h_exact(1, align_w(bold(false, fg_bg(fg, bg, &connect.info)))) ))))) }) } @@ -365,7 +348,7 @@ pub fn view_scenes_clips <'a, S: ScenesSizes<'a>> ( size: &Sizer, editing: bool, ) -> impl Draw { - let status = wh_full(origin_se(fg(Green, format!("{}x{}", size.w(), size.h())))); + let status = wh_full(align_se(fg(Green, format!("{}x{}", size.w(), size.h())))); let tracks = iter_once(tracks, move|(track_index, track, _, _), _| { let scenes = iter_once(scenes(), move|(scene_index, scene, _, _), _| { let (name, theme): (Arc, ItemTheme) = scene_name_theme(scene, track_index); @@ -379,7 +362,7 @@ pub fn view_scenes_clips <'a, S: ScenesSizes<'a>> ( wh_full(below( below( fg_bg(o, b, wh_full("")), - wh_full(origin_nw(fg_bg(f, b, bold(true, name)))), + wh_full(align_nw(fg_bg(f, b, bold(true, name)))), ), wh_full(when(is_selected, editor.map(|e|e.view()))))))) }); @@ -460,12 +443,12 @@ pub fn view_track_names ( track.color.light.term } else { track.color.base.term - }, south(w_full(origin_nw(east( + }, south(w_full(align_nw(east( format!("·t{index:02} "), fg(Rgb(255, 255, 255), bold(true, &track.name)) ))), ""))) ).draw(to)?; } - Ok(XYWH(0, 0, 0, 0)) + Ok(Some(XYWH(0, 0, 0, 0))) })))) } @@ -473,24 +456,24 @@ pub fn view_track_outputs ( theme: ItemTheme, tracks: impl TracksSizes<'_>, midi_outs: impl Iterator, ) -> impl Draw { view_track_row_section(theme, - south(w_full(origin_w(button_2("o", "utput", false))), + south(w_full(align_w(button_2("o", "utput", false))), thunk(|to: &mut Tui|{ for port in midi_outs { - w_full(origin_w(port.port_name())).draw(to); + w_full(align_w(port.port_name())).draw(to); } - Ok(XYWH(0, 0, 0, 0)) + Ok(Some(XYWH(0, 0, 0, 0))) })), button_2("O", "+", false), - bg(theme.darker.term, origin_w(thunk(|to: &mut Tui|{ + bg(theme.darker.term, align_w(thunk(|to: &mut Tui|{ for (index, track, _x1, _x2) in tracks { let iter = ||track.sequencer.midi_outs.iter(); let draw = |port: &MidiOutput, _|fg(Rgb(255, 255, 255), - h_exact(1, bg(track.color.dark.term, w_full(origin_w( + h_exact(1, bg(track.color.dark.term, w_full(align_w( format!("·o{index:02} {}", port.port_name())))))); w_exact(track_width(index, track), - origin_nw(h_full(iter_south(iter, draw)))).draw(to)?; + align_nw(h_full(iter_south(iter, draw)))).draw(to)?; } - Ok(XYWH(0, 0, 0, 0)) + Ok(Some(XYWH(0, 0, 0, 0))) })))) } @@ -498,22 +481,22 @@ pub fn view_track_inputs ( theme: ItemTheme, tracks: impl TracksSizes<'_>, height: u16, ) -> impl Draw { view_track_row_section(theme, button_2("i", "nput", false), button_2("I", "+", false), - bg(theme.darker.term, origin_w(thunk(move|to: &mut Tui|{ + bg(theme.darker.term, align_w(thunk(move|to: &mut Tui|{ for (index, track, _x1, _x2) in tracks { wh_exact(Some(track_width(index, track)), Some(height + 1), - origin_nw(south( + align_nw(south( bg(track.color.base.term, - w_full(origin_w(east!( + w_full(align_w(east!( either(track.sequencer.monitoring, fg(Green, "●mon "), "·mon "), either(track.sequencer.recording, fg(Red, "●rec "), "·rec "), either(track.sequencer.overdub, fg(Yellow, "●dub "), "·dub "), )))), iter_south(||track.sequencer.midi_ins.iter(), |port, _|fg_bg(Rgb(255, 255, 255), track.color.dark.term, - w_full(origin_w(format!("·i{index:02} {}", port.port_name())))))))) + w_full(align_w(format!("·i{index:02} {}", port.port_name())))))))) .draw(to)?; } - Ok(XYWH(0, 0, 0, 0)) + Ok(Some(XYWH(0, 0, 0, 0))) })))) } @@ -527,7 +510,7 @@ pub fn view_scenes_names ( for (index, scene, ..) in scenes { view_scene_name(select, editor, index, scene, editing).draw(to)?; } - Ok(XYWH(1, 1, 1, 1)) + Ok(Some(XYWH(1, 1, 1, 1))) })) } @@ -543,10 +526,10 @@ pub fn view_scene_name ( } else { H_SCENE as u16 }; - let a = w_full(origin_w(east(format!("·s{index:02} "), + let a = w_full(align_w(east(format!("·s{index:02} "), fg(g(255), bold(true, &scene.name))))); let b = when(select.scene() == Some(index) && editing, - wh_full(origin_nw(south( + wh_full(align_nw(south( editor.as_ref().map(|e|e.clip_status()), editor.as_ref().map(|e|e.edit_status()))))); let c = if select.scene() == Some(index) { @@ -554,7 +537,7 @@ pub fn view_scene_name ( } else { scene.color.base.term }; - wh_exact(Some(20), Some(h), bg(c, origin_nw(south(a, b)))) + wh_exact(Some(20), Some(h), bg(c, align_nw(south(a, b)))) } pub fn view_midi_ins_status (theme: ItemTheme, track: Option<&Track>) -> impl Draw { @@ -590,21 +573,21 @@ pub fn view_per_track () -> impl Draw {} pub fn view_per_track_top () -> impl Draw {} pub fn view_inputs (tracks: impl TracksSizes<'_>, midi_ins: &[MidiInput]) -> impl Draw { - let title_1 = wh_exact(Some(20), Some(1), origin_w(button_3("i", "nput ", format!("{}", midi_ins.len()), false))); + let title_1 = wh_exact(Some(20), Some(1), align_w(button_3("i", "nput ", format!("{}", midi_ins.len()), false))); let title_2 = wh_exact(Some(4), Some(1), w_exact(4, button_2("I", "+", false))); east(title_1, west(title_2, thunk(move|to: &mut Tui|{ for (_index, track, x1, _x2) in tracks { south( - x_push(x1 as u16, bg(track.color.dark.term, origin_w(w_exact(track.width as u16, east!( + x_push(x1 as u16, bg(track.color.dark.term, align_w(w_exact(track.width as u16, east!( either(track.sequencer.monitoring, fg(Green, "mon "), "mon "), either(track.sequencer.recording, fg(Red, "rec "), "rec "), either(track.sequencer.overdub, fg(Yellow, "dub "), "dub "), ))))), thunk(move |to: &mut Tui|{ for (index, port) in midi_ins.iter().enumerate() { - x_push(index as u16 * 10, h_exact(1, east(w_exact(20, origin_w(east(" ● ", bold(true, fg(Rgb(255,255,255), port.port_name()))))), + x_push(index as u16 * 10, h_exact(1, east(w_exact(20, align_w(east(" ● ", bold(true, fg(Rgb(255,255,255), port.port_name()))))), west(w_exact(4, ()), thunk(move|to: &mut Tui|{ - bg(track.color.darker.term, origin_w(w_exact(track.width as u16, east!( + bg(track.color.darker.term, align_w(w_exact(track.width as u16, east!( either(track.sequencer.monitoring, fg(Green, " ● "), " · "), either(track.sequencer.recording, fg(Red, " ● "), " · "), either(track.sequencer.overdub, fg(Yellow, " ● "), " · "), @@ -628,18 +611,18 @@ pub fn view_outputs ( ) -> impl Draw { let list = south( - h_exact(1, w_full(origin_w(button_3( + h_exact(1, w_full(align_w(button_3( "o", "utput", format!("{}", midi_outs.len()), false )))), - h_exact(height - 1, wh_full(origin_nw(thunk(|to: &mut Tui|{ + h_exact(height - 1, wh_full(align_nw(thunk(|to: &mut Tui|{ for (_index, port) in midi_outs.iter().enumerate() { h_exact(1,w_full(east( - origin_w(east(" ● ", fg(Rgb(255,255,255), bold(true, port.port_name())))), - w_full(origin_e(format!("{}/{} ", + align_w(east(" ● ", fg(Rgb(255,255,255), bold(true, port.port_name())))), + w_full(align_e(format!("{}/{} ", port.port().get_connections().len(), port.connections.len())))))).draw(to)?; for (index, conn) in port.connections.iter().enumerate() { - h_exact(1, w_full(origin_w(format!(" c{index:02}{}", conn.info())))) + h_exact(1, w_full(align_w(format!(" c{index:02}{}", conn.info())))) .draw(to)?; } } @@ -648,17 +631,17 @@ pub fn view_outputs ( ); h_exact(height, view_track_row_section(theme, list, button_2("O", "+", false), - bg(theme.darker.term, origin_w(w_full( + bg(theme.darker.term, align_w(w_full( thunk(|to: &mut Tui|{ for (index, track, _x1, _x2) in tracks { w_exact(track_width(index, track), thunk(|to: &mut Tui|{ - h_exact(1, origin_w(east( + h_exact(1, align_w(east( either(true, fg(Green, "play "), "play "), either(false, fg(Yellow, "solo "), "solo "), ))).draw(to)?; for (_index, port) in midi_outs.iter().enumerate() { - h_exact(1, origin_w(east( + h_exact(1, align_w(east( either(true, fg(Green, " ● "), " · "), either(false, fg(Yellow, " ● "), " · "), ))).draw(to)?; @@ -688,12 +671,12 @@ pub fn view_track_devices ( iter_once(tracks, move|(_, track, _x1, _x2), index| wh_exact( Some(track_width(index, track)), Some(h + 1), - bg(track.color.dark.term, origin_nw(iter_south(move||0..h, + bg(track.color.dark.term, align_nw(iter_south(move||0..h, |_, _index|wh_exact(Some(track.width as u16), Some(2), fg_bg( ItemTheme::G[32].lightest.term, ItemTheme::G[32].dark.term, - origin_nw(format!(" · {}", "--")) + align_nw(format!(" · {}", "--")) ) ))))))) } @@ -702,14 +685,14 @@ pub fn per_track <'a, T: Draw + 'a, U: TracksSizes<'a>> ( tracks: impl Fn() -> U + Send + Sync + 'a, callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a ) -> impl Draw + 'a { - per_track_top(tracks, move|index, track|h_full(origin_y(callback(index, track)))) + per_track_top(tracks, move|index, track|h_full(align_y(callback(index, track)))) } pub fn per_track_top <'a, T: Draw + 'a, U: TracksSizes<'a>> ( tracks: impl Fn() -> U + Send + Sync + 'a, callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a ) -> impl Draw + 'a { - origin_x(bg(Reset, iter_east(tracks, + align_x(bg(Reset, iter_east(tracks, move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|{ w_exact((x2 - x1) as u16, fg_bg( track.color.lightest.term, @@ -732,14 +715,14 @@ pub fn view_sessions () -> impl Draw { let b = if index == 0 { Rgb(50,50,50) } else { Rgb(40,40,40) }; let y = (2 * index) as u16; let h = 2; - y_push(y, h_exact(h, w_full(bg(b, origin_w(fg(f, *name)))))).draw(to)?; + y_push(y, h_exact(h, w_full(bg(b, align_w(fg(f, *name)))))).draw(to)?; } - Ok(to.area().into()) + Ok(Some(to.area().into())) }))) } pub fn view_browse_title (state: &App) -> impl Draw { - w_full(origin_w(field_v(ItemTheme::default(), + w_full(align_w(field_v(ItemTheme::default(), match state.dialog.browser_target().unwrap() { BrowseTarget::SaveProject => "Save project:", BrowseTarget::LoadProject => "Load project:", diff --git a/src/deps.rs b/src/deps.rs index ad94c204..f599cc16 100644 --- a/src/deps.rs +++ b/src/deps.rs @@ -6,7 +6,7 @@ pub(crate) use ::xdg::BaseDirectories; pub(crate) use ::midly::{Smf, TrackEventKind, MidiMessage, Error as MidiError, num::*, live::*}; pub(crate) use tengri::{ - *, lang::*, exit::*, eval::*, sing::*, time::*, draw::*, term::*, color::*, task::*, + *, lang::*, crossterm::event::{Event, KeyEvent}, ratatui::{ self, diff --git a/src/device/clock/moment.rs b/src/device/clock/moment.rs index bf62a822..ed93e2e2 100644 --- a/src/device/clock/moment.rs +++ b/src/device/clock/moment.rs @@ -1,7 +1,6 @@ use crate::*; use ::std::sync::{Arc, RwLock, atomic::{AtomicUsize, Ordering::*}}; use ::atomic_float::AtomicF64; -use ::tengri::{draw::*, term::*}; /// A point in time in all time scales (microsecond, sample, MIDI pulse) /// diff --git a/src/device/clock/ticker.rs b/src/device/clock/ticker.rs index 50656d77..1cb163b0 100644 --- a/src/device/clock/ticker.rs +++ b/src/device/clock/ticker.rs @@ -1,7 +1,6 @@ use crate::*; use ::std::sync::{Arc, RwLock, atomic::{AtomicUsize, Ordering::*}}; use ::atomic_float::AtomicF64; -use ::tengri::{draw::*, term::*}; /// Iterator that emits subsequent ticks within a range. /// diff --git a/src/device/clock/timebase.rs b/src/device/clock/timebase.rs index 923e054a..fef79202 100644 --- a/src/device/clock/timebase.rs +++ b/src/device/clock/timebase.rs @@ -1,7 +1,6 @@ use crate::*; use ::std::sync::{Arc, RwLock, atomic::{AtomicUsize, Ordering::*}}; use ::atomic_float::AtomicF64; -use ::tengri::{draw::*, term::*}; /// Temporal resolutions: sample rate, tempo, MIDI pulses per quaver (beat) /// diff --git a/src/device/editor/piano.rs b/src/device/editor/piano.rs index 6f163b60..4102953f 100644 --- a/src/device/editor/piano.rs +++ b/src/device/editor/piano.rs @@ -156,7 +156,7 @@ impl PianoHorizontal { } } } - Ok(xywh) + Ok(Some(xywh)) }) } @@ -190,7 +190,7 @@ impl PianoHorizontal { break } } - Ok(xywh) + Ok(Some(xywh)) }) } @@ -217,7 +217,7 @@ impl PianoHorizontal { to.blit(¬e_pitch_to_name(note), x, screen_y, off_style) }; } - Ok(xywh) + Ok(Some(xywh)) }))) } @@ -233,7 +233,7 @@ impl PianoHorizontal { to.blit(&"|", screen_x, y, style); } } - Ok(xywh) + Ok(Some(xywh)) }))) } } diff --git a/src/device/meter.rs b/src/device/meter.rs index bfe9a48a..e7c493ac 100644 --- a/src/device/meter.rs +++ b/src/device/meter.rs @@ -11,37 +11,33 @@ pub struct Log10Meter(pub f32); #[derive(Debug, Default, Clone)] pub struct RmsMeter(pub f32); -impl Draw for RmsMeter { - fn draw (self, to: &mut Tui) -> Usually> { - let XYWH(x, y, w, h) = to.area().into(); - let signal = f32::max(0.0, f32::min(100.0, self.0.abs())); - let v = (signal * h as f32).ceil() as u16; - let y2 = y + h; - //to.blit(&format!("\r{v} {} {signal}", self.0), x * 30, y, Some(Style::default())); - for y in y..(y + v) { - for x in x..(x + w) { - to.blit(&"▌", x, y2.saturating_sub(y), Some(Style::default().green())); - } +impl_draw!(|self: RmsMeter, to: Tui|{ + let XYWH(x, y, w, h) = to.area().into(); + let signal = f32::max(0.0, f32::min(100.0, self.0.abs())); + let v = (signal * h as f32).ceil() as u16; + let y2 = y + h; + //to.blit(&format!("\r{v} {} {signal}", self.0), x * 30, y, Some(Style::default())); + for y in y..(y + v) { + for x in x..(x + w) { + to.blit(&"▌", x, y2.saturating_sub(y), Some(Style::default().green())); } - Ok(to.area().into()) } -} + Ok(Some(to.area().into())) +}); -impl Draw for Log10Meter { - fn draw(self, to: &mut Tui) -> Usually> { - let XYWH(x, y, w, h) = to.area().into(); - let signal = 100.0 - f32::max(0.0, f32::min(100.0, self.0.abs())); - let v = (signal * h as f32 / 100.0).ceil() as u16; - let y2 = y + h; - //to.blit(&format!("\r{v} {} {signal}", self.0), x * 20, y, None); - for y in y..(y + v) { - for x in x..(x + w) { - to.blit(&"▌", x, y2 - y, Some(Style::default().green())); - } +impl_draw!(|self: Log10Meter, to: Tui| { + let XYWH(x, y, w, h) = to.area().into(); + let signal = 100.0 - f32::max(0.0, f32::min(100.0, self.0.abs())); + let v = (signal * h as f32 / 100.0).ceil() as u16; + let y2 = y + h; + //to.blit(&format!("\r{v} {} {signal}", self.0), x * 20, y, None); + for y in y..(y + v) { + for x in x..(x + w) { + to.blit(&"▌", x, y2 - y, Some(Style::default().green())); } - Ok(to.area().into()) } -} + Ok(Some(to.area().into())) +}); fn draw_meters (meters: &[f32]) -> impl Draw + use<'_> { bg(Black, w_exact(2, iter_east_fixed(1, ||meters.iter(), |value, _index|{ diff --git a/src/device/sampler.rs b/src/device/sampler.rs index 40bd30a3..f82c0a68 100644 --- a/src/device/sampler.rs +++ b/src/device/sampler.rs @@ -314,7 +314,7 @@ fn draw_viewer (sample: Option<&Arc>>) -> impl Draw + use<'_ }) .render(area, to.as_mut()); } - Ok(xywh) + Ok(Some(xywh)) }) } diff --git a/src/device/sampler/sample_add.rs b/src/device/sampler/sample_add.rs index 996e4b04..4fa88b67 100644 --- a/src/device/sampler/sample_add.rs +++ b/src/device/sampler/sample_add.rs @@ -12,6 +12,8 @@ use crate::{*, device::sampler::*}; pub _search: Option, } +impl_draw!(|self: SampleAdd, to: Tui|{ todo!() }); + impl SampleAdd { fn exited (&self) -> bool { self.exited @@ -118,9 +120,3 @@ impl SampleAdd { return Ok(false) } } - -impl Draw for SampleAdd { - fn draw (self, _to: &mut Tui) -> Usually> { - todo!() - } -} diff --git a/tengri b/tengri index 0b9e9c06..1f60b43f 160000 --- a/tengri +++ b/tengri @@ -1 +1 @@ -Subproject commit 0b9e9c06962e5cd55b639d9c0a7cef6f11405d81 +Subproject commit 1f60b43f616ff49ddd8187bcca8d31e9b6597cec