wip: <200 errors yay

This commit is contained in:
🪞👃🪞 2024-09-05 16:01:01 +03:00
parent 14d619a10a
commit 694970bf0d
20 changed files with 384 additions and 305 deletions

View file

@ -13,56 +13,20 @@ pub struct Sampler {
pub modal: Arc<Mutex<Option<Box<dyn Exit + Send>>>>,
pub output_gain: f32
}
impl<E: Engine> Handle<E> for Sampler {
fn handle (&mut self, e: &E) -> Usually<E::Handled> {
handle_keymap(self, event, KEYMAP_SAMPLER)
}
}
impl Render<Tui> for Sampler {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
tui_render_sampler(self, to)
}
}
process!(Sampler = Sampler::process);
handle!(Sampler |self, event| handle_keymap(self, event, KEYMAP_SAMPLER));
impl Render<Tui> for Sampler {
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
let Rect { x, y, height, .. } = to.area();
let style = Style::default().gray();
let title = format!(" {} ({})", self.name, self.voices.read().unwrap().len());
title.blit(to.buffer(), 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.mapped.iter()
.map(|(note, sample)|(Some(note), sample))
.chain(self.unmapped.iter().map(|sample|(None, sample)))
{
if y1 >= height {
break
}
let active = j == self.cursor.0;
width = width.max(
draw_sample(to.buffer(), x, y + y1, note, &*sample.read().unwrap(), active)?
);
y1 = y1 + 1;
j = j + 1;
}
let height = ((2 + y1) as u16).min(height);
Ok(Some(Rect { x, y, width: (width as u16).min(to.area().width), height }))
}
}
fn draw_sample (
buf: &mut Buffer, x: u16, y: u16, note: Option<&u7>, sample: &Sample, focus: bool
) -> Usually<usize> {
let style = if focus { Style::default().green() } else { Style::default() };
if focus {
"🬴".blit(buf, x+1, y, Some(style.bold()))?;
}
let label1 = format!("{:3} {:12}",
note.map(|n|n.to_string()).unwrap_or(String::default()),
sample.name);
let label2 = format!("{:>6} {:>6} +0.0",
sample.start,
sample.end);
label1.blit(buf, x+2, y, Some(style.bold()))?;
label2.blit(buf, x+3+label1.len()as u16, y, Some(style))?;
Ok(label1.len() + label2.len() + 4)
}
/// Key bindings for sampler device.
pub const KEYMAP_SAMPLER: &'static [KeyBinding<Sampler>] = keymap!(Sampler {
@ -105,7 +69,7 @@ pub const KEYMAP_SAMPLER: &'static [KeyBinding<Sampler>] = keymap!(Sampler {
});
impl Sampler {
pub fn from_edn <'e, E> (args: &[Edn<'e>]) -> Usually<JackDevice<E>> {
pub fn from_edn <'e, E: Engine> (args: &[Edn<'e>]) -> Usually<JackDevice<E>> {
let mut name = String::new();
let mut dir = String::new();
let mut samples = BTreeMap::new();
@ -134,7 +98,7 @@ impl Sampler {
Self::new(&name, Some(samples))
}
pub fn new <E> (
pub fn new <E: Engine> (
name: &str, mapped: Option<BTreeMap<u7, Arc<RwLock<Sample>>>>
) -> Usually<JackDevice<E>> {
Jack::new(name)?