still 91 until happiness :(
Some checks failed
/ build (push) Has been cancelled

This commit is contained in:
🪞👃🪞 2025-09-02 22:39:04 +03:00
parent 34070de5f7
commit fd26b12955
18 changed files with 243 additions and 194 deletions

View file

@ -133,7 +133,7 @@ impl App {
}
}
fn wrap_dialog (dialog: impl Content<TuiOut>) -> impl Content<TuiOut> {
fn wrap_dialog (dialog: impl Render<TuiOut>) -> impl Render<TuiOut> {
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))))
}

View file

@ -33,9 +33,10 @@ handle!(TuiIn:|self: App, input|{
#[derive(Debug, Copy, Clone)]
pub enum Axis { X, Y, Z, I }
impl<'t> DslNs<'t, AppCommand> for App {
dsl_exprs!(|app| -> AppCommand { /* TODO */ });
dsl_words!(|app| -> AppCommand {
impl<'a> DslNs<'a, AppCommand> for App {}
impl<'a> DslNsExprs<'a, AppCommand> for App {}
impl<'a> DslNsWords<'a, AppCommand> for App {
dsl_words!('a |app| -> AppCommand {
"x/inc" => AppCommand::Inc { axis: Axis::X },
"x/dec" => AppCommand::Dec { axis: Axis::X },
"y/inc" => AppCommand::Inc { axis: Axis::Y },

View file

@ -1,15 +1,17 @@
use crate::*;
impl<'t> DslNs<'t, Arc<str>> for App {
dsl_exprs!(|app| -> Arc<str> {});
dsl_words!(|app| -> Arc<str> {});
fn from_literal <D: Dsl> (&self, dsl: &D) -> Perhaps<Arc<str>> {
impl<'a> DslNs<'a, Arc<str>> for App {
fn from_literal (&self, dsl: impl Dsl) -> Perhaps<Arc<str>> {
Ok(dsl.src()?.map(|x|x.into()))
}
}
impl<'a> DslNsWords<'a, Arc<str>> for App {}
impl<'a> DslNsExprs<'a, Arc<str>> for App {}
impl<'t> DslNs<'t, bool> for App {
dsl_words!(|app| -> bool {
impl<'a> DslNs<'a, bool> for App {}
impl<'a> DslNsExprs<'a, bool> for App {}
impl<'a> DslNsWords<'a, bool> for App {
dsl_words!('a |app| -> bool {
":mode/editor" => app.project.editor.is_some(),
":focused/dialog" => !matches!(app.dialog, Dialog::None),
@ -29,15 +31,16 @@ impl<'t> DslNs<'t, bool> for App {
":focused/mix" => !app.editor_focused() && matches!(app.selection(),
Selection::Mix),
});
//fn from_literal <D: Dsl> (&self, dsl: &D) -> Perhaps<Arc<str>> {
//TODO
//}
}
impl<'t> DslNs<'t, ItemTheme> for App {}
impl<'a> DslNs<'a, ItemTheme> for App {}
impl<'a> DslNsWords<'a, ItemTheme> for App {}
impl<'a> DslNsExprs<'a, ItemTheme> for App {}
impl<'t> DslNs<'t, Dialog> for App {
dsl_words!(|app| -> Dialog {
impl<'a> DslNs<'a, Dialog> for App {}
impl<'a> DslNsExprs<'a, Dialog> for App {}
impl<'a> DslNsWords<'a, Dialog> for App {
dsl_words!('a |app| -> Dialog {
":dialog/none" => Dialog::None,
":dialog/options" => Dialog::Options,
":dialog/device" => Dialog::Device(0),
@ -59,8 +62,10 @@ impl<'t> DslNs<'t, Dialog> for App {
});
}
impl<'t> DslNs<'t, Selection> for App {
dsl_words!(|app| -> Selection {
impl<'a> DslNs<'a, Selection> for App {}
impl<'a> DslNsExprs<'a, Selection> for App {}
impl<'a> DslNsWords<'a, Selection> for App {
dsl_words!('a |app| -> Selection {
":select/scene" => app.selection().select_scene(app.tracks().len()),
":select/scene/next" => app.selection().select_scene_next(app.scenes().len()),
":select/scene/prev" => app.selection().select_scene_prev(),
@ -70,33 +75,42 @@ impl<'t> DslNs<'t, Selection> for App {
});
}
impl<'t> DslNs<'t, Color> for App {
dsl_words!(|app| -> Color {
impl<'a> DslNs<'a, Color> for App {}
impl<'a> DslNsWords<'a, Color> for App {
dsl_words!('a |app| -> Color {
":color/bg" => Color::Rgb(28, 32, 36),
});
dsl_exprs!(|app| -> Color {
"g" (n: u8) => Color::Rgb(n, n, n),
}
impl<'a> DslNsExprs<'a, Color> for App {
dsl_exprs!('a |app| -> Color {
"g" (n: u8) => Color::Rgb(n, n, n),
"rgb" (r: u8, g: u8, b: u8) => Color::Rgb(r, g, b),
});
}
impl<'t> DslNs<'t, Option<u7>> for App {
dsl_words!(|app| -> Option<u7> {
impl<'a> DslNs<'a, Option<u7>> for App {}
impl<'a> DslNsExprs<'a, Option<u7>> for App {}
impl<'a> DslNsWords<'a, Option<u7>> for App {
dsl_words!('a |app| -> Option<u7> {
":editor/pitch" => Some(
(app.editor().as_ref().map(|e|e.get_note_pos()).unwrap() as u8).into()
)
});
}
impl<'t> DslNs<'t, Option<usize>> for App {
dsl_words!(|app| -> Option<usize> {
impl<'a> DslNs<'a, Option<usize>> for App {}
impl<'a> DslNsExprs<'a, Option<usize>> for App {}
impl<'a> DslNsWords<'a, Option<usize>> for App {
dsl_words!('a |app| -> Option<usize> {
":selected/scene" => app.selection().scene(),
":selected/track" => app.selection().track(),
});
}
impl<'t> DslNs<'t, Option<Arc<RwLock<MidiClip>>>> for App {
dsl_words!(|app| -> Option<Arc<RwLock<MidiClip>>> {
impl<'a> DslNs<'a, Option<Arc<RwLock<MidiClip>>>> for App {}
impl<'a> DslNsExprs<'a, Option<Arc<RwLock<MidiClip>>>> for App {}
impl<'a> DslNsWords<'a, Option<Arc<RwLock<MidiClip>>>> for App {
dsl_words!('a |app| -> Option<Arc<RwLock<MidiClip>>> {
":selected/clip" => if let Selection::TrackClip { track, scene } = app.selection() {
app.scenes()[*scene].clips[*track].clone()
} else {
@ -105,18 +119,63 @@ impl<'t> DslNs<'t, Option<Arc<RwLock<MidiClip>>>> for App {
});
}
dsl_ns! { num |app: App|
u8;
u16 => {
impl<'a> DslNs<'a, u8> for App {
fn from_literal (&self, dsl: impl Dsl) -> Perhaps<u8> {
Ok(if let Some(src) = dsl.src()? {
Some(to_number(src)? as u8)
} else {
None
})
}
}
impl<'a> DslNsWords<'a, u8> for App {}
impl<'a> DslNsExprs<'a, u8> for App {}
impl<'a> DslNs<'a, u16> for App {
fn from_literal (&self, dsl: impl Dsl) -> Perhaps<u16> {
Ok(if let Some(src) = dsl.src()? {
Some(to_number(src)? as u16)
} else {
None
})
}
}
impl<'a> DslNsWords<'a, u16> for App {
dsl_words!('a |app| -> u16 {
":w/sidebar" => app.project.w_sidebar(app.editor().is_some()),
":h/sample-detail" => 6.max(app.height() as u16 * 3 / 9),
};
usize => {
});
}
impl<'a> DslNsExprs<'a, u16> for App {}
impl<'a> DslNs<'a, usize> for App {
fn from_literal (&self, dsl: impl Dsl) -> Perhaps<usize> {
Ok(if let Some(src) = dsl.src()? {
Some(to_number(src)? as usize)
} else {
None
})
}
}
impl<'a> DslNsWords<'a, usize> for App {
dsl_words!('a |app| -> usize {
":scene-count" => app.scenes().len(),
":track-count" => app.tracks().len(),
":device-kind" => app.dialog.device_kind().unwrap_or(0),
":device-kind/next" => app.dialog.device_kind_next().unwrap_or(0),
":device-kind/prev" => app.dialog.device_kind_prev().unwrap_or(0),
};
isize;
});
}
impl<'a> DslNsExprs<'a, usize> for App {}
impl<'a> DslNs<'a, isize> for App {
fn from_literal (&self, dsl: impl Dsl) -> Perhaps<isize> {
Ok(if let Some(src) = dsl.src()? {
Some(to_number(src)? as isize)
} else {
None
})
}
}
impl<'a> DslNsWords<'a, isize> for App {}
impl<'a> DslNsExprs<'a, isize> for App {}

View file

@ -1,97 +1,103 @@
use crate::*;
impl Content<TuiOut> for App {
fn content (&self) -> impl Render<TuiOut> + '_ {
Stack::above(move|add|for dsl in self.mode.view.iter() {
add(&Fill::xy(self.view(dsl.as_ref())));
})
impl Render<TuiOut> for App {
fn render (&self, to: &mut TuiOut) {
to.place(to.area(), &Stack::above(|add|for dsl in self.mode.view.iter() {
add(&self.view(dsl))
}))
}
}
impl App {
fn view <'t, D: Dsl> (&'t self, index: D) -> TuiBox<'t> {
match index.src() {
Ok(Some(src)) => render_dsl(self, src),
Ok(None) => Box::new(Tui::fg(Color::Rgb(192, 192, 192), "empty view")),
Err(e) => Box::new(format!("{e}")),
}
fn view <'a> (&'a self, dsl: impl Dsl + 'a) -> TuiBox<'a> {
self.from(dsl).unwrap().unwrap()
}
pub fn update_clock (&self) {
ViewCache::update_clock(&self.project.clock.view_cache, self.clock(), self.size.w() > 80)
}
}
type TuiBox<'t> = Box<dyn Render<TuiOut> + 't>;
type TuiBox<'a> = Box<dyn Render<TuiOut> + 'a>;
fn render_dsl <'t> (
state: &'t impl DslNs<'t, TuiBox<'t>>,
src: &str
) -> TuiBox<'t> {
let err: Option<Box<dyn Error>> = match state.from(&src) {
Ok(Some(value)) => return value, Ok(None) => None, Err(e) => Some(e),
};
fn render_error (err: impl Error, src: &str) -> impl Render<TuiOut> {
let (fg_1, bg_1) = (Color::Rgb(240, 160, 100), Color::Rgb(48, 0, 0));
let (fg_2, bg_2) = (Color::Rgb(250, 200, 180), Color::Rgb(48, 0, 0));
let (fg_3, bg_3) = (Color::Rgb(250, 200, 120), Color::Rgb(0, 0, 0));
let bg = Color::Rgb(24, 0, 0);
Box::new(col! {
col! {
Tui::fg(bg, Fixed::y(1, Fill::x(RepeatH("")))),
Tui::bg(bg, col! {
Fill::x(Bsp::e(
Tui::bold(true, Tui::fg_bg(fg_1, bg_1, " Render error: ")),
Tui::fg_bg(fg_2, bg_2, err.map(|e|format!(" {e} "))),
Tui::fg_bg(fg_2, bg_2, format!(" {err} ")),
)),
Fill::x(Align::x(Tui::fg_bg(fg_3, bg_3, format!(" {src} ")))),
}),
Tui::fg(bg, Fixed::y(1, Fill::x(RepeatH("")))),
})
}
}
impl<'t> DslNs<'t, TuiBox<'t>> for App {
dsl_exprs!(|app| -> TuiBox<'t> {
"text" (tail: Arc<str>) => Box::new(tail),
impl<'a> DslNs<'a, TuiBox<'a>> for App {}
"fg" (color: Color, x: TuiBox<'t>) => Box::new(Tui::fg(color, x)),
"bg" (color: Color, x: TuiBox<'t>) => Box::new(Tui::bg(color, x)),
"fg/bg" (fg: Color, bg: Color, x: TuiBox<'t>) => Box::new(Tui::fg_bg(fg, bg, x)),
impl<'a> DslNsExprs<'a, TuiBox<'a>> for App {
dsl_exprs!('a |app| -> TuiBox<'a> {
"text" (tail: Arc<str>) => tail.boxed(),
"either" (cond: bool, a: TuiBox<'t>, b: TuiBox<'t>) =>
"fg" (color: Color, x: TuiBox<'a>) => Tui::fg(color, x).boxed(),
"bg" (color: Color, x: TuiBox<'a>) => Tui::bg(color, x).boxed(),
"fg/bg" (fg: Color, bg: Color, x: TuiBox<'a>) => Box::new(Tui::fg_bg(fg, bg, x)),
"either" (cond: bool, a: TuiBox<'a>, b: TuiBox<'a>) =>
Box::new(Either(cond, a, b)),
"bsp/n" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::n(a, b)),
"bsp/s" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::s(a, b)),
"bsp/e" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::e(a, b)),
"bsp/w" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::w(a, b)),
"bsp/a" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::a(a, b)),
"bsp/b" (a: TuiBox<'t>, b: TuiBox<'t>) => Box::new(Bsp::b(a, b)),
"bsp/n" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::n(a, b)),
"bsp/s" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::s(a, b)),
"bsp/e" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::e(a, b)),
"bsp/w" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::w(a, b)),
"bsp/a" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::a(a, b)),
"bsp/b" (a: TuiBox<'a>, b: TuiBox<'a>) => Box::new(Bsp::b(a, b)),
"align/nw" (x: TuiBox<'t>) => Box::new(Align::nw(x)),
"align/ne" (x: TuiBox<'t>) => Box::new(Align::ne(x)),
"align/n" (x: TuiBox<'t>) => Box::new(Align::n(x)),
"align/s" (x: TuiBox<'t>) => Box::new(Align::s(x)),
"align/e" (x: TuiBox<'t>) => Box::new(Align::e(x)),
"align/w" (x: TuiBox<'t>) => Box::new(Align::w(x)),
"align/x" (x: TuiBox<'t>) => Box::new(Align::x(x)),
"align/y" (x: TuiBox<'t>) => Box::new(Align::y(x)),
"align/c" (x: TuiBox<'t>) => Box::new(Align::c(x)),
"align/nw" (x: TuiBox<'a>) => Box::new(Align::nw(x)),
"align/ne" (x: TuiBox<'a>) => Box::new(Align::ne(x)),
"align/n" (x: TuiBox<'a>) => Box::new(Align::n(x)),
"align/s" (x: TuiBox<'a>) => Box::new(Align::s(x)),
"align/e" (x: TuiBox<'a>) => Box::new(Align::e(x)),
"align/w" (x: TuiBox<'a>) => Box::new(Align::w(x)),
"align/x" (x: TuiBox<'a>) => Box::new(Align::x(x)),
"align/y" (x: TuiBox<'a>) => Box::new(Align::y(x)),
"align/c" (x: TuiBox<'a>) => Box::new(Align::c(x)),
"fill/x" (x: TuiBox<'t>) => Box::new(Fill::x(x)),
"fill/y" (x: TuiBox<'t>) => Box::new(Fill::y(x)),
"fill/xy" (x: TuiBox<'t>) => Box::new(Fill::xy(x)),
"fill/x" (x: TuiBox<'a>) => Box::new(Fill::x(x)),
"fill/y" (x: TuiBox<'a>) => Box::new(Fill::y(x)),
"fill/xy" (x: TuiBox<'a>) => Box::new(Fill::xy(x)),
"fixed/x" (x: u16, c: TuiBox<'t>) => Box::new(Fixed::x(x, c)),
"fixed/y" (y: u16, c: TuiBox<'t>) => Box::new(Fixed::y(y, c)),
"fixed/xy" (x: u16, y: u16, c: TuiBox<'t>) => Box::new(Fixed::xy(x, y, c)),
"fixed/x" (x: u16, c: TuiBox<'a>) => Box::new(Fixed::x(x, c)),
"fixed/y" (y: u16, c: TuiBox<'a>) => Box::new(Fixed::y(y, c)),
"fixed/xy" (x: u16, y: u16, c: TuiBox<'a>) => Box::new(Fixed::xy(x, y, c)),
"min/x" (x: u16, c: TuiBox<'t>) => Box::new(Min::x(x, c)),
"min/y" (y: u16, c: TuiBox<'t>) => Box::new(Min::y(y, c)),
"min/xy" (x: u16, y: u16, c: TuiBox<'t>) => Box::new(Min::xy(x, y, c)),
"min/x" (x: u16, c: TuiBox<'a>) => Box::new(Min::x(x, c)),
"min/y" (y: u16, c: TuiBox<'a>) => Box::new(Min::y(y, c)),
"min/xy" (x: u16, y: u16, c: TuiBox<'a>) => Box::new(Min::xy(x, y, c)),
"max/x" (x: u16, c: TuiBox<'t>) => Box::new(Max::x(x, c)),
"max/y" (y: u16, c: TuiBox<'t>) => Box::new(Max::y(y, c)),
"max/xy" (x: u16, y: u16, c: TuiBox<'t>) => Box::new(Max::xy(x, y, c)),
"max/x" (x: u16, c: TuiBox<'a>) => Box::new(Max::x(x, c)),
"max/y" (y: u16, c: TuiBox<'a>) => Box::new(Max::y(y, c)),
"max/xy" (x: u16, y: u16, c: TuiBox<'a>) => Box::new(Max::xy(x, y, c)),
});
dsl_words!(|app| -> TuiBox<'t> {
/// Resolve an expression if known.
fn from_expr (&'a self, dsl: impl Dsl) -> Perhaps<TuiBox<'a>> {
if let Some(head) = dsl.expr().head()? {
for (key, value) in Self::EXPRS.iter() {
if head == *key {
return value(self, dsl.expr().tail()?.unwrap_or(""))
}
}
}
return Ok(None)
}
}
impl<'a> DslNsWords<'a, TuiBox<'a>> for App {
dsl_words!('a |app| -> TuiBox<'a> {
":logo" => Box::new(Fixed::xy(32, 7, Tui::bold(true, Tui::fg(Rgb(240,200,180), Stack::south(|add|{
add(&Fixed::y(1, ""));
add(&Fixed::y(1, ""));
@ -168,27 +174,14 @@ impl<'t> DslNs<'t, TuiBox<'t>> for App {
let rb = if i == selected { " ]" } else { " " };
Fill::x(Tui::bg(bg, Bsp::e(lb, Bsp::w(rb, "FIXME device name")))) }))) },
});
/// Resolve an expression if known.
fn from_expr <D: Dsl> (&self, dsl: &D) -> Perhaps<TuiBox<'t>> {
if let Some(head) = dsl.expr().head()? {
for (key, value) in Self::EXPRS.0.iter() {
if head == *key {
return value(self, dsl.expr().tail()?.unwrap_or(""))
}
}
}
return Ok(None)
}
/// Resolve a symbol if known.
fn from_word <D: Dsl> (&self, dsl: &D) -> Perhaps<TuiBox<'t>> {
fn from_word (&'a self, dsl: impl Dsl) -> Perhaps<TuiBox<'a>> {
if let Some(dsl) = dsl.word()? {
let views = self.config.views.read().unwrap();
if let Some(view) = views.get(dsl) {
let view = view.clone();
std::mem::drop(views);
return Ok(Some(render_dsl(self, view.as_ref())))
return Ok(Some(self.view(view).boxed()))
}
for (word, get) in Self::WORDS.0 {
for (word, get) in Self::WORDS {
if dsl == *word {
return get(self)
}

View file

@ -74,7 +74,7 @@ impl Config {
}
}
pub fn init (&mut self) -> Usually<()> {
self.init_file(Self::CONFIG, Self::DEFAULTS, |cfgs, dsl|cfgs.load(dsl))?;
self.init_file(Self::CONFIG, Self::DEFAULTS, |cfgs, dsl|cfgs.load(&dsl))?;
Ok(())
}
pub fn init_file (
@ -82,7 +82,7 @@ impl Config {
) -> Usually<()> {
if self.dirs.find_config_file(path).is_none() {
println!("Creating {path:?}");
std::fs::write(self.dirs.place_config_file(path)?, defaults);
std::fs::write(self.dirs.place_config_file(path)?, defaults)?;
}
Ok(if let Some(path) = self.dirs.find_config_file(path) {
println!("Loading {path:?}");

View file

@ -13,7 +13,7 @@ def_sizes_iter!(InputsSizes => MidiInput);
def_sizes_iter!(OutputsSizes => MidiOutput);
def_sizes_iter!(PortsSizes => Arc<str>, [Connect]);
pub(crate) fn wrap (bg: Color, fg: Color, content: impl Content<TuiOut>) -> impl Content<TuiOut> {
pub(crate) fn wrap (bg: Color, fg: Color, content: impl Render<TuiOut>) -> impl Render<TuiOut> {
let left = Tui::fg_bg(bg, Reset, Fixed::x(1, RepeatV("")));
let right = Tui::fg_bg(bg, Reset, Fixed::x(1, RepeatV("")));
Bsp::e(left, Bsp::w(right, Tui::fg_bg(fg, bg, content)))

View file

@ -241,7 +241,7 @@ impl Track {
pub trait HasTrack {
fn track (&self) -> Option<&Track>;
fn track_mut (&mut self) -> Option<&mut Track>;
fn view_midi_ins_status (&self, theme: ItemTheme) -> impl Content<TuiOut> {
fn view_midi_ins_status (&self, theme: ItemTheme) -> impl Render<TuiOut> {
self.track().map(|track|{
let ins = track.sequencer.midi_ins.len() as u16;
Fixed::xy(20, 1 + ins, Outer(true, Style::default().fg(Tui::g(96))).enclose(
@ -249,7 +249,7 @@ pub trait HasTrack {
Map::south(1, ||track.sequencer.midi_ins.iter(),
|port, index|Fill::x(Align::w(format!(" {index} {}", port.port_name()))))))))})
}
fn view_midi_outs_status (&self, theme: ItemTheme) -> impl Content<TuiOut> {
fn view_midi_outs_status (&self, theme: ItemTheme) -> impl Render<TuiOut> {
self.track().map(|track|{
let outs = track.sequencer.midi_outs.len() as u16;
Fixed::xy(20, 1 + outs, Outer(true, Style::default().fg(Tui::g(96))).enclose(
@ -257,7 +257,7 @@ pub trait HasTrack {
Map::south(1, ||track.sequencer.midi_outs.iter(),
|port, index|Fill::x(Align::w(format!(" {index} {}", port.port_name()))))))))})
}
fn view_audio_ins_status (&self, theme: ItemTheme) -> impl Content<TuiOut> {
fn view_audio_ins_status (&self, theme: ItemTheme) -> impl Render<TuiOut> {
self.track().and_then(|track|track.devices.get(0)).map(|device|{
let ins = device.audio_ins().len() as u16;
Fixed::xy(20, 1 + ins, Outer(true, Style::default().fg(Tui::g(96))).enclose(
@ -265,7 +265,7 @@ pub trait HasTrack {
Map::south(1, ||device.audio_ins().iter(),
|port, index|Fill::x(Align::w(format!(" {index} {}", port.port_name()))))))))})
}
fn view_audio_outs_status (&self, theme: ItemTheme) -> impl Content<TuiOut> {
fn view_audio_outs_status (&self, theme: ItemTheme) -> impl Render<TuiOut> {
self.track().and_then(|track|track.devices.last()).map(|device|{
let outs = device.audio_outs().len() as u16;
Fixed::xy(20, 1 + outs, Outer(true, Style::default().fg(Tui::g(96))).enclose(
@ -279,7 +279,7 @@ impl Track {
pub fn per <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
tracks: impl Fn() -> U + Send + Sync + 'a,
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
) -> impl Render<TuiOut> + 'a {
Map::new(tracks,
move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|{
let width = (x2 - x1) as u16;
@ -293,7 +293,7 @@ impl Track {
pub(crate) fn per_track_top <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
tracks: impl Fn() -> U + Send + Sync + 'a,
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
) -> impl Render<TuiOut> + 'a {
Align::x(Tui::bg(Reset, Map::new(tracks,
move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|{
let width = (x2 - x1) as u16;
@ -306,13 +306,13 @@ pub(crate) fn per_track_top <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
pub(crate) fn per_track <'a, T: Content<TuiOut> + 'a, U: TracksSizes<'a>> (
tracks: impl Fn() -> U + Send + Sync + 'a,
callback: impl Fn(usize, &'a Track)->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
) -> impl Render<TuiOut> + 'a {
per_track_top(tracks, move|index, track|Fill::y(Align::y(callback(index, track))))
}
pub(crate) fn io_ports <'a, T: PortsSizes<'a>> (
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
) -> impl Render<TuiOut> + 'a {
Map::new(iter, move|(
_index, name, connections, y, y2
): (usize, &'a Arc<str>, &'a [Connect], usize, usize), _|
@ -325,7 +325,7 @@ pub(crate) fn io_ports <'a, T: PortsSizes<'a>> (
pub(crate) fn io_conns <'a, T: PortsSizes<'a>> (
fg: Color, bg: Color, iter: impl Fn()->T + Send + Sync + 'a
) -> impl Content<TuiOut> + 'a {
) -> impl Render<TuiOut> + 'a {
Map::new(iter, move|(
_index, _name, connections, y, y2
): (usize, &'a Arc<str>, &'a [Connect], usize, usize), _|

View file

@ -1,38 +1,36 @@
use crate::*;
type Add<'a> = &'a dyn FnMut(&dyn Render<TuiOut>);
impl Arrangement {
pub fn view_inputs <'a> (&'a self, _theme: ItemTheme) -> impl Content<TuiOut> + 'a {
pub fn view_inputs (&self, _theme: ItemTheme) -> impl Render<TuiOut> + '_ {
Stack::south(move|add|{
add(&Fixed::y(1,
Bsp::e(Fixed::x(20, Align::w(button_3("i", "nput ", format!("{}", self.midi_ins.len()), false))),
Bsp::w(Fixed::x(4, button_2("I", "+", false)),
Stack::east(move|add|{
for (_index, track, _x1, _x2) in self.tracks_with_sizes() {
add(&Tui::bg(track.color.dark.rgb, Align::w(Fixed::x(track.width as u16, row!(
Either(track.sequencer.monitoring, Tui::fg(Green, "mon "), "mon "),
Either(track.sequencer.recording, Tui::fg(Red, "rec "), "rec "),
Either(track.sequencer.overdub, Tui::fg(Yellow, "dub "), "dub "),
)))))
}
Stack::east(move|add|for (_index, track, _x1, _x2) in self.tracks_with_sizes() {
add(&Tui::bg(track.color.dark.rgb, Align::w(Fixed::x(track.width as u16, row!(
Either(track.sequencer.monitoring, Tui::fg(Green, "mon "), "mon "),
Either(track.sequencer.recording, Tui::fg(Red, "rec "), "rec "),
Either(track.sequencer.overdub, Tui::fg(Yellow, "dub "), "dub "),
)))))
})))));
for (_index, port) in self.midi_ins().iter().enumerate() {
add(&Fixed::y(1, Bsp::e(
Fixed::x(20, Align::w(Bsp::e("",
Tui::bold(true, Tui::fg(Rgb(255,255,255), port.port_name()))))),
Bsp::w(Fixed::x(4, ()),
Stack::east(move|add|{
for (_index, track, _x1, _x2) in self.tracks_with_sizes() {
add(&Tui::bg(track.color.darker.rgb, Align::w(Fixed::x(track.width as u16, row!(
Either(track.sequencer.monitoring, Tui::fg(Green, ""), " · "),
Either(track.sequencer.recording, Tui::fg(Red, ""), " · "),
Either(track.sequencer.overdub, Tui::fg(Yellow, ""), " · "),
)))))
}
Stack::east(move|add|for (_index, track, _x1, _x2) in self.tracks_with_sizes() {
add(&Tui::bg(track.color.darker.rgb, Align::w(Fixed::x(track.width as u16, row!(
Either(track.sequencer.monitoring, Tui::fg(Green, ""), " · "),
Either(track.sequencer.recording, Tui::fg(Red, ""), " · "),
Either(track.sequencer.overdub, Tui::fg(Yellow, ""), " · "),
)))))
})))));
}
})
}
pub fn view_outputs <'a> (&'a self, theme: ItemTheme) -> impl Content<TuiOut> + 'a {
pub fn view_outputs <'a> (&'a self, theme: ItemTheme) -> impl Render<TuiOut> + 'a {
let mut h = 1;
for output in self.midi_outs().iter() {
h += 1 + output.connections.len();
@ -72,7 +70,7 @@ impl Arrangement {
}
}})))}}))))))
}
pub fn view_track_devices <'a> (&'a self, theme: ItemTheme) -> impl Content<TuiOut> + 'a {
pub fn view_track_devices <'a> (&'a self, theme: ItemTheme) -> impl Render<TuiOut> + 'a {
let mut h = 2u16;
for track in self.tracks().iter() {
h = h.max(track.devices.len() as u16 * 2);
@ -137,19 +135,19 @@ pub trait TracksView:
}
fn view_track_row_section (
_theme: ItemTheme,
button: impl Content<TuiOut>,
button_add: impl Content<TuiOut>,
content: impl Content<TuiOut>
) -> impl Content<TuiOut> {
button: impl Render<TuiOut>,
button_add: impl Render<TuiOut>,
content: impl Render<TuiOut>
) -> impl Render<TuiOut> {
Bsp::w(Fill::y(Fixed::x(4, Align::nw(button_add))),
Bsp::e(Fixed::x(20, Fill::y(Align::nw(button))), Fill::xy(Align::c(content))))
}
fn view_track_header <'a, T: Content<TuiOut>> (
&'a self, theme: ItemTheme, content: T
) -> impl Content<TuiOut> {
) -> impl Render<TuiOut> {
Fixed::x(12, Tui::bg(theme.darker.rgb, Fill::x(Align::e(content))))
}
fn view_track_names (&self, theme: ItemTheme) -> impl Content<TuiOut> {
fn view_track_names (&self, theme: ItemTheme) -> impl Render<TuiOut> {
let track_count = self.tracks().len();
let scene_count = self.scenes().len();
let selected = self.selection();
@ -176,7 +174,7 @@ pub trait TracksView:
}
})))))
}
fn view_track_outputs <'a> (&'a self, theme: ItemTheme, _h: u16) -> impl Content<TuiOut> {
fn view_track_outputs <'a> (&'a self, theme: ItemTheme, _h: u16) -> impl Render<TuiOut> {
Self::view_track_row_section(theme,
Bsp::s(
Fill::x(Align::w(button_2("o", "utput", false))),
@ -197,7 +195,7 @@ pub trait TracksView:
}
})))))
}
fn view_track_inputs <'a> (&'a self, theme: ItemTheme) -> impl Content<TuiOut> {
fn view_track_inputs <'a> (&'a self, theme: ItemTheme) -> impl Render<TuiOut> {
let mut h = 0u16;
for track in self.tracks().iter() {
h = h.max(track.sequencer.midi_ins.len() as u16);
@ -259,14 +257,14 @@ pub trait ScenesView:
}
})
}
fn view_scenes_names (&self) -> impl Content<TuiOut> {
fn view_scenes_names (&self) -> impl Render<TuiOut> {
Fixed::x(20, Stack::south(move|add|{
for (index, scene, ..) in self.scenes_with_sizes() {
add(&self.view_scene_name(index, scene));
}
}))
}
fn view_scene_name (&self, index: usize, scene: &Scene) -> impl Content<TuiOut> {
fn view_scene_name (&self, index: usize, scene: &Scene) -> impl Render<TuiOut> {
let h = if self.selection().scene() == Some(index) && let Some(_editor) = self.editor() {
7
} else {
@ -297,7 +295,7 @@ pub trait ClipsView:
Sync
{
fn view_scenes_clips <'a> (&'a self)
-> impl Content<TuiOut> + 'a
-> impl Render<TuiOut> + 'a
{
self.clips_size().of(Fill::xy(Bsp::a(
Fill::xy(Align::se(Tui::fg(Green, format!("{}x{}", self.clips_size().w(), self.clips_size().h())))),
@ -312,7 +310,7 @@ pub trait ClipsView:
}))))
}
fn view_track_clips <'a> (&'a self, track_index: usize, track: &'a Track) -> impl Content<TuiOut> + 'a {
fn view_track_clips <'a> (&'a self, track_index: usize, track: &'a Track) -> impl Render<TuiOut> + 'a {
Stack::south(move|cell|{
for (scene_index, scene, ..) in self.scenes_with_sizes() {
let (name, theme): (Arc<str>, ItemTheme) = if let Some(Some(clip)) = &scene.clips.get(track_index) {

View file

@ -6,7 +6,7 @@ pub fn view_transport (
bpm: Arc<RwLock<String>>,
beat: Arc<RwLock<String>>,
time: Arc<RwLock<String>>,
) -> impl Content<TuiOut> {
) -> impl Render<TuiOut> {
let theme = ItemTheme::G[96];
Tui::bg(Black, row!(Bsp::a(
Fill::xy(Align::w(button_play_pause(play))),
@ -23,7 +23,7 @@ pub fn view_status (
sr: Arc<RwLock<String>>,
buf: Arc<RwLock<String>>,
lat: Arc<RwLock<String>>,
) -> impl Content<TuiOut> {
) -> impl Render<TuiOut> {
let theme = ItemTheme::G[96];
Tui::bg(Black, row!(Bsp::a(
Fill::xy(Align::w(sel.map(|sel|FieldH(theme, "Selected", sel)))),
@ -35,7 +35,7 @@ pub fn view_status (
)))
}
pub(crate) fn button_play_pause (playing: bool) -> impl Content<TuiOut> {
pub(crate) fn button_play_pause (playing: bool) -> impl Render<TuiOut> {
let compact = true;//self.is_editing();
Tui::bg(if playing { Rgb(0, 128, 0) } else { Rgb(128, 64, 0) },
Either::new(compact,
@ -93,7 +93,7 @@ impl ViewCache {
//}
//pub fn scene_add (cache: &Arc<RwLock<Self>>, scene: usize, scenes: usize, is_editing: bool)
//-> impl Content<TuiOut>
//-> impl Render<TuiOut>
//{
//let data = (scene, scenes);
//cache.write().unwrap().scns.update(Some(data), rewrite!(buf, "({}/{})", data.0, data.1));
@ -133,7 +133,7 @@ impl ViewCache {
}
}
//pub fn view_h2 (&self) -> impl Content<TuiOut> {
//pub fn view_h2 (&self) -> impl Render<TuiOut> {
//let cache = self.project.clock.view_cache.clone();
//let cache = cache.read().unwrap();
//add(&Fixed::x(15, Align::w(Bsp::s(

View file

@ -8,7 +8,7 @@ content!(TuiOut: |self: MidiEditor| {
impl MidiEditor {
pub fn clip_status (&self) -> impl Content<TuiOut> + '_ {
pub fn clip_status (&self) -> impl Render<TuiOut> + '_ {
let (_color, name, length, looped) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) {
(clip.color, clip.name.clone(), clip.length, clip.looped)
} else { (ItemTheme::G[64], String::new().into(), 0, false) };
@ -25,7 +25,7 @@ impl MidiEditor {
))
}
pub fn edit_status (&self) -> impl Content<TuiOut> + '_ {
pub fn edit_status (&self) -> impl Render<TuiOut> + '_ {
let (_color, length) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) {
(clip.color, clip.length)
} else { (ItemTheme::G[64], 0) };

View file

@ -139,7 +139,7 @@ impl PianoHorizontal {
}
}
fn notes (&self) -> impl Content<TuiOut> {
fn notes (&self) -> impl Render<TuiOut> {
let time_start = self.get_time_start();
let note_lo = self.get_note_lo();
let note_hi = self.get_note_hi();
@ -170,7 +170,7 @@ impl PianoHorizontal {
}
})
}
fn cursor (&self) -> impl Content<TuiOut> {
fn cursor (&self) -> impl Render<TuiOut> {
let note_hi = self.get_note_hi();
let note_lo = self.get_note_lo();
let note_pos = self.get_note_pos();
@ -201,7 +201,7 @@ impl PianoHorizontal {
}
})
}
fn keys (&self) -> impl Content<TuiOut> {
fn keys (&self) -> impl Render<TuiOut> {
let state = self;
let color = state.color;
let note_lo = state.get_note_lo();
@ -225,7 +225,7 @@ impl PianoHorizontal {
}
})))
}
fn timeline (&self) -> impl Content<TuiOut> + '_ {
fn timeline (&self) -> impl Render<TuiOut> + '_ {
Fill::x(Fixed::y(1, ThunkRender::new(move|to: &mut TuiOut|{
let [x, y, w, _h] = to.area();
let style = Some(Style::default().dim());

View file

@ -48,8 +48,10 @@ macro_rules! def_sizes_iter {
#[cfg(feature = "vst3")] mod vst3; #[cfg(feature = "vst3")] pub use self::vst3::*;
pub fn button_2 <'a> (
key: impl Content<TuiOut> + 'a, label: impl Content<TuiOut> + 'a, editing: bool,
) -> impl Content<TuiOut> + 'a {
key: impl Render<TuiOut> + 'a,
label: impl Render<TuiOut> + 'a,
editing: bool,
) -> impl Render<TuiOut> + 'a {
let key = Tui::fg_bg(Tui::orange(), Tui::g(0), Bsp::e(
Tui::fg(Tui::g(0), ""),
Bsp::e(key, Tui::fg(Tui::g(96), ""))
@ -58,16 +60,12 @@ pub fn button_2 <'a> (
Tui::bold(true, Bsp::e(key, label))
}
pub fn button_3 <'a, K, L, V> (
key: K,
label: L,
value: V,
pub fn button_3 <'a> (
key: impl Render<TuiOut> + 'a,
label: impl Render<TuiOut> + 'a,
value: impl Render<TuiOut> + 'a,
editing: bool,
) -> impl Content<TuiOut> + 'a where
K: Content<TuiOut> + 'a,
L: Content<TuiOut> + 'a,
V: Content<TuiOut> + 'a,
{
) -> impl Render<TuiOut> + 'a {
let key = Tui::fg_bg(Tui::orange(), Tui::g(0),
Bsp::e(Tui::fg(Tui::g(0), ""), Bsp::e(key, Tui::fg(if editing {
Tui::g(128)

View file

@ -1,7 +1,7 @@
use crate::*;
use super::*;
impl Content<TuiOut> for Lv2 {
impl Render<TuiOut> for Lv2 {
fn render (&self, to: &mut TuiOut) {
let area = to.area();
let [x, y, _, height] = area;

View file

@ -53,7 +53,7 @@ pub fn to_rms (samples: &[f32]) -> f32 {
(sum / samples.len() as f32).sqrt()
}
pub fn view_meter <'a> (label: &'a str, value: f32) -> impl Content<TuiOut> + 'a {
pub fn view_meter <'a> (label: &'a str, value: f32) -> impl Render<TuiOut> + 'a {
col!(
FieldH(ItemTheme::G[128], label, format!("{:>+9.3}", value)),
Fixed::xy(if value >= 0.0 { 13 }
@ -74,7 +74,7 @@ pub fn view_meter <'a> (label: &'a str, value: f32) -> impl Content<TuiOut> + 'a
else { Green }, ())))
}
pub fn view_meters (values: &[f32;2]) -> impl Content<TuiOut> + use<'_> {
pub fn view_meters (values: &[f32;2]) -> impl Render<TuiOut> + use<'_> {
let left = format!("L/{:>+9.3}", values[0]);
let right = format!("R/{:>+9.3}", values[1]);
Bsp::s(left, right)

View file

@ -143,7 +143,7 @@ fn scan (dir: &PathBuf) -> Usually<(Vec<OsString>, Vec<OsString>)> {
Ok((subdirs, files))
}
impl Content<TuiOut> for AddSampleModal {
impl Render<TuiOut> for AddSampleModal {
fn render (&self, _to: &mut TuiOut) {
todo!()
//let area = to.area();

View file

@ -2,7 +2,7 @@ use crate::*;
impl Sampler {
pub fn view_grid (&self) -> impl Content<TuiOut> + use<'_> {
pub fn view_grid (&self) -> impl Render<TuiOut> + use<'_> {
let cells_x = 8u16;
let cells_y = 8u16;
let cell_width = 10u16;
@ -23,7 +23,7 @@ impl Sampler {
pub fn view_grid_cell <'a> (
&'a self, name: &'a str, x: u16, y: u16, w: u16, h: u16
) -> impl Content<TuiOut> + use<'a> {
) -> impl Render<TuiOut> + use<'a> {
let cursor = self.cursor();
let hi_fg = Color::Rgb(64, 64, 64);
let hi_bg = if y == 0 { Color::Reset } else { Color::Rgb(64, 64, 64) /*prev*/ };
@ -55,7 +55,7 @@ impl Sampler {
pub fn view_list <'a, T: NotePoint + NoteRange> (
&'a self, compact: bool, editor: &T
) -> impl Content<TuiOut> + 'a {
) -> impl Render<TuiOut> + 'a {
let note_lo = editor.get_note_lo();
let note_pt = editor.get_note_pos();
let note_hi = editor.get_note_hi();
@ -97,7 +97,7 @@ impl Sampler {
}
}
pub fn view_sample (&self, note_pt: usize) -> impl Content<TuiOut> + use<'_> {
pub fn view_sample (&self, note_pt: usize) -> impl Render<TuiOut> + use<'_> {
Outer(true, Style::default().fg(Tui::g(96)))
.enclose(Fill::xy(draw_viewer(if let Some((_, Some(sample))) = &self.recording {
Some(sample)
@ -108,7 +108,7 @@ impl Sampler {
})))
}
pub fn view_sample_info (&self, note_pt: usize) -> impl Content<TuiOut> + use<'_> {
pub fn view_sample_info (&self, note_pt: usize) -> impl Render<TuiOut> + use<'_> {
Fill::x(Fixed::y(1, draw_info(if let Some((_, Some(sample))) = &self.recording {
Some(sample)
} else if let Some(sample) = &self.mapped[note_pt] {
@ -118,7 +118,7 @@ impl Sampler {
})))
}
pub fn view_sample_status (&self, note_pt: usize) -> impl Content<TuiOut> + use<'_> {
pub fn view_sample_status (&self, note_pt: usize) -> impl Render<TuiOut> + use<'_> {
Fixed::x(20, draw_info_v(if let Some((_, Some(sample))) = &self.recording {
Some(sample)
} else if let Some(sample) = &self.mapped[note_pt] {
@ -128,20 +128,20 @@ impl Sampler {
}))
}
pub fn view_status (&self, index: usize) -> impl Content<TuiOut> {
pub fn view_status (&self, index: usize) -> impl Render<TuiOut> {
draw_status(self.mapped[index].as_ref())
}
pub fn view_meters_input (&self) -> impl Content<TuiOut> + use<'_> {
pub fn view_meters_input (&self) -> impl Render<TuiOut> + use<'_> {
draw_meters(&self.input_meters)
}
pub fn view_meters_output (&self) -> impl Content<TuiOut> + use<'_> {
pub fn view_meters_output (&self) -> impl Render<TuiOut> + use<'_> {
draw_meters(&self.output_meters)
}
}
fn draw_meters (meters: &[f32]) -> impl Content<TuiOut> + use<'_> {
fn draw_meters (meters: &[f32]) -> impl Render<TuiOut> + use<'_> {
Tui::bg(Black, Fixed::x(2, Map::east(1, ||meters.iter(), |value, _index|{
Fill::y(RmsMeter(*value))
})))
@ -163,7 +163,7 @@ fn draw_list_item (sample: &Option<Arc<RwLock<Sample>>>) -> String {
}
}
fn draw_viewer (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> + use<'_> {
fn draw_viewer (sample: Option<&Arc<RwLock<Sample>>>) -> impl Render<TuiOut> + use<'_> {
let min_db = -64.0;
ThunkRender::new(move|to: &mut TuiOut|{
let [x, y, width, height] = to.area();
@ -218,7 +218,7 @@ fn draw_viewer (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> +
})
}
fn draw_info (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> + use<'_> {
fn draw_info (sample: Option<&Arc<RwLock<Sample>>>) -> impl Render<TuiOut> + use<'_> {
When(sample.is_some(), Thunk::new(move||{
let sample = sample.unwrap().read().unwrap();
let theme = sample.color;
@ -233,7 +233,7 @@ fn draw_info (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> + us
}))
}
fn draw_info_v (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> + use<'_> {
fn draw_info_v (sample: Option<&Arc<RwLock<Sample>>>) -> impl Render<TuiOut> + use<'_> {
Either(sample.is_some(), Thunk::new(move||{
let sample = sample.unwrap().read().unwrap();
let theme = sample.color;
@ -252,7 +252,7 @@ fn draw_info_v (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> +
))))
}
fn draw_status (sample: Option<&Arc<RwLock<Sample>>>) -> impl Content<TuiOut> {
fn draw_status (sample: Option<&Arc<RwLock<Sample>>>) -> impl Render<TuiOut> {
Tui::bold(true, Tui::fg(Tui::g(224), sample
.map(|sample|{
let sample = sample.read().unwrap();

View file

@ -38,7 +38,7 @@ pub trait HasPlayClip: HasClock {
*self.reset_mut() = true;
}
fn play_status (&self) -> impl Content<TuiOut> {
fn play_status (&self) -> impl Render<TuiOut> {
let (name, color): (Arc<str>, ItemTheme) = if let Some((_, Some(clip))) = self.play_clip() {
let MidiClip { ref name, color, .. } = *clip.read().unwrap();
(name.clone(), color)
@ -51,7 +51,7 @@ pub trait HasPlayClip: HasClock {
FieldV(color, "Now:", format!("{} {}", time, name))
}
fn next_status (&self) -> impl Content<TuiOut> {
fn next_status (&self) -> impl Render<TuiOut> {
let mut time: Arc<str> = String::from("--.-.--").into();
let mut name: Arc<str> = String::from("").into();
let mut color = ItemTheme::G[64];