make transport focusable

This commit is contained in:
🪞👃🪞 2024-07-12 13:23:32 +03:00
parent a7a798b484
commit 449615eea8
14 changed files with 220 additions and 237 deletions

View file

@ -9,8 +9,36 @@ pub struct Sampler {
pub buffer: Vec<Vec<f32>>,
pub output_gain: f32
}
render!(Sampler |self, buf, area| {
let Rect { x, y, height, .. } = area;
let style = Style::default().gray();
let title = format!(" {} ({})", self.name, self.voices.len());
title.blit(buf, x+1, y, Some(style.white().bold().not_dim()))?;
let mut width = title.len() + 2;
for (i, (note, sample)) in self.samples.iter().enumerate() {
let style = if i == self.cursor.0 {
Style::default().green()
} else {
Style::default()
};
let i = i as u16;
let y1 = y+1+i;
if y1 >= y + height {
break
}
if i as usize == self.cursor.0 {
"".blit(buf, x+1, y1, Some(style.bold()))?;
}
let label1 = format!("{note:3} {:12}", sample.name);
let label2 = format!("{:>6} {:>6} +0.0", sample.start, sample.end);
label1.blit(buf, x+2, y1, Some(style.bold()))?;
label2.blit(buf, x+3+label1.len()as u16, y1, Some(style))?;
width = width.max(label1.len() + label2.len() + 4);
}
let height = ((2 + self.samples.len()) as u16).min(height);
Ok(Rect { x, y, width: (width as u16).min(area.width), height })
});
render!(Sampler = crate::view::sampler::render);
handle!(Sampler = crate::control::sampler::handle);
//jack!(Sampler {
//process = Sampler::process,
@ -184,3 +212,48 @@ impl Iterator for Voice {
None
}
}
//fn render_table (
//self: &mut Sampler,
//stdout: &mut Stdout,
//offset: (u16, u16),
//) -> Result<(), Box<dyn Error>> {
//let move_to = |col, row| crossterm::cursor::MoveTo(offset.0 + col, offset.1 + row);
//stdout.queue(move_to(0, 3))?.queue(
//Print(" Name Rate Trigger Route")
//)?;
//for (i, sample) in self.samples.lock().unwrap().iter().enumerate() {
//let row = 4 + i as u16;
//for (j, (column, field)) in [
//(0, format!(" {:7} ", sample.name)),
//(9, format!(" {:.1}Hz ", sample.rate)),
//(18, format!(" MIDI C{} {} ", sample.trigger.0, sample.trigger.1)),
//(33, format!(" {:.1}dB -> Output ", sample.gain)),
//(50, format!(" {} ", sample.playing.unwrap_or(0))),
//].into_iter().enumerate() {
//stdout.queue(move_to(column, row))?;
//if self.selected_sample == i && self.selected_column == j {
//stdout.queue(PrintStyledContent(field.to_string().bold().reverse()))?;
//} else {
//stdout.queue(PrintStyledContent(field.to_string().bold()))?;
//}
//}
//}
//Ok(())
//}
//fn render_meters (
//self: &mut Sampler,
//stdout: &mut Stdout,
//offset: (u16, u16),
//) -> Result<(), Box<dyn Error>> {
//let move_to = |col, row| crossterm::cursor::MoveTo(offset.0 + col, offset.1 + row);
//for (i, sample) in self.samples.lock().iter().enumerate() {
//let row = 4 + i as u16;
//stdout.queue(move_to(32, row))?.queue(
//PrintStyledContent("▁".green())
//)?;
//}
//Ok(())
//}

View file

@ -20,17 +20,6 @@ impl App {
Ok(&mut self.tracks[self.track_cursor - 1])
}
fn add_track_with_cb (
&mut self, name: Option<&str>, init: impl FnOnce(&Client, &mut Track)->Usually<()>,
) -> Usually<&mut Track> {
let name = name.ok_or_else(||self.new_track_name())?;
let mut track = Track::new(&name, None, None)?;
init(self.client(), &mut track)?;
self.tracks.push(track);
self.track_cursor = self.tracks.len();
Ok(&mut self.tracks[self.track_cursor - 1])
}
pub fn track (&self) -> Option<(usize, &Track)> {
match self.track_cursor { 0 => None, _ => {
let id = self.track_cursor as usize - 1;
@ -61,6 +50,7 @@ pub struct Track {
pub sequence: Option<usize>,
/// Output from current sequence.
pub midi_out: Option<Port<MidiOut>>,
/// MIDI output buffer
midi_out_buf: Vec<Vec<Vec<u8>>>,
/// Device chain
pub devices: Vec<JackDevice>,
@ -74,6 +64,7 @@ pub struct Track {
/// Highlight keys on piano roll.
pub notes_out: [bool;128],
}
impl Track {
fn new (
name: &str,