mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 20:26:42 +01:00
modularize core
This commit is contained in:
parent
a4061535b5
commit
2837ffff4a
43 changed files with 629 additions and 770 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use crate::prelude::*;
|
||||
use crate::core::*;
|
||||
use crate::layout::*;
|
||||
|
||||
mod keys; use self::keys::*;
|
||||
mod handle; pub use self::handle::*;
|
||||
|
|
@ -22,7 +23,7 @@ pub struct Sequencer {
|
|||
/// FIXME: play start / end / loop in ppm
|
||||
pub steps: usize,
|
||||
/// Phrase selector
|
||||
pub sequence: usize,
|
||||
pub sequence: Option<usize>,
|
||||
/// Map: tick -> MIDI events at tick
|
||||
pub phrases: Vec<Phrase>,
|
||||
/// Red keys on piano roll.
|
||||
|
|
@ -51,12 +52,7 @@ pub struct Sequencer {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum SequencerView {
|
||||
Tiny,
|
||||
Compact,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
}
|
||||
pub enum SequencerView { Tiny, Compact, Horizontal, Vertical, }
|
||||
|
||||
impl Sequencer {
|
||||
pub fn new (
|
||||
|
|
@ -74,8 +70,10 @@ impl Sequencer {
|
|||
timebase: timebase.clone(),
|
||||
steps: 16,
|
||||
resolution: 4,
|
||||
sequence: 0,
|
||||
phrases: phrases.unwrap_or(vec![]),
|
||||
sequence: Some(0),
|
||||
phrases: phrases.unwrap_or(vec![
|
||||
Phrase::new("Phrase0", 4*timebase.ppq() as u32, None)
|
||||
]),
|
||||
notes_on: vec![false;128],
|
||||
|
||||
playing: TransportState::Starting,
|
||||
|
|
@ -93,12 +91,12 @@ impl Sequencer {
|
|||
}
|
||||
|
||||
pub fn phrase <'a> (&'a self) -> Option<&'a Phrase> {
|
||||
self.phrases.get(self.sequence)
|
||||
self.sequence.map(|s|self.phrases.get(s))?
|
||||
}
|
||||
}
|
||||
|
||||
impl PortList for Sequencer {
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
fn midi_ins (&self) -> Usually<Vec<String>> {
|
||||
Ok(vec![self.midi_in.name()?])
|
||||
}
|
||||
fn midi_outs (&self) -> Usually<Vec<String>> {
|
||||
|
|
@ -117,22 +115,22 @@ fn render (s: &Sequencer, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
|||
let steps = usecs / ustep;
|
||||
let header = draw_header(s, buf, area, steps)?;
|
||||
let piano = match s.mode {
|
||||
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::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)?,
|
||||
};
|
||||
Ok(draw_box(buf, Rect {
|
||||
x,
|
||||
|
|
@ -150,12 +148,12 @@ pub fn draw_header (s: &Sequencer, buf: &mut Buffer, area: Rect, beat: usize) ->
|
|||
let steps = s.steps % s.resolution;
|
||||
draw_timer(buf, x + width - 2, y + 1, &format!("{rep}.{step:02} / {reps}.{steps}"));
|
||||
let style = Style::default().gray();
|
||||
draw_play_stop(buf, x + 2, y + 1, &s.playing);
|
||||
crate::device::transport::draw_play_stop(buf, x + 2, y + 1, &s.playing);
|
||||
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);
|
||||
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 })
|
||||
}
|
||||
|
|
@ -165,45 +163,12 @@ pub fn draw_timer (
|
|||
let style = Some(Style::default().gray().bold().not_dim());
|
||||
timer.blit(buf, x - timer.len() as u16, y, style);
|
||||
}
|
||||
pub fn draw_play_stop (buf: &mut Buffer, x: u16, y: u16, state: &TransportState) {
|
||||
let style = Style::default().gray();
|
||||
match state {
|
||||
TransportState::Rolling => "▶ PLAYING",
|
||||
TransportState::Starting => "READY ...",
|
||||
TransportState::Stopped => "⏹ STOPPED",
|
||||
}.blit(buf, x, y, Some(match state {
|
||||
TransportState::Stopped => style.dim().bold(),
|
||||
TransportState::Starting => style.not_dim().bold(),
|
||||
TransportState::Rolling => style.not_dim().white().bold()
|
||||
}));
|
||||
}
|
||||
pub 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()
|
||||
}))
|
||||
}
|
||||
pub fn draw_dub (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
||||
"⏺ DUB".blit(buf, x, y, Some(if on {
|
||||
Style::default().bold().yellow()
|
||||
} else {
|
||||
Style::default().bold().dim()
|
||||
}))
|
||||
}
|
||||
pub fn draw_mon (buf: &mut Buffer, x: u16, y: u16, on: bool) {
|
||||
"⏺ MON".blit(buf, x, y, 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.phrases.iter().enumerate() {
|
||||
let label = format!("▶ {}", &sequence.name);
|
||||
label.blit(buf, x + 2, y + 3 + (i as u16)*2, Some(if i == s.sequence {
|
||||
label.blit(buf, x + 2, y + 3 + (i as u16)*2, Some(if Some(i) == s.sequence {
|
||||
match s.playing {
|
||||
TransportState::Rolling => style.white().bold(),
|
||||
_ => style.not_dim().bold()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue