mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-04-08 19:10:13 +02:00
extract has_sampler
This commit is contained in:
parent
09c8e651d4
commit
432b916823
sampler/src
30
sampler/src/has_sampler.rs
Normal file
30
sampler/src/has_sampler.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
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 }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,3 +25,5 @@ pub(crate) use ratatui::{prelude::Rect, widgets::{Widget, canvas::{Canvas, Line}
|
|||
// TODO!
|
||||
let sample = Sample::new("test", 0, 0, vec![]);
|
||||
}
|
||||
|
||||
mod has_sampler; pub use self::has_sampler::*;
|
||||
|
|
|
@ -1,33 +1,4 @@
|
|||
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 }
|
||||
}
|
||||
}
|
||||
}
|
||||
/// The sampler device plays sounds in response to MIDI notes.
|
||||
#[derive(Debug)] pub struct Sampler {
|
||||
pub jack: Jack,
|
||||
|
@ -837,7 +808,8 @@ impl Sampler {
|
|||
let offset = |a|Push::y(i as u16, Align::n(Fixed::y(1, Fill::x(a))));
|
||||
let mut bg = if note == note_pt { Tui::g(64) } else { Color::Reset };
|
||||
let mut fg = Tui::g(160);
|
||||
if self.mapped[note].is_some() {
|
||||
let mapped: &Option<Arc<RwLock<Sample>>> = &self.mapped[note];
|
||||
if mapped.is_some() {
|
||||
fg = Tui::g(224);
|
||||
bg = Color::Rgb(0, if note == note_pt { 96 } else { 64 }, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue