fix bsp north and stack sampler/sequencer

This commit is contained in:
🪞👃🪞 2024-12-17 17:43:48 +01:00
parent bd7e1d16d6
commit 471d5bc0d3
4 changed files with 43 additions and 39 deletions

View file

@ -61,43 +61,37 @@ impl<E: Engine, X: Render<E>, Y: Render<E>> Render<E> for Bsp<E, X, Y> {
}))
}
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!()
})

View file

@ -4,10 +4,12 @@ use super::*;
impl TryFrom<&Arc<RwLock<JackClient>>> for GrooveboxTui {
type Error = Box<dyn std::error::Error>;
fn try_from (jack: &Arc<RwLock<JackClient>>) -> Usually<Self> {
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!(<Tui>|self:GrooveboxTui,input|Ok(None));

View file

@ -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(())
}));

View file

@ -10,11 +10,8 @@ impl TryFrom<&Arc<RwLock<JackClient>>> for SequencerTui {
fn try_from (jack: &Arc<RwLock<JackClient>>) -> Usually<Self> {
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<RwLock<JackClient>>> 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<Tui>,
pub(crate) show_pool: bool,
pub(crate) status: bool,
pub(crate) note_buf: Vec<u8>,
pub(crate) midi_buf: Vec<Vec<Vec<u8>>>,
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)));