From 471d5bc0d3a9dc23502a644296ca7355fcb1e1a9 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Tue, 17 Dec 2024 17:43:48 +0100 Subject: [PATCH] fix bsp north and stack sampler/sequencer --- crates/tek/src/layout/bsp.rs | 42 +++++++++++++---------------- crates/tek/src/tui/app_groovebox.rs | 10 ++++--- crates/tek/src/tui/app_sampler.rs | 18 +++++++++---- crates/tek/src/tui/app_sequencer.rs | 12 ++++----- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/crates/tek/src/layout/bsp.rs b/crates/tek/src/layout/bsp.rs index a8bffc3d..083761e1 100644 --- a/crates/tek/src/layout/bsp.rs +++ b/crates/tek/src/layout/bsp.rs @@ -61,43 +61,37 @@ impl, Y: Render> Render for Bsp { })) } fn render (&self, to: &mut E::Output) -> Usually<()> { + let n = [0.into(), 0.into()].into(); + let s = to.area().wh().into(); Ok(match self { Self::Null(_) => {}, Self::S(a, b) => { - let n = [0.into(), 0.into()].into(); - let s = to.area().wh().into(); let s_a = a.min_size(s)?.unwrap_or(n); - let s_b = b.min_size(s)?.unwrap_or(n); - let s_y = s_a.h().into(); - to.render_in(to.area().clip_h(s_y).into(), a)?; - to.render_in(to.area().push_y(s_y).shrink_y(s_y).into(), b)?; + //let s_b = b.min_size(s)?.unwrap_or(n); + let h = s_a.h().into(); + to.render_in(to.area().clip_h(h).into(), a)?; + to.render_in(to.area().push_y(h).shrink_y(h).into(), b)?; }, Self::E(a, b) => { - let n = [0.into(), 0.into()].into(); - let s = to.area().wh().into(); let s_a = a.min_size(s)?.unwrap_or(n); - let s_b = b.min_size(s)?.unwrap_or(n); - let s_x = s_a.w().into(); - to.render_in(to.area().clip_w(s_x).into(), a)?; - to.render_in(to.area().push_x(s_x).shrink_x(s_x).into(), b)?; + //let s_b = b.min_size(s)?.unwrap_or(n); + let w = s_a.w().into(); + to.render_in(to.area().clip_w(w).into(), a)?; + to.render_in(to.area().push_x(w).shrink_x(w).into(), b)?; }, Self::W(a, b) => { - let n = [0.into(), 0.into()].into(); - let s = to.area().wh().into(); let s_a = a.min_size(s)?.unwrap_or(n); - let s_b = b.min_size(s)?.unwrap_or(n); - let s_x = (to.area().w() - s_a.w()).into(); - to.render_in(to.area().push_x(s_x).into(), a)?; - to.render_in(to.area().shrink_x(s_x).into(), b)?; + //let s_b = b.min_size(s)?.unwrap_or(n); + let w = (to.area().w() - s_a.w()).into(); + to.render_in(to.area().push_x(w).into(), a)?; + to.render_in(to.area().shrink_x(w).into(), b)?; }, Self::N(a, b) => { - let n = [0.into(), 0.into()].into(); - let s = to.area().wh().into(); let s_a = a.min_size(s)?.unwrap_or(n); - let s_b = b.min_size(s)?.unwrap_or(n); - let s_y = (to.area().h() - s_a.h()).into(); - to.render_in(to.area().push_y(s_y).into(), a)?; - to.render_in(to.area().shrink_y(s_y).into(), b)?; + //let s_b = b.min_size(s)?.unwrap_or(n); + let h = to.area().h() - s_a.h(); + to.render_in(to.area().push_y(h).into(), a)?; + to.render_in(to.area().shrink_y(h).into(), b)?; }, _ => todo!() }) diff --git a/crates/tek/src/tui/app_groovebox.rs b/crates/tek/src/tui/app_groovebox.rs index e0ea179b..7b44bfc5 100644 --- a/crates/tek/src/tui/app_groovebox.rs +++ b/crates/tek/src/tui/app_groovebox.rs @@ -4,10 +4,12 @@ use super::*; impl TryFrom<&Arc>> for GrooveboxTui { type Error = Box; fn try_from (jack: &Arc>) -> Usually { + let mut sequencer = SequencerTui::try_from(jack)?; + sequencer.status = false; Ok(Self { - sequencer: SequencerTui::try_from(jack)?, - sampler: SamplerTui::try_from(jack)?, - split: 20 + sequencer, + sampler: SamplerTui::try_from(jack)?, + split: 16 }) } } @@ -18,6 +20,6 @@ pub struct GrooveboxTui { pub split: u16, } -render!(|self:GrooveboxTui|Bsp::n(Tui::fixed_y(self.split, &self.sampler), &self.sequencer)); +render!(|self:GrooveboxTui|Bsp::s(Tui::fixed_y(self.split, &self.sequencer), &self.sampler)); audio!(|self:GrooveboxTui,_client,_process|Control::Continue); handle!(|self:GrooveboxTui,input|Ok(None)); diff --git a/crates/tek/src/tui/app_sampler.rs b/crates/tek/src/tui/app_sampler.rs index 9501d125..bef748fc 100644 --- a/crates/tek/src/tui/app_sampler.rs +++ b/crates/tek/src/tui/app_sampler.rs @@ -52,10 +52,18 @@ pub enum SamplerFocus { audio!(|self: SamplerTui, _client, _scope|Control::Continue); render!(|self: SamplerTui|render(|to|{ - let [x, y, _, height] = to.area(); + let [x, y, w, h] = to.area(); + let style = Some(Style::default().fg(Color::Green)); + to.blit(&"🭚", x, y, style); + to.blit(&"🭥", x + w.saturating_sub(1), y, style); + to.blit(&"🬿", x, y + h.saturating_sub(1), style); + to.blit(&"🭊", x + w.saturating_sub(1), y + h.saturating_sub(1), style); + let style = Style::default().gray(); - let title = format!(" {} ({})", self.state.name, self.state.voices.read().unwrap().len()); + let voice = self.state.voices.read().unwrap().len(); + let title = format!(" {} ({voice})", self.state.name); to.blit(&title, x+1, y, Some(style.white().bold().not_dim())); + let mut width = title.len() + 2; let mut y1 = 1; let mut j = 0; @@ -63,7 +71,7 @@ render!(|self: SamplerTui|render(|to|{ .map(|(note, sample)|(Some(note), sample)) .chain(self.state.unmapped.iter().map(|sample|(None, sample))) { - if y1 >= height { + if y1 >= h { break } let active = j == self.cursor.0; @@ -73,8 +81,8 @@ render!(|self: SamplerTui|render(|to|{ y1 = y1 + 1; j = j + 1; } - let height = ((2 + y1) as u16).min(height); - //Ok(Some([x, y, (width as u16).min(to.area().w()), height])) + let h = ((2 + y1) as u16).min(h); + //Ok(Some([x, y, (width as u16).min(to.area().w()), h])) Ok(()) })); diff --git a/crates/tek/src/tui/app_sequencer.rs b/crates/tek/src/tui/app_sequencer.rs index a17aa161..029d79fa 100644 --- a/crates/tek/src/tui/app_sequencer.rs +++ b/crates/tek/src/tui/app_sequencer.rs @@ -10,11 +10,8 @@ impl TryFrom<&Arc>> for SequencerTui { fn try_from (jack: &Arc>) -> Usually { let clock = ClockModel::from(jack); let phrase = Arc::new(RwLock::new(Phrase::new( - "New", - true, - 4 * clock.timebase.ppq.get() as usize, - None, - Some(ItemColor::random().into()) + "New", true, 4 * clock.timebase.ppq.get() as usize, + None, Some(ItemColor::random().into()) ))); Ok(Self { _jack: jack.clone(), @@ -27,6 +24,7 @@ impl TryFrom<&Arc>> for SequencerTui { note_buf: vec![], perf: PerfModel::default(), show_pool: true, + status: true, }) } @@ -41,6 +39,7 @@ pub struct SequencerTui { pub(crate) editor: PhraseEditorModel, pub(crate) size: Measure, pub(crate) show_pool: bool, + pub(crate) status: bool, pub(crate) note_buf: Vec, pub(crate) midi_buf: Vec>>, pub(crate) perf: PerfModel, @@ -155,7 +154,8 @@ render!(|self: SequencerTui|{ let pool_w = if self.show_pool { phrase_w } else { 0 }; let pool = Tui::fill_y(Tui::at_e(PhraseListView(&self.phrases))); let with_pool = move|x|Tui::split_w(false, pool_w, pool, x); - let with_status = |x|Tui::split_n(false, 2, SequencerStatusBar::from(self), x); + let status = SequencerStatusBar::from(self); + let with_status = |x|Tui::split_n(false, if self.status { 2 } else { 0 }, status, x); let with_editbar = |x|Tui::split_n(false, 3, PhraseEditStatus(&self.editor), x); let with_size = |x|lay!([self.size, x]); let editor = with_editbar(with_pool(Tui::fill_xy(&self.editor)));