lv2 plugin plays!

This commit is contained in:
🪞👃🪞 2024-06-25 22:50:30 +03:00
parent 403d0f2dfe
commit a4a2f645b1
4 changed files with 125 additions and 88 deletions

View file

@ -222,6 +222,15 @@ impl Sequencer {
}
}
impl DevicePorts for Sequencer {
fn midi_ins (&self) -> Usually<Vec<String>> {
Ok(vec!["in".into()])
}
fn midi_outs (&self) -> Usually<Vec<String>> {
Ok(vec!["out".into()])
}
}
fn render (s: &Sequencer, buf: &mut Buffer, mut area: Rect) -> Usually<Rect> {
let Rect { x, y, width, .. } = area;
let (time0, time1) = s.time_axis;
@ -266,59 +275,62 @@ fn draw_header (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) -> Usu
let Rect { x, y, width, .. } = area;
let style = Style::default().gray();
let timer = format!("{rep}.{step:02} / {reps}.{steps}");
buf.set_string(x + width - 2 - timer.len() as u16, y + 1, &timer, style.bold().not_dim());
buf.set_string(x + 2, y + 1, &match s.playing {
TransportState::Rolling => format!("▶ PLAYING"),
TransportState::Starting => format!("READY ..."),
TransportState::Stopped => format!("⏹ STOPPED")
}, match s.playing {
timer.blit(buf, x + width - 2 - timer.len() as u16, y + 1, Some(style.bold().not_dim()));
match s.playing {
TransportState::Rolling => "▶ PLAYING",
TransportState::Starting => "READY ...",
TransportState::Stopped => "⏹ STOPPED",
}.blit(buf, x + 2, y + 1, Some(match s.playing {
TransportState::Stopped => style.dim().bold(),
TransportState::Starting => style.not_dim().bold(),
TransportState::Rolling => style.not_dim().white().bold()
});
buf.set_string(x, y + 2, format!("{}", "-".repeat((area.width - 2).into())), style.dim());
//buf.set_string(x + 2, y + 2,
//&format!("▶ PLAY"), if s.playing {
//Style::default().green()
//} else {
//Style::default().dim()
//});
buf.set_string(x + 13, y + 1, &format!("⏺ REC"), if s.recording {
Style::default().bold().red()
} else {
Style::default().bold().dim()
});
buf.set_string(x + 20, y + 1, &format!("⏺ DUB"), if s.overdub {
Style::default().bold().yellow()
} else {
Style::default().bold().dim()
});
buf.set_string(x + 27, y + 1, &format!("⏺ MON"), if s.monitoring {
Style::default().bold().green()
} else {
Style::default().bold().dim()
});
}));
let separator = format!("{}", "-".repeat((area.width - 2).into()));
separator.blit(buf, x, y + 2, Some(style.dim()));
draw_rec(buf, x + 13, y + 1, s.recording);
draw_dub(buf, x + 20, y + 1, s.overdub);
draw_mon(buf, x + 27, y + 1, s.monitoring);
let clips = draw_clips(s, buf, area)?;
Ok(Rect { x, y, width: area.width, height: 3 })
}
fn draw_rec (buf: &mut Buffer, x: u16, y: u16, on: bool) {
"⏺ REC".blit(buf, x, y, Some(if on {
Style::default().bold().red()
} else {
Style::default().bold().dim()
}))
}
fn draw_dub (buf: &mut Buffer, x: u16, y: u16, on: bool) {
"⏺ DUB".blit(buf, x + 20, y + 1, Some(if on {
Style::default().bold().yellow()
} else {
Style::default().bold().dim()
}))
}
fn draw_mon (buf: &mut Buffer, x: u16, y: u16, on: bool) {
"⏺ MON".blit(buf, x + 27, y + 1, Some(if on {
Style::default().bold().green()
} else {
Style::default().bold().dim()
}))
}
fn draw_clips (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let Rect { x, y, .. } = area;
let style = Style::default().gray();
for (i, sequence) in s.sequences.iter().enumerate() {
let label = format!("{}", &sequence.name);
buf.set_string(x + 2, y + 3 + (i as u16)*2, &label, if i == s.sequence {
label.blit(buf, x + 2, y + 3 + (i as u16)*2, Some(if i == s.sequence {
match s.playing {
TransportState::Rolling => style.white().bold(),
_ => style.not_dim().bold()
}
} else {
style.dim()
});
}));
}
Ok(Rect { x, y, width: 14, height: 14 })
}
pub fn contains_note_on (sequence: &Sequence, k: ::midly::num::u7, start: u32, end: u32) -> bool {
for (_, (_, events)) in sequence.notes.range(start..end).enumerate() {
for event in events.iter() {
@ -334,11 +346,9 @@ pub fn contains_note_on (sequence: &Sequence, k: ::midly::num::u7, start: u32, e
}
return false
}
pub fn handle (s: &mut Sequencer, event: &AppEvent) -> Usually<bool> {
handle_keymap(s, event, KEYMAP)
}
pub const KEYMAP: &'static [KeyBinding<Sequencer>] = keymap!(Sequencer {
[Up, NONE, "cursor_up", "move cursor up", cursor_up],
[Down, NONE, "cursor_down", "move cursor down", cursor_down],
@ -373,14 +383,12 @@ pub const KEYMAP: &'static [KeyBinding<Sequencer>] = keymap!(Sequencer {
[Char('7'), NONE, "seq_7", "Sequence 7", focus_seq(6)],
[Char('8'), NONE, "seq_8", "Sequence 8", focus_seq(7)],
});
const fn focus_seq (i: usize) -> impl Fn(&mut Sequencer)->Usually<bool> {
move |s: &mut Sequencer| {
s.sequence = i;
Ok(true)
}
}
fn nop (_: &mut Sequencer) -> Usually<bool> {
Ok(false)
}
@ -561,12 +569,3 @@ fn quantize_prev (s: &mut Sequencer) -> Usually<bool> {
Ok(())
}
}
impl DevicePorts for Sequencer {
fn midi_ins (&self) -> Usually<Vec<String>> {
Ok(vec!["in".into()])
}
fn midi_outs (&self) -> Usually<Vec<String>> {
Ok(vec!["out".into()])
}
}