mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-10 21:56:42 +01:00
30 lines
1.2 KiB
Rust
30 lines
1.2 KiB
Rust
use crate::*;
|
|
pub trait HasSampler {
|
|
fn sampler (&self) -> &Option<Sampler>;
|
|
fn sampler_mut (&mut self) -> &mut Option<Sampler>;
|
|
fn sample_index (&self) -> usize;
|
|
fn view_sample <'a> (&'a self, compact: bool) -> impl Content<TuiOut> + 'a {
|
|
self.sampler().as_ref().map(|sampler|Max::y(
|
|
if compact { 0u16 } else { 5 }.into(),
|
|
Fill::x(sampler.viewer(self.sample_index()))
|
|
))
|
|
}
|
|
fn view_sampler <'a> (&'a self, compact: bool, editor: &Option<MidiEditor>) -> impl Content<TuiOut> + 'a {
|
|
self.sampler().as_ref().map(|sampler|Fixed::x(
|
|
if compact { 4u16 } else { 40 }.into(),
|
|
Push::y(
|
|
if compact { 1u16 } else { 0 }.into(),
|
|
editor.as_ref().map(|e|Fill::y(sampler.list(compact, e)))
|
|
)
|
|
))
|
|
}
|
|
}
|
|
#[macro_export] macro_rules! has_sampler {
|
|
(|$self:ident:$Struct:ty| { sampler = $e0:expr; index = $e1:expr; }) => {
|
|
impl HasSampler for $Struct {
|
|
fn sampler (&$self) -> &Option<Sampler> { &$e0 }
|
|
fn sampler_mut (&mut $self) -> &mut Option<Sampler> { &mut $e0 }
|
|
fn sample_index (&$self) -> usize { $e1 }
|
|
}
|
|
}
|
|
}
|