instant crash

This commit is contained in:
🪞👃🪞 2025-01-10 01:32:58 +01:00
parent a6643ab990
commit 2401dc8fcd
5 changed files with 105 additions and 122 deletions

View file

@ -21,6 +21,7 @@ pub struct Arranger {
pub note_buf: Vec<u8>,
pub midi_buf: Vec<Vec<Vec<u8>>>,
pub editor: MidiEditor,
pub editing: bool,
pub perf: PerfModel,
pub compact: bool,
}

View file

@ -31,55 +31,6 @@ impl Arranger {
pub const LEFT_SEP: char = '▎';
pub const TRACK_MIN_WIDTH: usize = 4;
/// A 1-row cell.
fn cell <T: Content<TuiOut>> (color: ItemPalette, field: T) -> impl Content<TuiOut> {
Tui::fg_bg(color.lightest.rgb, color.base.rgb, Fixed::y(1, field))
}
/// A phat line
fn phat_lo (fg: Color, bg: Color) -> impl Content<TuiOut> {
Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(&"")))
}
fn phat_hi (fg: Color, bg: Color) -> impl Content<TuiOut> {
Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(&"")))
}
/// A cell that is 3-row on its own, but stacks, giving (N+1)*2 rows per N cells.
fn phat_cell <T: Content<TuiOut>> (
color: ItemPalette, last: ItemPalette, field: T
) -> impl Content<TuiOut> {
Bsp::s(Self::phat_lo(color.base.rgb, last.base.rgb),
Bsp::n(Self::phat_hi(color.base.rgb, last.base.rgb),
Fixed::y(1, Fill::x(Tui::fg_bg(color.lightest.rgb, color.base.rgb, field))),
)
)
}
fn phat_cell_3 <T: Content<TuiOut>> (
field: T, top: Color, middle: Color, bottom: Color
) -> impl Content<TuiOut> {
Bsp::s(Self::phat_lo(middle, top),
Bsp::n(Self::phat_hi(middle, bottom),
Fixed::y(1, Fill::x(Tui::bg(middle, field))),
)
)
}
fn phat_sel_3 <T: Content<TuiOut>> (
selected: bool, field_1: T, field_2: T, top: Option<Color>, middle: Color, bottom: Color
) -> impl Content<TuiOut> {
let border = Style::default().fg(Color::Rgb(255,255,255)).bg(middle);
Either(selected,
Tui::bg(middle, Outer(border).enclose( Align::w(Bsp::s("", Bsp::s(field_1, ""))))),
Bsp::s(
Fixed::y(1, top.map(|top|Self::phat_lo(middle, top))),
Bsp::n(Self::phat_hi(middle, bottom),
Fixed::y(1, Fill::x(Tui::bg(middle, field_2))),
)
))
}
fn output_row_header <'a> (&'a self) -> BoxThunk<'a, TuiOut> {
let fg = TuiTheme::g(192);
let bg = TuiTheme::g(48);
@ -90,7 +41,7 @@ impl Arranger {
(move||Fixed::y(2, Map::new(||self.tracks_with_widths(), move|(_, track, x1, x2), i| {
let w = (x2 - x1) as u16;
let color: ItemPalette = track.color().dark.into();
let cell = Bsp::s(format!(" M S "), Self::phat_hi(color.dark.rgb, color.darker.rgb));
let cell = Bsp::s(format!(" M S "), phat_hi(color.dark.rgb, color.darker.rgb));
map_east(x1 as u16, w, Fixed::x(w, Self::cell(color, cell)))
})).boxed()).into()
}
@ -111,7 +62,7 @@ impl Arranger {
} else {
String::new()
});
let cell = Bsp::s(value, Self::phat_hi(color.dark.rgb, color.darker.rgb));
let cell = Bsp::s(value, phat_hi(color.dark.rgb, color.darker.rgb));
Tui::bg(color.base.rgb, map_east(x1 as u16, (x2 - x1) as u16, cell))
})).boxed()).into()
}
@ -125,7 +76,7 @@ impl Arranger {
let color: ItemPalette = track.color().dark.into();
let until_next = Self::cell(color, Tui::bold(true, Self::cell_until_next(track, &self.clock().playhead)));
let value = Tui::fg_bg(color.lightest.rgb, color.base.rgb, until_next);
let cell = Bsp::s(value, Self::phat_hi(color.dark.rgb, color.darker.rgb));
let cell = Bsp::s(value, phat_hi(color.dark.rgb, color.darker.rgb));
Tui::bg(color.base.rgb, map_east(x1 as u16, (x2 - x1) as u16, cell))
})).boxed()).into()
}
@ -140,7 +91,7 @@ impl Arranger {
let name = Push::x(1, &track.name);
Tui::bg(color.base.rgb, map_east(x1 as u16, (x2 - x1) as u16,
Tui::fg_bg(color.lightest.rgb, color.base.rgb,
Self::phat_cell(color, color.darkest.rgb.into(),
phat_cell(color, color.darkest.rgb.into(),
Tui::bold(true, name))))) })).boxed()).into()
}
@ -170,7 +121,7 @@ impl Arranger {
let h = (y2 - y1) as u16;
let name = format!("🭬{}", &scene.name);
let color = scene.color();
let cell = Self::phat_sel_3(
let cell = phat_sel_3(
selected_scene == Some(i),
Push::x(1, Tui::bold(true, name.clone())),
Push::x(1, Tui::bold(true, name)),
@ -193,7 +144,8 @@ impl Arranger {
}).into()
}
fn scene_row_cells <'a> (&'a self) -> BoxThunk<'a, TuiOut> {
(move||Fixed::y(2, Map::new(||self.tracks_with_widths(), move|(_, track, x1, x2), i| {
let editing = self.editing;
(move||Fixed::y(2, Map::new(||self.tracks_with_widths(), move|(_, track, x1, x2), t| {
let w = (x2 - x1) as u16;
let cell = Bsp::s("[Rec]", "[Mon]");
let color: ItemPalette = track.color().dark.into();
@ -204,21 +156,38 @@ impl Arranger {
};
map_east(x1 as u16, w, Fixed::x(w, Tui::bg(Color::Rgb(0,0,0), Fill::y(Map::new(
||self.scenes_with_heights(2),
move|(_, scene, y1, y2), j| {
move|(_, scene, y1, y2), s| {
let h = (y2 - y1) as u16;
let color = scene.color();
let name = "";
let cell = Self::phat_sel_3(
selected_track == Some(i) && selected_scene == Some(j),
Tui::fg(TuiTheme::g(64), Push::x(1, name)),
Tui::fg(TuiTheme::g(64), Push::x(1, name)),
if selected_track == Some(i) && selected_scene.map(|s|s+1) == Some(j) {
None
} else {
Some(TuiTheme::g(32).into())
},
TuiTheme::g(32).into(),
TuiTheme::g(32).into(),
let last = last_color.read().unwrap().clone();
//let cell = phat_sel_3(
//selected_track == Some(i) && selected_scene == Some(j),
//Tui::fg(TuiTheme::g(64), Push::x(1, name)),
//Tui::fg(TuiTheme::g(64), Push::x(1, name)),
//if selected_track == Some(i) && selected_scene.map(|s|s+1) == Some(j) {
//None
//} else {
//Some(TuiTheme::g(32).into())
//},
//TuiTheme::g(32).into(),
//TuiTheme::g(32).into(),
//);
let active = editing && selected_track == Some(t) && selected_scene == Some(s);
let cell = Either(active,
Thunk::new(||&self.editor),
Thunk::new(move||phat_sel_3(
selected_track == Some(t) && selected_scene == Some(s),
Tui::fg(TuiTheme::g(64), Push::x(1, Tui::bold(true, name.to_string()))),
Tui::fg(TuiTheme::g(64), Push::x(1, Tui::bold(true, name.to_string()))),
if selected_track == Some(t) && selected_scene.map(|s|s+1) == Some(s) {
None
} else {
Some(TuiTheme::g(32).into())
},
TuiTheme::g(32).into(),
TuiTheme::g(32).into(),
))
);
map_south(y1 as u16, 3, Fill::x(cell))
}
@ -283,7 +252,8 @@ impl Arranger {
Map::new(||self.scenes_with_heights(1), move|(_, scene, y1, y2), i| {
let h = (y2 - y1) as u16;
let color = scene.color();
let cell = Fixed::y(h, Fixed::x(scenes_w, Self::cell(color, scene.name.clone())));
let cell = Self::cell(color, scene.name.clone());
let cell = Fixed::y(h, Fixed::x(scenes_w, cell));
map_south(y1 as u16, 1, cell)
})
}
@ -439,6 +409,51 @@ impl Arranger {
};
})
}
/// A 1-row cell.
fn cell <T: Content<TuiOut>> (color: ItemPalette, field: T) -> impl Content<TuiOut> {
Tui::fg_bg(color.lightest.rgb, color.base.rgb, Fixed::y(1, field))
}
}
/// A phat line
fn phat_lo (fg: Color, bg: Color) -> impl Content<TuiOut> {
Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(&"")))
}
/// A phat line
fn phat_hi (fg: Color, bg: Color) -> impl Content<TuiOut> {
Fixed::y(1, Tui::fg_bg(fg, bg, RepeatH(&"")))
}
/// A cell that is 3-row on its own, but stacks, giving (N+1)*2 rows per N cells.
fn phat_cell <T: Content<TuiOut>> (
color: ItemPalette, last: ItemPalette, field: T
) -> impl Content<TuiOut> {
Bsp::s(phat_lo(color.base.rgb, last.base.rgb),
Bsp::n(phat_hi(color.base.rgb, last.base.rgb),
Fixed::y(1, Fill::x(Tui::fg_bg(color.lightest.rgb, color.base.rgb, field))),
)
)
}
fn phat_cell_3 <T: Content<TuiOut>> (
field: T, top: Color, middle: Color, bottom: Color
) -> impl Content<TuiOut> {
Bsp::s(phat_lo(middle, top),
Bsp::n(phat_hi(middle, bottom),
Fixed::y(1, Fill::x(Tui::bg(middle, field))),
)
)
}
fn phat_sel_3 <T: Content<TuiOut>> (
selected: bool, field_1: T, field_2: T, top: Option<Color>, middle: Color, bottom: Color
) -> impl Content<TuiOut> {
let border = Style::default().fg(Color::Rgb(255,255,255)).bg(middle);
Either(selected,
Tui::bg(middle, Outer(border).enclose( Align::w(Bsp::s("", Bsp::s(field_1, ""))))),
Bsp::s(
Fixed::y(1, top.map(|top|phat_lo(middle, top))),
Bsp::n(phat_hi(middle, bottom),
Fixed::y(1, Fill::x(Tui::bg(middle, field_2))),
)
))
}
//pub struct ArrangerVCursor {