use Arc<str> where applicable; use konst split_at

This commit is contained in:
🪞👃🪞 2025-01-08 00:24:40 +01:00
parent 411fc0c4bc
commit 305481adee
35 changed files with 286 additions and 273 deletions

View file

@ -3,27 +3,25 @@ pub(crate) const HEADER_H: u16 = 0; // 5
pub(crate) const SCENES_W_OFFSET: u16 = 0;
render!(TuiOut: (self: Arranger) => {
let toolbar = |x|Bsp::s(self.toolbar_view(), x);
let status = |x|Bsp::n(self.status_view(), x);
let pool = |x|Bsp::w(self.pool_view(), x);
let editing = |x|Bsp::n(self.editor_status_view(), x);
let editing = |x|Bsp::n(Bsp::e(self.editor.clip_status(), self.editor.edit_status()), x);
let enclosed = |x|Outer(Style::default().fg(Color::Rgb(72,72,72))).enclose(x);
let editor = Fixed::y(20, enclosed(&self.editor));
let scenes_w = 16;//.max(SCENES_W_OFFSET + ArrangerScene::longest_name(&self.scenes) as u16);
let arrrrrr = Fixed::y(32, Map::new(
let arrrrrr = Fixed::y(27, Map::new(
move||[
(0, 2, self.output_row_header(), self.output_row_cells()),
(2, 2, self.elapsed_row_header(), self.elapsed_row_cells()),
(4, 2, self.next_row_header(), self.next_row_cells()),
(2, 3, self.elapsed_row_header(), self.elapsed_row_cells()),
(4, 3, self.next_row_header(), self.next_row_cells()),
(6, 3, self.track_row_header(), self.track_row_cells()),
(9, 20, self.scene_row_headers(), self.scene_row_cells()),
(29, 2, self.input_row_header(), self.input_row_cells()),
(8, 20, self.scene_row_headers(), self.scene_row_cells()),
(25, 2, self.input_row_header(), self.input_row_cells()),
].into_iter(),
move|(y, h, header, cells), index|map_south(y, h, Fill::x(Align::w(Bsp::e(
Fixed::xy(scenes_w, h, header),
Fixed::xy(self.tracks.len() as u16*6, h, cells)
))))));
self.size.of(toolbar(status(pool(editing(Bsp::n(editor, arrrrrr))))))
self.size.of(toolbar(pool(editing(Bsp::s(arrrrrr, enclosed(&self.editor))))))
});
impl Arranger {
@ -63,7 +61,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!("MutSol"), Self::phat_hi(color.dark.rgb, color.darker.rgb));
let cell = Bsp::s(format!(" M S "), Self::phat_hi(color.dark.rgb, color.darker.rgb));
map_east(x1 as u16, w, Fixed::x(w, Self::cell(color, cell)))
})).boxed()).into()
}
@ -73,19 +71,17 @@ impl Arranger {
}
fn elapsed_row_cells <'a> (&'a self) -> BoxThunk<'a, TuiOut> {
(move||Fixed::y(2, Map::new(||self.tracks_with_widths(), move|(_, track, x1, x2), i| {
let color = track.color();
//let color = track.color();
let color: ItemPalette = track.color().dark.into();
let timebase = self.clock().timebase();
let elapsed = {
let mut result = String::new();
let value = Tui::fg_bg(color.lightest.rgb, color.base.rgb,
if let Some((_, Some(phrase))) = track.player.play_phrase().as_ref() {
let length = phrase.read().unwrap().length;
let elapsed = track.player.pulses_since_start().unwrap() as usize;
result = format!("+{:>}", timebase.format_beats_1_short((elapsed % length) as f64))
}
result
};
let value = Tui::fg_bg(color.lightest.rgb, color.base.rgb, elapsed);
format!("+{:>}", timebase.format_beats_1_short((elapsed % length) as f64))
} else {
String::new()
});
let cell = Bsp::s(value, Self::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()
@ -109,12 +105,14 @@ impl Arranger {
(||Tui::bold(true, Tui::fg(TuiTheme::g(128), "Track")).boxed()).into()
}
fn track_row_cells <'a> (&'a self) -> BoxThunk<'a, TuiOut> {
(move||Fixed::y(2, Map::new(||self.tracks_with_widths(), move|(_, track, x1, x2), i| {
let iter = ||self.tracks_with_widths();
(move||Fixed::y(2, Map::new(iter, move|(_, track, x1, x2), i| {
let color = track.color();
let name = format!(" {}", &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(), Tui::bold(true, format!("{}", track.name.read().unwrap()))))))
})).boxed()).into()
Self::phat_cell(color, color.darkest.rgb.into(),
Tui::bold(true, name))))) })).boxed()).into()
}
fn input_row_header <'a> (&'a self) -> BoxThunk<'a, TuiOut> {
@ -138,7 +136,7 @@ impl Arranger {
move|(_, scene, y1, y2), i| {
let h = (y2 - y1) as u16;
let color = scene.color();
let name = format!(" {}", scene.name.read().unwrap());
let name = format!("🭬{}", &scene.name);
let cell = Self::phat_cell(color, *last_color.read().unwrap(), name);
*last_color.write().unwrap() = color;
map_south(y1 as u16, 2, Fill::x(cell))
@ -147,7 +145,7 @@ impl Arranger {
}).into()
}
fn scene_row_cells <'a> (&'a self) -> BoxThunk<'a, TuiOut> {
(||Tui::bg(Color::Rgb(20,40,60), "").boxed()).into()
(||Tui::bg(self.color.darkest.rgb, "").boxed()).into()
}
pub fn tracks_with_widths (&self)
@ -175,8 +173,7 @@ impl Arranger {
}
/// name and width of track
fn cell_name (track: &ArrangerTrack, _w: usize) -> impl Content<TuiOut> {
let name = track.name().read().unwrap().clone();
Tui::bold(true, Tui::fg(track.color.lightest.rgb, name))
Tui::bold(true, Tui::fg(track.color.lightest.rgb, track.name().clone()))
}
/// beats until switchover
fn cell_until_next (track: &ArrangerTrack, current: &Arc<Moment>)
@ -207,7 +204,7 @@ 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.read().unwrap().clone())));
let cell = Fixed::y(h, Fixed::x(scenes_w, Self::cell(color, scene.name.clone())));
map_south(y1 as u16, 1, cell)
})
}
@ -235,7 +232,7 @@ impl Arranger {
scene.color.base.rgb, if playing { "" } else { " " }
);
let name = Tui::fg_bg(scene.color.lightest.rgb, scene.color.base.rgb,
Expand::x(1, Tui::bold(true, scene.name.read().unwrap().clone()))
Expand::x(1, Tui::bold(true, scene.name.clone()))
);
let clips = Map::new(||Arranger::tracks_with_widths_static(tracks), move|(index, track, x1, x2), _|
Push::x((x2 - x1) as u16, Self::cell_clip(scene, index, track, (x2 - x1) as u16, height))
@ -264,20 +261,6 @@ impl Arranger {
fn toolbar_view (&self) -> impl Content<TuiOut> + use<'_> {
Fill::x(Fixed::y(2, Align::x(TransportView::new(true, &self.clock))))
}
fn status_view (&self) -> impl Content<TuiOut> + use<'_> {
ArrangerStatus::from(self)
//let edit_clip = MidiEditClip(&self.editor);
////let selectors = When(false, Bsp::e(ClipSelected::play_phrase(&self.player), ClipSelected::next_phrase(&self.player)));
//row!([>selectors,<] edit_clip, MidiEditStatus(&self.editor))
}
fn editor_status_view (&self) -> impl Content<TuiOut> + use<'_> {
Bsp::e(
//ClipSelected::play_phrase(&self.player),
//ClipSelected::next_phrase(&self.player),
MidiEditClip(&self.editor),
MidiEditStatus(&self.editor),
)
}
fn pool_view (&self) -> impl Content<TuiOut> + use<'_> {
let w = self.size.w();
let phrase_w = if w > 60 { 20 } else if w > 40 { 15 } else { 10 };