mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
remove some more string allocations from render loop
This commit is contained in:
parent
f5d84c2450
commit
f7dcc28e1f
1 changed files with 21 additions and 15 deletions
|
|
@ -534,18 +534,22 @@ impl Tek {
|
||||||
map_east(x1 as u16, w, border(Map::new(scenes, move|(_, scene, y1, y2), s| {
|
map_east(x1 as u16, w, border(Map::new(scenes, move|(_, scene, y1, y2), s| {
|
||||||
let last_color = last_color.clone();
|
let last_color = last_color.clone();
|
||||||
let h = (1 + y2 - y1) as u16;
|
let h = (1 + y2 - y1) as u16;
|
||||||
let color = scene.color;
|
let color = scene.color;
|
||||||
let (name, fg, bg) = if let Some(c) = &scene.clips[t] {
|
let mut name = String::from("⏹ ");
|
||||||
let c = c.read().unwrap();
|
let mut fg = Tui::g(64);
|
||||||
(c.name.to_string(), c.color.lightest.rgb, c.color)
|
let mut bg = ItemPalette::G[32];
|
||||||
} else {
|
if let Some(clip) = &scene.clips[t] {
|
||||||
("⏹ ".to_string(), Tui::g(64), ItemPalette::G[32])
|
let clip = clip.read().unwrap();
|
||||||
|
name.clear();
|
||||||
|
write!(&mut name, "{}", clip.name);
|
||||||
|
fg = clip.color.lightest.rgb;
|
||||||
|
bg = clip.color
|
||||||
};
|
};
|
||||||
let same_track = selected_track == Some(t+1);
|
let same_track = selected_track == Some(t+1);
|
||||||
let selected = same_track && Some(s+1) == selected_scene;
|
let selected = same_track && Some(s+1) == selected_scene;
|
||||||
let neighbor = same_track && Some(s) == selected_scene;
|
let neighbor = same_track && Some(s) == selected_scene;
|
||||||
let active = editing && selected;
|
let active = editing && selected;
|
||||||
let label = move||Tui::fg(fg, Push::x(1, Tui::bold(true, name.to_string())));
|
let label = move||Tui::fg(fg, Push::x(1, Tui::bold(true, name.clone())));
|
||||||
let mid = if active { bg.light } else { bg.base };
|
let mid = if active { bg.light } else { bg.base };
|
||||||
let top = if neighbor { None } else { Some(last_color.read().unwrap().base.rgb) };
|
let top = if neighbor { None } else { Some(last_color.read().unwrap().base.rgb) };
|
||||||
let mid = mid.rgb;
|
let mid = mid.rgb;
|
||||||
|
|
@ -553,10 +557,10 @@ impl Tek {
|
||||||
*last_color.write().unwrap() = bg;
|
*last_color.write().unwrap() = bg;
|
||||||
map_south(y1 as u16, h, Push::y(1, Fixed::y(h, Either::new(active,
|
map_south(y1 as u16, h, Push::y(1, Fixed::y(h, Either::new(active,
|
||||||
Thunk::new(||Bsp::a(
|
Thunk::new(||Bsp::a(
|
||||||
Fill::xy(Align::nw(button(" Tab ".into(), "".into()))),
|
Fill::xy(Align::nw(button(" Tab ", ""))),
|
||||||
&self.editor)),
|
&self.editor)),
|
||||||
Thunk::new(move||Bsp::a(
|
Thunk::new(move||Bsp::a(
|
||||||
When::new(selected, Fill::y(Align::n(button(" Tab ".into(), "edit".into())))),
|
When::new(selected, Fill::y(Align::n(button(" Tab ", "edit")))),
|
||||||
phat_sel_3(selected, label(), label(), top, mid, low)
|
phat_sel_3(selected, label(), label(), top, mid, low)
|
||||||
)),
|
)),
|
||||||
))))
|
))))
|
||||||
|
|
@ -592,7 +596,7 @@ impl Tek {
|
||||||
fn input_header <'a> (&'a self) -> ThunkBox<'a, TuiOut> {
|
fn input_header <'a> (&'a self) -> ThunkBox<'a, TuiOut> {
|
||||||
let fg = Tui::g(224);
|
let fg = Tui::g(224);
|
||||||
let bg = Tui::g(64);
|
let bg = Tui::g(64);
|
||||||
(move||Bsp::s(Fill::x(Align::w(self.button(" I ".to_string(), format!(" midi ins ({})", self.midi_ins().len())))), self.midi_ins().get(0).map(|inp|Bsp::s(
|
(move||Bsp::s(Fill::x(Align::w(self.button(" I ", format!(" midi ins ({})", self.midi_ins().len())))), self.midi_ins().get(0).map(|inp|Bsp::s(
|
||||||
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(inp.name.clone())))),
|
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(inp.name.clone())))),
|
||||||
inp.connect.get(0).map(|connect|Fill::x(Align::w(Tui::bold(false,
|
inp.connect.get(0).map(|connect|Fill::x(Align::w(Tui::bold(false,
|
||||||
Tui::fg_bg(fg, bg, connect.info()))))),
|
Tui::fg_bg(fg, bg, connect.info()))))),
|
||||||
|
|
@ -601,17 +605,17 @@ impl Tek {
|
||||||
fn output_header <'a> (&'a self) -> ThunkBox<'a, TuiOut> {
|
fn output_header <'a> (&'a self) -> ThunkBox<'a, TuiOut> {
|
||||||
let fg = Tui::g(224);
|
let fg = Tui::g(224);
|
||||||
let bg = Tui::g(64);
|
let bg = Tui::g(64);
|
||||||
(move||Bsp::s(Fill::x(Align::w(self.button(" O ".to_string(), format!(" midi outs ({}) ", self.midi_outs().len())))), self.midi_outs().get(0).map(|out|Bsp::s(
|
(move||Bsp::s(Fill::x(Align::w(self.button(" O ", format!(" midi outs ({}) ", self.midi_outs().len())))), self.midi_outs().get(0).map(|out|Bsp::s(
|
||||||
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(out.name.clone())))),
|
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(out.name.clone())))),
|
||||||
out.connect.get(0).map(|connect|Fill::x(Align::w(Tui::bold(false,
|
out.connect.get(0).map(|connect|Fill::x(Align::w(Tui::bold(false,
|
||||||
Tui::fg_bg(fg, bg, connect.info()))))),
|
Tui::fg_bg(fg, bg, connect.info()))))),
|
||||||
))).boxed()).into()
|
))).boxed()).into()
|
||||||
}
|
}
|
||||||
fn track_header <'a> (&'a self) -> ThunkBox<'a, TuiOut> {
|
fn track_header <'a> (&'a self) -> ThunkBox<'a, TuiOut> {
|
||||||
let add_scene = ||self.button(" C-a ".to_string(), format!(" add scene ({}/{})",
|
let add_scene = ||self.button(" C-a ", format!(" add scene ({}/{})",
|
||||||
self.selected.scene().unwrap_or(0),
|
self.selected.scene().unwrap_or(0),
|
||||||
self.scenes().len()));
|
self.scenes().len()));
|
||||||
let add_track = ||self.button(" C-t ".to_string(), format!(" add track ({}/{})",
|
let add_track = ||self.button(" C-t ", format!(" add track ({}/{})",
|
||||||
self.selected.track().unwrap_or(0),
|
self.selected.track().unwrap_or(0),
|
||||||
self.tracks().len()));
|
self.tracks().len()));
|
||||||
(move||Tui::bg(Tui::g(32), Bsp::s(
|
(move||Tui::bg(Tui::g(32), Bsp::s(
|
||||||
|
|
@ -619,7 +623,9 @@ impl Tek {
|
||||||
Fill::x(Align::w(add_track())),
|
Fill::x(Align::w(add_track())),
|
||||||
)).boxed()).into()
|
)).boxed()).into()
|
||||||
}
|
}
|
||||||
fn button (&self, key: String, label: String) -> impl Content<TuiOut> {
|
fn button <'a> (
|
||||||
|
&'a self, key: impl Content<TuiOut> + 'a, label: impl Content<TuiOut> + 'a
|
||||||
|
) -> impl Content<TuiOut> + 'a {
|
||||||
let compact = !self.is_editing();
|
let compact = !self.is_editing();
|
||||||
Tui::bold(true, Bsp::e(
|
Tui::bold(true, Bsp::e(
|
||||||
Margin::x(1, Tui::fg_bg(Tui::g(0), Tui::orange(), key)),
|
Margin::x(1, Tui::fg_bg(Tui::g(0), Tui::orange(), key)),
|
||||||
|
|
@ -1269,7 +1275,7 @@ audio!(|self: Tek, client, scope|{
|
||||||
self.perf.update(t0, scope);
|
self.perf.update(t0, scope);
|
||||||
Control::Continue
|
Control::Continue
|
||||||
});
|
});
|
||||||
fn button (key: String, label: String) -> impl Content<TuiOut> {
|
fn button (key: &'static str, label: &'static str) -> impl Content<TuiOut> + 'static {
|
||||||
Tui::bold(true, Bsp::e(
|
Tui::bold(true, Bsp::e(
|
||||||
Margin::x(1, Tui::fg_bg(Tui::g(0), Tui::orange(), key)),
|
Margin::x(1, Tui::fg_bg(Tui::g(0), Tui::orange(), key)),
|
||||||
Margin::x(1, Tui::fg_bg(Tui::g(255), Tui::g(96), label)),
|
Margin::x(1, Tui::fg_bg(Tui::g(255), Tui::g(96), label)),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue