mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
overlays
This commit is contained in:
parent
85507bf27e
commit
c13eff95ca
2 changed files with 39 additions and 27 deletions
|
|
@ -1,5 +1,25 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
#[derive(Debug, Default)] struct ViewMemo<T, U> {
|
||||||
|
value: T,
|
||||||
|
view: Arc<RwLock<U>>
|
||||||
|
}
|
||||||
|
impl<T: PartialEq, U> ViewMemo<T, U> {
|
||||||
|
fn new (value: T, view: U) -> Self {
|
||||||
|
Self {
|
||||||
|
value,
|
||||||
|
view: Arc::new(view.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn update <R> (&mut self, newval: T, render: impl Fn(&mut U, &T, &T)->R) -> Option<R> {
|
||||||
|
if newval != self.value {
|
||||||
|
let result = render(&mut*self.view.write().unwrap(), &newval, &self.value);
|
||||||
|
self.value = newval;
|
||||||
|
return Some(result);
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
#[derive(Debug)] pub(crate) struct ViewCache {
|
#[derive(Debug)] pub(crate) struct ViewCache {
|
||||||
sr: ViewMemo<Option<(bool, f64)>, String>,
|
sr: ViewMemo<Option<(bool, f64)>, String>,
|
||||||
buf: ViewMemo<Option<f64>, String>,
|
buf: ViewMemo<Option<f64>, String>,
|
||||||
|
|
@ -26,20 +46,6 @@ impl Default for ViewCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Debug, Default)] struct ViewMemo<T, U> { value: T, view: Arc<RwLock<U>> }
|
|
||||||
impl<T, U> ViewMemo<T, U> {
|
|
||||||
fn new (value: T, view: U) -> Self { Self { value, view: Arc::new(view.into()) } }
|
|
||||||
}
|
|
||||||
impl<T: PartialEq, U> ViewMemo<T, U> {
|
|
||||||
fn update <R> (&mut self, newval: T, render: impl Fn(&mut U, &T, &T)->R) -> Option<R> {
|
|
||||||
if newval != self.value {
|
|
||||||
let result = render(&mut*self.view.write().unwrap(), &newval, &self.value);
|
|
||||||
self.value = newval;
|
|
||||||
return Some(result);
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
view!(TuiOut: |self: Tek| self.size.of(View(self, self.view)); {
|
view!(TuiOut: |self: Tek| self.size.of(View(self, self.view)); {
|
||||||
":editor" => (&self.editor).boxed(),
|
":editor" => (&self.editor).boxed(),
|
||||||
":pool" => self.view_pool().boxed(),
|
":pool" => self.view_pool().boxed(),
|
||||||
|
|
@ -97,7 +103,8 @@ impl Tek {
|
||||||
let pulse = clock.timebase.usecs_to_pulse(now);
|
let pulse = clock.timebase.usecs_to_pulse(now);
|
||||||
let time = now/1000000.;
|
let time = now/1000000.;
|
||||||
let bpm = clock.timebase.bpm.get();
|
let bpm = clock.timebase.bpm.get();
|
||||||
fmtd.beat.update(Some(pulse), |buf, _, _|clock.timebase.format_beats_1_to(buf, pulse));
|
fmtd.beat.update(Some(pulse),
|
||||||
|
|buf, _, _|{buf.clear();clock.timebase.format_beats_1_to(buf, pulse)});
|
||||||
fmtd.time.update(Some(time), rewrite!(buf, "{:.3}s", time));
|
fmtd.time.update(Some(time), rewrite!(buf, "{:.3}s", time));
|
||||||
fmtd.bpm.update(Some(bpm), rewrite!(buf, "{:.3}", bpm));
|
fmtd.bpm.update(Some(bpm), rewrite!(buf, "{:.3}", bpm));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -182,8 +189,8 @@ impl Tek {
|
||||||
fn view_row <'a> (
|
fn view_row <'a> (
|
||||||
&'a self, w: u16, h: u16, a: impl Content<TuiOut> + 'a, b: impl Content<TuiOut> + 'a
|
&'a self, w: u16, h: u16, a: impl Content<TuiOut> + 'a, b: impl Content<TuiOut> + 'a
|
||||||
) -> impl Content<TuiOut> + 'a {
|
) -> impl Content<TuiOut> + 'a {
|
||||||
Fixed::y(h, Bsp::e(
|
Fixed::y(h, Bsp::a(
|
||||||
Fixed::x(self.w_sidebar() as u16, a),
|
Fill::x(Align::w(Fixed::x(self.w_sidebar() as u16, a))),
|
||||||
Fill::x(Align::c(Fixed::xy(w, h, b)))
|
Fill::x(Align::c(Fixed::xy(w, h, b)))
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -191,11 +198,16 @@ impl Tek {
|
||||||
let fg = Tui::g(224);
|
let fg = Tui::g(224);
|
||||||
let bg = Tui::g(64);
|
let bg = Tui::g(64);
|
||||||
let h = 1 + self.midi_ins.len() as u16;
|
let h = 1 + self.midi_ins.len() as u16;
|
||||||
let header: ThunkBox<_> = io_header!(self, " I ", " midi ins", self.midi_ins.len(), self.midi_ins().get(0).map(
|
let header: ThunkBox<_> = io_header!(
|
||||||
move|input: &JackPort<MidiIn>|Bsp::s(
|
self,
|
||||||
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(input.name.clone())))),
|
" I ",
|
||||||
input.connect.get(0).map(|connect|Fill::x(Align::w(Tui::bold(false,
|
" midi ins",
|
||||||
Tui::fg_bg(fg, bg, connect.info()))))))));
|
self.midi_ins.len(),
|
||||||
|
self.midi_ins().get(0).map(
|
||||||
|
move|input: &JackPort<MidiIn>|Bsp::s(
|
||||||
|
Fill::x(Tui::bold(true, Tui::fg_bg(fg, bg, Align::w(input.name.clone())))),
|
||||||
|
input.connect.get(0).map(|connect|Fill::x(Align::w(Tui::bold(false,
|
||||||
|
Tui::fg_bg(fg, bg, connect.info()))))))));
|
||||||
let rec = false;
|
let rec = false;
|
||||||
let mon = false;
|
let mon = false;
|
||||||
let cells: ThunkBox<_> = per_track!(|self, track, _t|Bsp::s(Tui::bold(true, row!(
|
let cells: ThunkBox<_> = per_track!(|self, track, _t|Bsp::s(Tui::bold(true, row!(
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
(bsp/s (max/y 1 :toolbar)
|
(bsp/a (fill/xy (align/n (max/y 1 :toolbar)))
|
||||||
(fill/x (align/c (bsp/w (fixed/x :pool-w :pool)
|
(fill/x (align/c (bsp/a (fill/xy (align/e (fixed/x :pool-w :pool)))
|
||||||
(bsp/n
|
(bsp/a
|
||||||
(bsp/s :scene-add (bsp/s :tracks (bsp/n :inputs :outputs)))
|
(fill/xy (align/s (bsp/s :scene-add (bsp/s :tracks (bsp/n :inputs :outputs)))))
|
||||||
:scenes)))))
|
(fill/xy :scenes))))))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue