wip: decruft

This commit is contained in:
🪞👃🪞 2024-07-01 14:35:02 +03:00
parent 78e5469b32
commit 55a8b67bfb
7 changed files with 125 additions and 180 deletions

View file

@ -34,17 +34,17 @@ pub struct Sequencer {
/// Don't delete when recording.
pub overdub: bool,
/// Display mode
pub mode: SequencerView,
pub view: SequencerView,
/// Range of notes to display
pub note_axis: (u16, u16),
pub note_start: usize,
/// Position of cursor within note range
pub note_cursor: u16,
pub note_cursor: usize,
/// PPM per display unit
pub time_zoom: usize,
/// Range of time steps to display
pub time_axis: (u16, u16),
pub time_start: usize,
/// Position of cursor within time range
pub time_cursor: u16,
pub time_cursor: usize,
}
#[derive(Debug, Clone)]
@ -65,22 +65,22 @@ impl Sequencer {
timebase: timebase.clone(),
sequence: Some(0),
phrases: phrases.unwrap_or(vec![
phrases: phrases.unwrap_or_else(||vec![
Phrase::new("Phrase0", 4*timebase.ppq() as u32, None)
]),
notes_on: vec![false;128],
transport,
playing: TransportState::Starting,
monitoring: true,
recording: true,
overdub: true,
transport,
mode: SequencerView::Horizontal,
note_axis: (36, 68),
view: SequencerView::Horizontal,
notes_on: vec![false;128],
note_start: 36,
note_cursor: 0,
time_zoom: 24,
time_axis: (0, 64),
time_start: 0,
time_cursor: 0,
}).activate(client)
}
@ -89,76 +89,51 @@ impl Sequencer {
self.phrases.get(self.sequence?)
}
}
impl PortList for Sequencer {
fn midi_ins (&self) -> Usually<Vec<String>> {
Ok(vec![self.midi_in.name()?])
}
fn midi_outs (&self) -> Usually<Vec<String>> {
Ok(vec![self.midi_out.name()?])
}
fn midi_ins (&self) -> Usually<Vec<String>> { Ok(vec![self.midi_in.name()?]) }
fn midi_outs (&self) -> Usually<Vec<String>> { Ok(vec![self.midi_out.name()?]) }
}
fn render (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let Rect { x, y, width, .. } = area;
let (time0, time1) = s.time_axis;
let (note0, note1) = s.note_axis;
let Rect { x, y, width, height } = area;
let pos = s.transport.query().unwrap().pos;
let frame = pos.frame();
let usecs = s.timebase.frame_to_usec(frame as usize);
let ustep = s.timebase.usec_per_step(s.time_zoom as usize);
let steps = usecs / ustep;
let header = draw_header(s, buf, area, steps)?;
let piano = match s.mode {
let piano = match s.view {
SequencerView::Tiny => Rect { x, y, width, height: 0 },
SequencerView::Compact => Rect { x, y, width, height: 0 },
SequencerView::Vertical =>
self::vertical::draw(s, buf, Rect {
x,
y: y + header.height,
width: 3 + note1 - note0,
height: 3 + time1 - time0,
}, steps)?,
SequencerView::Horizontal =>
self::horizontal::draw(s, buf, Rect {
x,
y: y + header.height,
width: area.width.max(3 + time1 - time0),
height: 3 + note1 - note0,
}, steps)?,
SequencerView::Vertical => self::vertical::draw(s, buf, Rect {
x, y: y + header.height, width, height,
}, steps)?,
SequencerView::Horizontal => self::horizontal::draw(s, buf, Rect {
x, y: y + header.height, width, height,
})?,
};
Ok(draw_box(buf, Rect {
x,
y,
x, y,
width: header.width.max(piano.width),
height: header.height + piano.height
}))
}
pub fn draw_header (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) -> Usually<Rect> {
let Rect { x, y, .. } = area;
//let rep = beat / s.steps;
//let step = beat % s.steps;
//let reps = s.steps / s.time_zoom;
//let steps = s.steps % s.time_zoom;
//draw_timer(buf, x + width - 2, y + 1, &format!("{rep}.{step:02} / {reps}.{steps}"));
pub fn draw_header (s: &Sequencer, buf: &mut Buffer, area: Rect, _: usize) -> Usually<Rect> {
let Rect { x, y, width, .. } = area;
let style = Style::default().gray();
crate::device::transport::draw_play_stop(buf, x + 2, y + 1, &s.playing);
let separator = format!("{}", "-".repeat((area.width - 2).into()));
let separator = format!("{}", "-".repeat((width - 2).into()));
separator.blit(buf, x, y + 2, Some(style.dim()));
crate::device::transport::draw_rec(buf, x + 13, y + 1, s.recording);
crate::device::transport::draw_dub(buf, x + 20, y + 1, s.overdub);
crate::device::transport::draw_mon(buf, x + 27, y + 1, s.monitoring);
let _ = draw_clips(s, buf, area)?;
Ok(Rect { x, y, width: area.width, height: 3 })
Ok(Rect { x, y, width, height: 3 })
}
pub fn draw_timer (
buf: &mut Buffer, x: u16, y: u16, timer: &str
) {
pub fn draw_timer (buf: &mut Buffer, x: u16, y: u16, timer: &str) {
let style = Some(Style::default().gray().bold().not_dim());
timer.blit(buf, x - timer.len() as u16, y, style);
}
fn draw_clips (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
pub 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.phrases.iter().enumerate() {