mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-08-07 22:17:07 +02:00
wip: simplify and document
This commit is contained in:
parent
701a651fbd
commit
b9e7b9732e
12 changed files with 116 additions and 72 deletions
|
|
@ -16,9 +16,9 @@ use crate::*;
|
|||
/// TODO rename to "render_cache" or smth
|
||||
pub arranger: Arc<RwLock<Buffer>>,
|
||||
/// Display size
|
||||
pub size: Size,
|
||||
pub size: Sizer,
|
||||
/// Display size of clips area
|
||||
pub size_inner: Size,
|
||||
pub size_inner: Sizer,
|
||||
/// Source of time
|
||||
#[cfg(feature = "clock")] pub clock: Clock,
|
||||
/// Allows one MIDI clip to be edited
|
||||
|
|
@ -47,7 +47,7 @@ use crate::*;
|
|||
|
||||
impl HasJack<'static> for Arrangement { fn jack (&self) -> &Jack<'static> { &self.jack } }
|
||||
impl_has!(Jack<'static>: |self: Arrangement| self.jack);
|
||||
impl_has!(Size: |self: Arrangement| self.size);
|
||||
impl_has!(Sizer: |self: Arrangement| self.size);
|
||||
impl_has!(Vec<MidiInput>: |self: Arrangement| self.midi_ins);
|
||||
impl_has!(Vec<MidiOutput>: |self: Arrangement| self.midi_outs);
|
||||
impl_has!(Clock: |self: Arrangement| self.clock);
|
||||
|
|
|
|||
|
|
@ -37,10 +37,6 @@ pub trait ClipsView: TracksView + ScenesView {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasClipsSize for Arrangement {
|
||||
fn clips_size (&self) -> &Size { &self.size_inner }
|
||||
}
|
||||
|
||||
def_command!(ClipCommand: |clip: MidiClip| {
|
||||
SetColor { color: Option<ItemTheme> } => {
|
||||
//(SetColor [t: usize, s: usize, c: ItemTheme]
|
||||
|
|
@ -86,8 +82,14 @@ impl Arrangement {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait HasClipsSize { fn clips_size (&self) -> &Size; }
|
||||
pub trait HasClipsSize {
|
||||
fn clips_size (&self) -> &Sizer;
|
||||
}
|
||||
|
||||
impl HasClipsSize for App {
|
||||
fn clips_size (&self) -> &Size { &self.project.size_inner }
|
||||
fn clips_size (&self) -> &Sizer { &self.project.size_inner }
|
||||
}
|
||||
|
||||
impl HasClipsSize for Arrangement {
|
||||
fn clips_size (&self) -> &Sizer { &self.size_inner }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ def_command!(FileBrowserCommand: |sampler: Sampler|{
|
|||
pub filter: String,
|
||||
pub index: usize,
|
||||
pub scroll: usize,
|
||||
pub size: Size,
|
||||
pub size: Sizer,
|
||||
}
|
||||
|
||||
pub(crate) struct EntriesIterator<'a, S: Screen> {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
use crate::*;
|
||||
use ::std::sync::{Arc, RwLock, atomic::{AtomicUsize, Ordering::*}};
|
||||
use ::std::sync::{Arc, RwLock, atomic::AtomicUsize};
|
||||
use ::atomic_float::AtomicF64;
|
||||
use ::tengri::{draw::*, term::*};
|
||||
|
||||
mod memo; pub use self::memo::*;
|
||||
mod moment; pub use self::moment::*;
|
||||
mod ticker; pub use self::ticker::*;
|
||||
mod timebase; pub use self::timebase::*;
|
||||
mod clock_view; pub use self::clock_view::*;
|
||||
|
||||
impl <T: AsRef<Clock>+AsMut<Clock>> HasClock for T {}
|
||||
pub trait HasClock: AsRef<Clock> + AsMut<Clock> {
|
||||
|
|
@ -396,8 +401,3 @@ impl_time_unit!(Ppq);
|
|||
impl_time_unit!(Pulse);
|
||||
impl_time_unit!(Bpm);
|
||||
impl_time_unit!(LaunchSync);
|
||||
|
||||
mod moment; pub use self::moment::*;
|
||||
mod ticker; pub use self::ticker::*;
|
||||
mod timebase; pub use self::timebase::*;
|
||||
mod clock_view; pub use self::clock_view::*;
|
||||
|
|
|
|||
53
src/device/clock/memo.rs
Normal file
53
src/device/clock/memo.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use crate::*;
|
||||
|
||||
#[macro_export] macro_rules! rewrite {
|
||||
($buf:ident, $($rest:tt)*) => {
|
||||
|$buf,_,_|{
|
||||
$buf.clear();
|
||||
write!($buf, $($rest)*)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub struct Memo<T, U> {
|
||||
value: T,
|
||||
view: U,
|
||||
}
|
||||
|
||||
impl<T, U> Memo<T, U> {
|
||||
pub fn new (value: T, view: U) -> Self {
|
||||
Self { value, view }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PartialEq + Debug, U: Debug> Debug for Memo<T, U> {
|
||||
fn fmt (&self, _: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PartialEq, U> Memo<T, U> {
|
||||
pub 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, &newval, &self.value);
|
||||
self.value = newval;
|
||||
return Some(result);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Gettable<T> {
|
||||
/// Returns current value
|
||||
fn get (&self) -> T;
|
||||
}
|
||||
|
||||
pub trait Mutable<T>: Gettable<T> {
|
||||
/// Sets new value, returns old
|
||||
fn set (&mut self, value: T) -> T;
|
||||
}
|
||||
|
||||
pub trait InteriorMutable<T>: Gettable<T> {
|
||||
/// Sets new value, returns old
|
||||
fn set (&self, value: T) -> T;
|
||||
}
|
||||
|
|
@ -19,12 +19,12 @@ pub struct MidiEditor {
|
|||
/// View mode and state of editor
|
||||
pub mode: PianoHorizontal,
|
||||
/// Size of editor on screen
|
||||
pub size: Size,
|
||||
pub size: Sizer,
|
||||
}
|
||||
|
||||
impl_default!(MidiEditor: Self {
|
||||
mode: PianoHorizontal::new(None),
|
||||
size: Size(
|
||||
size: Sizer(
|
||||
Arc::new(0usize.into()),
|
||||
Arc::new(0usize.into()),
|
||||
),
|
||||
|
|
@ -255,13 +255,7 @@ pub trait MidiViewer: MidiRange + MidiPoint + Debug + Send + Sync {
|
|||
}
|
||||
}
|
||||
|
||||
impl_has!(Size: |self: MidiEditor| self.size);
|
||||
|
||||
impl Draw<Tui> for MidiEditor {
|
||||
fn draw (self, to: &mut Tui) -> Usually<XYWH<u16>> {
|
||||
self.mode.tui().draw(to)
|
||||
}
|
||||
}
|
||||
impl_has!(Sizer: |self: MidiEditor| self.size);
|
||||
|
||||
impl std::fmt::Debug for MidiEditor {
|
||||
fn fmt (&self, f: &mut Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
||||
|
|
@ -303,7 +297,7 @@ impl View<Tui> for MidiEditor {
|
|||
fn view (&self) -> impl Draw<Tui> {
|
||||
self.autoscroll();
|
||||
/*self.autozoom();*/
|
||||
self.size.of(&self.mode)
|
||||
self.size.of(self.mode.view())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub struct PianoHorizontal {
|
|||
/// Buffer where the whole clip is rerendered on change
|
||||
pub buffer: Arc<RwLock<BigBuffer>>,
|
||||
/// Size of actual notes area
|
||||
pub size: Size,
|
||||
pub size: Sizer,
|
||||
/// The display window
|
||||
pub range: MidiSelection,
|
||||
/// The note cursor
|
||||
|
|
@ -22,17 +22,21 @@ pub struct PianoHorizontal {
|
|||
pub keys_width: u16,
|
||||
}
|
||||
|
||||
impl_has!(Size: |self: PianoHorizontal| self.size);
|
||||
impl Draw<Tui> for PianoHorizontal {
|
||||
fn draw (self, to: &mut Tui) -> Usually<XYWH<u16>> {
|
||||
self.tui().draw(to)
|
||||
impl_has!(Sizer: |self: PianoHorizontal| self.size);
|
||||
|
||||
impl View<Tui> for PianoHorizontal {
|
||||
fn view (&self) -> impl Draw<Tui> {
|
||||
south(
|
||||
east(w_exact(5, format!("{}x{}", self.size.w(), self.size.h())), self.timeline()),
|
||||
east(self.keys(), self.size.of(below(wh_full(self.notes()), wh_full(self.cursor())))),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl PianoHorizontal {
|
||||
|
||||
pub fn new (clip: Option<&Arc<RwLock<MidiClip>>>) -> Self {
|
||||
let size = Size::default();
|
||||
let size = Sizer::default();
|
||||
let mut range = MidiSelection::from((12, true));
|
||||
range.time_axis = size.0.clone();
|
||||
range.note_axis = size.1.clone();
|
||||
|
|
@ -49,13 +53,6 @@ impl PianoHorizontal {
|
|||
piano
|
||||
}
|
||||
|
||||
pub fn tui (&self) -> impl Draw<Tui> {
|
||||
south(
|
||||
east(w_exact(5, format!("{}x{}", self.size.w(), self.size.h())), self.timeline()),
|
||||
east(self.keys(), self.size.of(below(wh_full(self.notes()), wh_full(self.cursor())))),
|
||||
)
|
||||
}
|
||||
|
||||
/// Draw the piano roll background.
|
||||
///
|
||||
/// This mode uses full blocks on note on and half blocks on legato: █▄ █▄ █▄
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ mod sample_kit; pub use self::sample_kit::*;
|
|||
/// Currently active modal, if any.
|
||||
pub mode: Option<SamplerMode>,
|
||||
/// Size of rendered sampler.
|
||||
pub size: Size,
|
||||
pub size: Sizer,
|
||||
/// Lowest note displayed.
|
||||
pub note_lo: AtomicUsize,
|
||||
/// Currently selected note.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue