sequencer zoom; still slooo

This commit is contained in:
🪞👃🪞 2024-07-02 16:30:16 +03:00
parent 939ffe3630
commit 2f96897d39
9 changed files with 111 additions and 73 deletions

View file

@ -121,22 +121,21 @@ pub fn draw_as_row (
state: &Chain, buf: &mut Buffer, area: Rect, _: Option<Style>
) -> Usually<(Rect, Vec<Rect>)> {
let Rect { mut x, y, width, height } = area;
x = x + 1;
let mut h = 0u16;
let mut frames = vec![];
for (i, device) in state.items.iter().enumerate() {
let mut x2 = 1u16;
let mut y2 = 1u16;
for port in device.midi_ins()?.iter() {
port.blit(buf, x, y + y2, Some(Style::default()));
x2 = x2.max(port.len() as u16);
y2 = y2 + 1;
}
for port in device.audio_ins()?.iter() {
port.blit(buf, x, y + y2, Some(Style::default()));
x2 = x2.max(port.len() as u16);
y2 = y2 + 1;
}
//for port in device.midi_ins()?.iter() {
//port.blit(buf, x, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
//for port in device.audio_ins()?.iter() {
//port.blit(buf, x, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
let width = width.saturating_sub(x).saturating_sub(x2);
let style = Some(if i == state.focus {
if state.focused {
@ -150,17 +149,17 @@ pub fn draw_as_row (
lozenge_left(buf, x + x2, y, height, style);
let frame = device.render(buf, Rect { x: x + x2, y, width, height })?;
lozenge_right(buf, x + x2 + frame.width - 1, y, height, style);
let mut y2 = 1u16;
for port in device.midi_outs()?.iter() {
port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
x2 = x2.max(port.len() as u16);
y2 = y2 + 1;
}
for port in device.audio_outs()?.iter() {
port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
x2 = x2.max(port.len() as u16);
y2 = y2 + 1;
}
//let mut y2 = 1u16;
//for port in device.midi_outs()?.iter() {
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
//for port in device.audio_outs()?.iter() {
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
//x2 = x2.max(port.len() as u16);
//y2 = y2 + 1;
//}
frames.push(frame);
h = h.max(frame.height);
x = x + frame.width;

View file

@ -172,7 +172,7 @@ pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
-> Usually<Rect>
{
let Rect { x, y, height, .. } = area;
let mut width = 40u16;
let mut width = 20u16;
match &state.plugin {
Some(PluginKind::LV2(LV2Plugin { port_list, instance, .. })) => {
let start = state.selected.saturating_sub((height as usize / 2).saturating_sub(1));
@ -185,8 +185,9 @@ pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
} else {
port.default_value
};
let label = &format!("C·· M·· {:25} = {value:.03}", port.name);
width = width.max(label.len() as u16);
//let label = &format!("C·· M·· {:25} = {value:.03}", port.name);
let label = &format!("{:25} = {value:.03}", port.name);
width = width.max(label.len() as u16 + 4);
label.blit(buf, x + 2, y + 1 + i as u16 - start as u16, if i == state.selected {
Some(Style::default().green())
} else {

View file

@ -199,8 +199,8 @@ pub fn render (state: &Launcher, buf: &mut Buffer, mut area: Rect) -> Usually<Re
area.height = y;
if state.show_help {
let style = Some(Style::default().bold().white().not_dim().on_black().italic());
let hide = "[Left Right] Track [Up Down] Scene [, .] Value [F1] Toggle help ";
hide.blit(buf, width - hide.len() as u16, height - 1, style);
let hide = "[Tab] Mode [Arrows] Move [.,] Value [F1] Toggle help ";
hide.blit(buf, x + (width - hide.len() as u16) / 2, height - 1, style);
}
Ok(area)
}

View file

@ -8,11 +8,11 @@ pub const KEYMAP: &'static [KeyBinding<Sequencer>] = keymap!(Sequencer {
[Down, NONE, "cursor_down", "move cursor down", cursor_down],
[Left, NONE, "cursor_left", "move cursor left", cursor_left],
[Right, NONE, "cursor_right", "move cursor right", cursor_right],
[Char(']'), NONE, "cursor_inc", "increase note duration", cursor_duration_inc],
[Char('['), NONE, "cursor_dec", "decrease note duration", cursor_duration_dec],
[Char('.'), NONE, "cursor_inc", "increase note duration", cursor_duration_inc],
[Char(','), NONE, "cursor_dec", "decrease note duration", cursor_duration_dec],
[Char('`'), NONE, "mode_next", "Next view mode", mode_next],
[Char('+'), NONE, "zoom_in", "Zoom in", nop],
[Char('-'), NONE, "zoom_out", "Zoom out", nop],
[Char('='), NONE, "zoom_in", "Zoom in", zoom_in],
[Char('-'), NONE, "zoom_out", "Zoom out", zoom_out],
[Char('a'), NONE, "note_add", "Add note", note_add],
[Char('z'), NONE, "note_del", "Delete note", note_del],
[CapsLock, NONE, "advance", "Toggle auto advance", nop],
@ -188,3 +188,11 @@ fn quantize_prev (s: &mut Sequencer) -> Usually<bool> {
Ok(true)
}
fn zoom_in (s: &mut Sequencer) -> Usually<bool> {
s.time_zoom = s.time_zoom / 2;
Ok(true)
}
fn zoom_out (s: &mut Sequencer) -> Usually<bool> {
s.time_zoom = s.time_zoom * 2;
Ok(true)
}

View file

@ -8,21 +8,40 @@ pub fn draw (
ppq: usize,
time: usize,
time0: usize,
timeZ: usize,
time_z: usize,
note: usize,
note0: usize,
style: Option<Style>,
) -> Usually<Rect> {
let now = 0;
let notes = &[];
match time_z {
1 => "1/384",
2 => "1/192",
3 => "1/128",
4 => "1/96",
6 => "1/64",
8 => "1/48",
12 => "1/32",
16 => "1/24",
24 => "1/16",
32 => "1/12",
48 => "1/8",
64 => "1/6",
96 => "1/4",
128 => "1/3",
192 => "1/2",
384 => "1/1",
_ => ""
}.blit(buf, area.x, area.y, Some(Style::default().dim()));
keys(buf, area, note0, notes)?;
timer(buf, area, time0, now);
if let Some(phrase) = phrase {
lanes(buf, area, phrase, ppq, timeZ, time0, note0);
lanes(buf, area, phrase, ppq, time_z, time0, note0);
}
let style = style.unwrap_or_else(||{Style::default().green().not_dim()});
cursor(buf, area, style, time, note);
//footer(buf, area, note0, note, time0, time, timeZ);
//footer(buf, area, note0, note, time0, time, time_z);
Ok(area)
}
@ -51,58 +70,69 @@ pub fn keys (
let bw = Style::default().dim();
let Rect { x, y, width, height } = area;
let h = height.saturating_sub(2);
for i in 0..h {
let y = y + i + 1;
let key = KEYS_VERTICAL[(i % 6) as usize];
for index in 0..h {
let y = y + h - index;
let key = KEYS_VERTICAL[(index % 6) as usize];
key.blit(buf, x + 1, y, Some(bw));
"".blit(buf, x + 2, y, Some(bw));
"|---".repeat(width.saturating_sub(6) as usize).blit(buf, x + 5, y, Some(bw.black()));
//buf.set_string(x + 3, y, &format!("{i}"), Style::default());
if i % 6 == 0 {
let octave = format!("C{}", ((note0 - i as usize) / 6) as i8 - 4);
buf.set_string(x + 3, y, &octave, Style::default());
let note_a = note0 + (index * 2) as usize;
if note_a % 12 == 0 {
let octave = format!("C{}", (note_a / 12) as i8 - 2);
octave.blit(buf, x + 3, y, None);
continue
}
let note_b = note0 + (index * 2) as usize;
if note_b % 12 == 0 {
let octave = format!("C{}", (note_b / 12) as i8 - 2);
octave.blit(buf, x + 3, y, None);
continue
}
}
Ok(area)
}
pub fn lanes (
buf: &mut Buffer,
area: Rect,
phrase: &Phrase,
ppq: usize,
time_zoom: usize,
time0: usize,
note0: usize,
buf: &mut Buffer,
area: Rect,
phrase: &Phrase,
ppq: usize,
time_z: usize,
time0: usize,
note0: usize,
) {
let Rect { x, y, width, height } = area;
let time0 = time0 / time_z;
let time1 = time0 + width as usize;
let note1 = note0 + height as usize;
let bg = Style::default();
let (bw, wh) = (bg.dim(), bg.white());
for step in time0..time1 {
let x = x as usize + 5 + step;
let (a, b) = ((step + 0) * ppq / time_zoom, (step + 1) * ppq / time_zoom,);
if step % 4 == 0 {
let offset = 5;
for x in x+offset..x+width-offset {
let step = (x-offset) as usize * time_z;
if step % ppq == 0 {
"|".blit(buf, x as u16, y, Some(Style::default().dim()));
}
if step % (time_zoom * 4) == 0 {
format!("{}", step / time_zoom / 4 + 1)
let bar = 4 * ppq;
if step % bar == 0 {
format!("{}", (step/bar)+1)
.blit(buf, x as u16, y, Some(Style::default().bold().not_dim()));
}
let h = ((note1-note0)/2).saturating_sub(y as usize);
for k in 0..h {
let (a, b) = (step, step + time_z);
for index in 0..height-2 {
let note_a = note0 + index as usize * 2;
let note_b = note0 + index as usize * 2 + 1;
let (character, style) = match (
contains_note_on(phrase, u7::from_int_lossy((note0 + k * 2 + 0) as u8), a, b),
contains_note_on(phrase, u7::from_int_lossy((note0 + k * 2 + 1) as u8), a, b),
contains_note_on(phrase, u7::from_int_lossy(note_a as u8), a, b),
contains_note_on(phrase, u7::from_int_lossy(note_b as u8), a, b),
) {
(true, true) => ("", wh),
(true, false) => ("", wh),
(false, true) => ("", wh),
(true, false) => ("", wh),
(false, false) => ("·", bw),
};
let y = y as usize + k;
character.blit(buf, x as u16, y as u16, Some(style));
let y = y + height.saturating_sub(index+2) as u16;
character.blit(buf, x, y, Some(style));
}
}
}
@ -121,13 +151,13 @@ pub fn cursor (
}
pub fn footer (
buf: &mut Buffer,
area: Rect,
note0: usize,
note: usize,
time0: usize,
time: usize,
timeZ: usize,
buf: &mut Buffer,
area: Rect,
note0: usize,
note: usize,
time0: usize,
time: usize,
time_z: usize,
) {
let Rect { mut x, y, width, height } = area;
buf.set_string(x, y + height, format!("{}", "-".repeat((width - 2).into())),
@ -138,7 +168,7 @@ pub fn footer (
{
for (_, [letter, title, value]) in [
["S", &format!("ync"), &format!("<4/4>")],
["Q", &format!("uant"), &format!("<1/{}>", 4 * timeZ)],
["Q", &format!("uant"), &format!("<1/{}>", 4 * time_z)],
["N", &format!("ote"), &format!("{} ({}-{})", note0 + note, note0, "X")],
["T", &format!("ime"), &format!("{} ({}-{})", time0 + time, time0 + 1, "X")],
].iter().enumerate() {

View file

@ -22,5 +22,5 @@ pub const KEY_STYLE: [Style;12] = [
];
pub const KEYS_VERTICAL: [&'static str; 6] = [
"", "", "", "", "", "",
"", "", "", "", "", "",
];

View file

@ -77,7 +77,7 @@ impl Sequencer {
view: SequencerView::Horizontal,
notes_on: vec![false;128],
note_start: 36,
note_start: 12,
note_cursor: 0,
time_zoom: 24,
time_start: 0,

View file

@ -55,7 +55,7 @@ pub fn draw_bpm (buf: &mut Buffer, x: u16, y: u16, bpm: usize) {
let style = Style::default().not_dim();
"BPM"
.blit(buf, x, y, Some(style));
format!("{:03}.{:03}", bpm / 1000, bpm % 1000)
format!("{}.{:03}", bpm as usize, bpm % 1)
.blit(buf, x + 4, y, Some(style.bold()));
"SYNC"
.blit(buf, x + 13, y, Some(style));

View file

@ -43,7 +43,7 @@ fn main () -> Result<(), Box<dyn Error>> {
let input = ".*nanoKEY.*";
let output = ["Komplete.*:playback_FL", "Komplete.*:playback_FR"];
let (client, _) = Client::new("init", ClientOptions::NO_START_SERVER)?;
let timebase = Arc::new(Timebase::new(client.sample_rate() as f64, 60.0, 96.0));
let timebase = Arc::new(Timebase::new(client.sample_rate() as f64, 125.0, 96.0));
let ppq = timebase.ppq() as usize;
macro_rules! play {
($t1:expr => [ $($msg:expr),* $(,)? ]) => {