edn stub examples are now runnable

the Render/Content trait pair is very finicky
This commit is contained in:
🪞👃🪞 2025-01-05 04:57:42 +01:00
parent f1b3fc0040
commit f6c603bf73
9 changed files with 69 additions and 56 deletions

View file

@ -10,10 +10,8 @@ mod groovebox_audio; pub use self::groovebox_audio::*;
mod groovebox_command; pub use self::groovebox_command::*;
mod groovebox_tui; pub use self::groovebox_tui::*;
pub struct Groovebox<'a> {
pub struct Groovebox {
_jack: Arc<RwLock<JackConnection>>,
pub view: EdnView<'a, Tui, Self>,
pub player: MidiPlayer,
pub pool: PoolModel,
pub editor: MidiEditor,
@ -27,7 +25,7 @@ pub struct Groovebox<'a> {
pub perf: PerfModel,
}
impl<'a> Groovebox<'a> {
impl Groovebox {
pub fn new (
jack: &Arc<RwLock<JackConnection>>,
midi_from: &[impl AsRef<str>],
@ -57,49 +55,44 @@ impl<'a> Groovebox<'a> {
midi_buf: vec![vec![];65536],
note_buf: vec![],
perf: PerfModel::default(),
view: EdnView::new(include_str!("groovebox/groovebox.edn"))?,
})
}
}
has_clock!(|self: Groovebox<'a>|self.player.clock());
has_clock!(|self: Groovebox|self.player.clock());
impl<'a> EdnLayout<'a, Tui> for Groovebox<'a> {
fn get_bool (&self, item: &EdnItem<&str>) -> bool { todo!() }
fn get_unit (&self, item: &EdnItem<&str>) -> u16 {
impl EdnLayout<Tui> for Groovebox {
fn get_bool (&self, item: &str) -> bool { todo!() }
fn get_unit (&self, item: &str) -> u16 {
use EdnItem::*;
match item {
Sym(":sample-h") => if self.compact { 0 } else { 5 },
Sym(":samples-w") => if self.compact { 4 } else { 11 },
Sym(":samples-y") => if self.compact { 1 } else { 0 },
Sym(":pool-w") => if self.compact { 5 } else {
":sample-h" => if self.compact { 0 } else { 5 },
":samples-w" => if self.compact { 4 } else { 11 },
":samples-y" => if self.compact { 1 } else { 0 },
":pool-w" => if self.compact { 5 } else {
let w = self.size.w();
if w > 60 { 20 } else if w > 40 { 15 } else { 10 }
},
_ => 0
}
}
fn get_content (&'a self, item: &EdnItem<&str>) -> Box<EdnRender<'a, Tui>> {
fn get_content <'a> (&'a self, item: &str) -> Box<EdnRender<'a, Tui>> {
use EdnItem::*;
match item {
Sym(":input-meter-l") => Box::new(Meter("L/", self.sampler.input_meter[0])),
Sym(":input-meter-r") => Box::new(Meter("R/", self.sampler.input_meter[1])),
":input-meter-l" => Box::new(Meter("L/", self.sampler.input_meter[0])),
":input-meter-r" => Box::new(Meter("R/", self.sampler.input_meter[1])),
Sym(":transport") => Box::new(TransportView::new(true, &self.player.clock)),
Sym(":clip-play") => Box::new(ClipSelected::play_phrase(&self.player)),
Sym(":clip-next") => Box::new(ClipSelected::next_phrase(&self.player)),
Sym(":clip-edit") => Box::new(MidiEditClip(&self.editor)),
Sym(":edit-stat") => Box::new(MidiEditStatus(&self.editor)),
Sym(":pool-view") => Box::new(PoolView(self.compact, &self.pool)),
Sym(":midi-view") => Box::new(&self.editor),
":transport" => Box::new(TransportView::new(true, &self.player.clock)),
":clip-play" => Box::new(ClipSelected::play_phrase(&self.player)),
":clip-next" => Box::new(ClipSelected::next_phrase(&self.player)),
":clip-edit" => Box::new(MidiEditClip(&self.editor)),
":edit-stat" => Box::new(MidiEditStatus(&self.editor)),
":pool-view" => Box::new(PoolView(self.compact, &self.pool)),
":midi-view" => Box::new(&self.editor),
Sym(":sample-view") => Box::new(SampleViewer::from_sampler(
&self.sampler, self.editor.note_point())),
Sym(":sample-stat") => Box::new(SamplerStatus(
&self.sampler, self.editor.note_point())),
Sym(":samples-view") => Box::new(SampleList::new(
self.compact, &self.sampler, &self.editor)),
":sample-view" => Box::new(SampleViewer::from_sampler(&self.sampler, self.editor.note_point())),
":sample-stat" => Box::new(SamplerStatus(&self.sampler, self.editor.note_point())),
":samples-view" => Box::new(SampleList::new(self.compact, &self.sampler, &self.editor)),
_ => Box::new(())
}
@ -114,7 +107,7 @@ pub struct GrooveboxStatus {
pub(crate) size: String,
pub(crate) playing: bool,
}
from!(|state: &Groovebox<'_>|GrooveboxStatus = {
from!(|state: &Groovebox|GrooveboxStatus = {
let samples = state.clock().chunk.load(Relaxed);
let rate = state.clock().timebase.sr.get();
let buffer = samples as f64 / rate;