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 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 {
|
||||
sr: ViewMemo<Option<(bool, 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)); {
|
||||
":editor" => (&self.editor).boxed(),
|
||||
":pool" => self.view_pool().boxed(),
|
||||
|
|
@ -97,7 +103,8 @@ impl Tek {
|
|||
let pulse = clock.timebase.usecs_to_pulse(now);
|
||||
let time = now/1000000.;
|
||||
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.bpm.update(Some(bpm), rewrite!(buf, "{:.3}", bpm));
|
||||
} else {
|
||||
|
|
@ -182,8 +189,8 @@ impl Tek {
|
|||
fn view_row <'a> (
|
||||
&'a self, w: u16, h: u16, a: impl Content<TuiOut> + 'a, b: impl Content<TuiOut> + 'a
|
||||
) -> impl Content<TuiOut> + 'a {
|
||||
Fixed::y(h, Bsp::e(
|
||||
Fixed::x(self.w_sidebar() as u16, a),
|
||||
Fixed::y(h, Bsp::a(
|
||||
Fill::x(Align::w(Fixed::x(self.w_sidebar() as u16, a))),
|
||||
Fill::x(Align::c(Fixed::xy(w, h, b)))
|
||||
))
|
||||
}
|
||||
|
|
@ -191,7 +198,12 @@ impl Tek {
|
|||
let fg = Tui::g(224);
|
||||
let bg = Tui::g(64);
|
||||
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!(
|
||||
self,
|
||||
" I ",
|
||||
" midi ins",
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
(bsp/s (max/y 1 :toolbar)
|
||||
(fill/x (align/c (bsp/w (fixed/x :pool-w :pool)
|
||||
(bsp/n
|
||||
(bsp/s :scene-add (bsp/s :tracks (bsp/n :inputs :outputs)))
|
||||
:scenes)))))
|
||||
(bsp/a (fill/xy (align/n (max/y 1 :toolbar)))
|
||||
(fill/x (align/c (bsp/a (fill/xy (align/e (fixed/x :pool-w :pool)))
|
||||
(bsp/a
|
||||
(fill/xy (align/s (bsp/s :scene-add (bsp/s :tracks (bsp/n :inputs :outputs)))))
|
||||
(fill/xy :scenes))))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue