From 93413ae303ab12a92b85e6e289163ee3237e704e Mon Sep 17 00:00:00 2001 From: unspeaker Date: Tue, 17 Dec 2024 18:03:57 +0100 Subject: [PATCH] stub sampler --- crates/tek/src/tui/app_sampler.rs | 91 ++++++++++++++++++++----------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/crates/tek/src/tui/app_sampler.rs b/crates/tek/src/tui/app_sampler.rs index bef748fc..cfc9e445 100644 --- a/crates/tek/src/tui/app_sampler.rs +++ b/crates/tek/src/tui/app_sampler.rs @@ -51,40 +51,67 @@ pub enum SamplerFocus { } audio!(|self: SamplerTui, _client, _scope|Control::Continue); -render!(|self: SamplerTui|render(|to|{ - 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); +render!(|self: SamplerTui|{ + Tui::fill_xy(lay!([ - let style = Style::default().gray(); - 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())); + Tui::fill_xy(render(|to|{ // border + let [x, y, w, h] = to.area(); + let green = Some(Style::default().fg(Color::Green)); + to.blit(&"🭚", x, y, green); + to.blit(&"🭥", x + w.saturating_sub(1), y, green); + to.blit(&"🬿", x, y + h.saturating_sub(1), green); + to.blit(&"🭊", x + w.saturating_sub(1), y + h.saturating_sub(1), green); + Ok(()) + })), - let mut width = title.len() + 2; - let mut y1 = 1; - let mut j = 0; - for (note, sample) in self.state.mapped.iter() - .map(|(note, sample)|(Some(note), sample)) - .chain(self.state.unmapped.iter().map(|sample|(None, sample))) - { - if y1 >= h { - break - } - let active = j == self.cursor.0; - width = width.max( - draw_sample(to, x, y + y1, note, &*sample.read().unwrap(), active)? - ); - y1 = y1 + 1; - j = j + 1; - } - let h = ((2 + y1) as u16).min(h); - //Ok(Some([x, y, (width as u16).min(to.area().w()), h])) - Ok(()) -})); + col!([ + "", + row!([ + " ", Tui::bold(true, "Sampler."), " Voices: ", + &format!("{}", self.state.voices.read().unwrap().len()), + ]), + " ", + Tui::either(self.state.unmapped.len() > 0, + col!((index, sample) in self.state.unmapped.iter().enumerate() => + { &format!("| Unmapped #{index}") }), " · No unmapped samples."), + " ", + Tui::either(self.state.mapped.len() > 0, + col!((index, sample) in self.state.unmapped.iter().enumerate() => + { &format!("| Mapped #{index}") }), " · No mapped samples."), + ]) + + //render(|to|{ + //let [x, y, w, h] = to.area(); + //let style = Style::default().gray(); + //let voice = self.state.voices.read().unwrap().len(); + //let title = format!(" {} ({voice} voice(s) playing now)", 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; + //for (note, sample) in self.state.mapped.iter() + //.map(|(note, sample)|(Some(note), sample)) + //.chain(self.state.unmapped.iter().map(|sample|(None, sample))) + //{ + //if y1 >= h { + //break + //} + //let active = j == self.cursor.0; + //width = width.max( + //draw_sample(to, x, y + y1, note, &*sample.read().unwrap(), active)? + //); + //y1 = y1 + 1; + //j = j + 1; + //} + //let h = ((2 + y1) as u16).min(h); + ////Ok(Some([x, y, (width as u16).min(to.area().w()), h])) + //Ok(()) + //}), + //]) + + ])) +}); impl SamplerTui { /// Immutable reference to sample at cursor.