mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
sequencer zoom; still slooo
This commit is contained in:
parent
939ffe3630
commit
2f96897d39
9 changed files with 111 additions and 73 deletions
|
|
@ -121,22 +121,21 @@ pub fn draw_as_row (
|
||||||
state: &Chain, buf: &mut Buffer, area: Rect, _: Option<Style>
|
state: &Chain, buf: &mut Buffer, area: Rect, _: Option<Style>
|
||||||
) -> Usually<(Rect, Vec<Rect>)> {
|
) -> Usually<(Rect, Vec<Rect>)> {
|
||||||
let Rect { mut x, y, width, height } = area;
|
let Rect { mut x, y, width, height } = area;
|
||||||
x = x + 1;
|
|
||||||
let mut h = 0u16;
|
let mut h = 0u16;
|
||||||
let mut frames = vec![];
|
let mut frames = vec![];
|
||||||
for (i, device) in state.items.iter().enumerate() {
|
for (i, device) in state.items.iter().enumerate() {
|
||||||
let mut x2 = 1u16;
|
let mut x2 = 1u16;
|
||||||
let mut y2 = 1u16;
|
let mut y2 = 1u16;
|
||||||
for port in device.midi_ins()?.iter() {
|
//for port in device.midi_ins()?.iter() {
|
||||||
port.blit(buf, x, y + y2, Some(Style::default()));
|
//port.blit(buf, x, y + y2, Some(Style::default()));
|
||||||
x2 = x2.max(port.len() as u16);
|
//x2 = x2.max(port.len() as u16);
|
||||||
y2 = y2 + 1;
|
//y2 = y2 + 1;
|
||||||
}
|
//}
|
||||||
for port in device.audio_ins()?.iter() {
|
//for port in device.audio_ins()?.iter() {
|
||||||
port.blit(buf, x, y + y2, Some(Style::default()));
|
//port.blit(buf, x, y + y2, Some(Style::default()));
|
||||||
x2 = x2.max(port.len() as u16);
|
//x2 = x2.max(port.len() as u16);
|
||||||
y2 = y2 + 1;
|
//y2 = y2 + 1;
|
||||||
}
|
//}
|
||||||
let width = width.saturating_sub(x).saturating_sub(x2);
|
let width = width.saturating_sub(x).saturating_sub(x2);
|
||||||
let style = Some(if i == state.focus {
|
let style = Some(if i == state.focus {
|
||||||
if state.focused {
|
if state.focused {
|
||||||
|
|
@ -150,17 +149,17 @@ pub fn draw_as_row (
|
||||||
lozenge_left(buf, x + x2, y, height, style);
|
lozenge_left(buf, x + x2, y, height, style);
|
||||||
let frame = device.render(buf, Rect { x: x + x2, y, width, height })?;
|
let frame = device.render(buf, Rect { x: x + x2, y, width, height })?;
|
||||||
lozenge_right(buf, x + x2 + frame.width - 1, y, height, style);
|
lozenge_right(buf, x + x2 + frame.width - 1, y, height, style);
|
||||||
let mut y2 = 1u16;
|
//let mut y2 = 1u16;
|
||||||
for port in device.midi_outs()?.iter() {
|
//for port in device.midi_outs()?.iter() {
|
||||||
port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
|
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
|
||||||
x2 = x2.max(port.len() as u16);
|
//x2 = x2.max(port.len() as u16);
|
||||||
y2 = y2 + 1;
|
//y2 = y2 + 1;
|
||||||
}
|
//}
|
||||||
for port in device.audio_outs()?.iter() {
|
//for port in device.audio_outs()?.iter() {
|
||||||
port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
|
//port.blit(buf, x + x2 + frame.width, y + y2, Some(Style::default()));
|
||||||
x2 = x2.max(port.len() as u16);
|
//x2 = x2.max(port.len() as u16);
|
||||||
y2 = y2 + 1;
|
//y2 = y2 + 1;
|
||||||
}
|
//}
|
||||||
frames.push(frame);
|
frames.push(frame);
|
||||||
h = h.max(frame.height);
|
h = h.max(frame.height);
|
||||||
x = x + frame.width;
|
x = x + frame.width;
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
|
||||||
-> Usually<Rect>
|
-> Usually<Rect>
|
||||||
{
|
{
|
||||||
let Rect { x, y, height, .. } = area;
|
let Rect { x, y, height, .. } = area;
|
||||||
let mut width = 40u16;
|
let mut width = 20u16;
|
||||||
match &state.plugin {
|
match &state.plugin {
|
||||||
Some(PluginKind::LV2(LV2Plugin { port_list, instance, .. })) => {
|
Some(PluginKind::LV2(LV2Plugin { port_list, instance, .. })) => {
|
||||||
let start = state.selected.saturating_sub((height as usize / 2).saturating_sub(1));
|
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 {
|
} else {
|
||||||
port.default_value
|
port.default_value
|
||||||
};
|
};
|
||||||
let label = &format!("C·· M·· {:25} = {value:.03}", port.name);
|
//let label = &format!("C·· M·· {:25} = {value:.03}", port.name);
|
||||||
width = width.max(label.len() as u16);
|
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 {
|
label.blit(buf, x + 2, y + 1 + i as u16 - start as u16, if i == state.selected {
|
||||||
Some(Style::default().green())
|
Some(Style::default().green())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -199,8 +199,8 @@ pub fn render (state: &Launcher, buf: &mut Buffer, mut area: Rect) -> Usually<Re
|
||||||
area.height = y;
|
area.height = y;
|
||||||
if state.show_help {
|
if state.show_help {
|
||||||
let style = Some(Style::default().bold().white().not_dim().on_black().italic());
|
let style = Some(Style::default().bold().white().not_dim().on_black().italic());
|
||||||
let hide = "[Left Right] Track [Up Down] Scene [, .] Value [F1] Toggle help ";
|
let hide = "[Tab] Mode [Arrows] Move [.,] Value [F1] Toggle help ";
|
||||||
hide.blit(buf, width - hide.len() as u16, height - 1, style);
|
hide.blit(buf, x + (width - hide.len() as u16) / 2, height - 1, style);
|
||||||
}
|
}
|
||||||
Ok(area)
|
Ok(area)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,11 @@ pub const KEYMAP: &'static [KeyBinding<Sequencer>] = keymap!(Sequencer {
|
||||||
[Down, NONE, "cursor_down", "move cursor down", cursor_down],
|
[Down, NONE, "cursor_down", "move cursor down", cursor_down],
|
||||||
[Left, NONE, "cursor_left", "move cursor left", cursor_left],
|
[Left, NONE, "cursor_left", "move cursor left", cursor_left],
|
||||||
[Right, NONE, "cursor_right", "move cursor right", cursor_right],
|
[Right, NONE, "cursor_right", "move cursor right", cursor_right],
|
||||||
[Char(']'), NONE, "cursor_inc", "increase note duration", cursor_duration_inc],
|
[Char('.'), NONE, "cursor_inc", "increase note duration", cursor_duration_inc],
|
||||||
[Char('['), NONE, "cursor_dec", "decrease note duration", cursor_duration_dec],
|
[Char(','), NONE, "cursor_dec", "decrease note duration", cursor_duration_dec],
|
||||||
[Char('`'), NONE, "mode_next", "Next view mode", mode_next],
|
[Char('`'), NONE, "mode_next", "Next view mode", mode_next],
|
||||||
[Char('+'), NONE, "zoom_in", "Zoom in", nop],
|
[Char('='), NONE, "zoom_in", "Zoom in", zoom_in],
|
||||||
[Char('-'), NONE, "zoom_out", "Zoom out", nop],
|
[Char('-'), NONE, "zoom_out", "Zoom out", zoom_out],
|
||||||
[Char('a'), NONE, "note_add", "Add note", note_add],
|
[Char('a'), NONE, "note_add", "Add note", note_add],
|
||||||
[Char('z'), NONE, "note_del", "Delete note", note_del],
|
[Char('z'), NONE, "note_del", "Delete note", note_del],
|
||||||
[CapsLock, NONE, "advance", "Toggle auto advance", nop],
|
[CapsLock, NONE, "advance", "Toggle auto advance", nop],
|
||||||
|
|
@ -188,3 +188,11 @@ fn quantize_prev (s: &mut Sequencer) -> Usually<bool> {
|
||||||
Ok(true)
|
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)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,21 +8,40 @@ pub fn draw (
|
||||||
ppq: usize,
|
ppq: usize,
|
||||||
time: usize,
|
time: usize,
|
||||||
time0: usize,
|
time0: usize,
|
||||||
timeZ: usize,
|
time_z: usize,
|
||||||
note: usize,
|
note: usize,
|
||||||
note0: usize,
|
note0: usize,
|
||||||
style: Option<Style>,
|
style: Option<Style>,
|
||||||
) -> Usually<Rect> {
|
) -> Usually<Rect> {
|
||||||
let now = 0;
|
let now = 0;
|
||||||
let notes = &[];
|
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)?;
|
keys(buf, area, note0, notes)?;
|
||||||
timer(buf, area, time0, now);
|
timer(buf, area, time0, now);
|
||||||
if let Some(phrase) = phrase {
|
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()});
|
let style = style.unwrap_or_else(||{Style::default().green().not_dim()});
|
||||||
cursor(buf, area, style, time, note);
|
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)
|
Ok(area)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,58 +70,69 @@ pub fn keys (
|
||||||
let bw = Style::default().dim();
|
let bw = Style::default().dim();
|
||||||
let Rect { x, y, width, height } = area;
|
let Rect { x, y, width, height } = area;
|
||||||
let h = height.saturating_sub(2);
|
let h = height.saturating_sub(2);
|
||||||
for i in 0..h {
|
for index in 0..h {
|
||||||
let y = y + i + 1;
|
let y = y + h - index;
|
||||||
let key = KEYS_VERTICAL[(i % 6) as usize];
|
let key = KEYS_VERTICAL[(index % 6) as usize];
|
||||||
key.blit(buf, x + 1, y, Some(bw));
|
key.blit(buf, x + 1, y, Some(bw));
|
||||||
"█".blit(buf, x + 2, 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()));
|
"|---".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());
|
let note_a = note0 + (index * 2) as usize;
|
||||||
if i % 6 == 0 {
|
if note_a % 12 == 0 {
|
||||||
let octave = format!("C{}", ((note0 - i as usize) / 6) as i8 - 4);
|
let octave = format!("C{}", (note_a / 12) as i8 - 2);
|
||||||
buf.set_string(x + 3, y, &octave, Style::default());
|
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)
|
Ok(area)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lanes (
|
pub fn lanes (
|
||||||
buf: &mut Buffer,
|
buf: &mut Buffer,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
phrase: &Phrase,
|
phrase: &Phrase,
|
||||||
ppq: usize,
|
ppq: usize,
|
||||||
time_zoom: usize,
|
time_z: usize,
|
||||||
time0: usize,
|
time0: usize,
|
||||||
note0: usize,
|
note0: usize,
|
||||||
) {
|
) {
|
||||||
let Rect { x, y, width, height } = area;
|
let Rect { x, y, width, height } = area;
|
||||||
|
let time0 = time0 / time_z;
|
||||||
let time1 = time0 + width as usize;
|
let time1 = time0 + width as usize;
|
||||||
let note1 = note0 + height as usize;
|
let note1 = note0 + height as usize;
|
||||||
let bg = Style::default();
|
let bg = Style::default();
|
||||||
let (bw, wh) = (bg.dim(), bg.white());
|
let (bw, wh) = (bg.dim(), bg.white());
|
||||||
for step in time0..time1 {
|
let offset = 5;
|
||||||
let x = x as usize + 5 + step;
|
for x in x+offset..x+width-offset {
|
||||||
let (a, b) = ((step + 0) * ppq / time_zoom, (step + 1) * ppq / time_zoom,);
|
let step = (x-offset) as usize * time_z;
|
||||||
if step % 4 == 0 {
|
if step % ppq == 0 {
|
||||||
"|".blit(buf, x as u16, y, Some(Style::default().dim()));
|
"|".blit(buf, x as u16, y, Some(Style::default().dim()));
|
||||||
}
|
}
|
||||||
if step % (time_zoom * 4) == 0 {
|
let bar = 4 * ppq;
|
||||||
format!("{}", step / time_zoom / 4 + 1)
|
if step % bar == 0 {
|
||||||
|
format!("{}", (step/bar)+1)
|
||||||
.blit(buf, x as u16, y, Some(Style::default().bold().not_dim()));
|
.blit(buf, x as u16, y, Some(Style::default().bold().not_dim()));
|
||||||
}
|
}
|
||||||
let h = ((note1-note0)/2).saturating_sub(y as usize);
|
let (a, b) = (step, step + time_z);
|
||||||
for k in 0..h {
|
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 (
|
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(note_a 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_b as u8), a, b),
|
||||||
) {
|
) {
|
||||||
(true, true) => ("█", wh),
|
(true, true) => ("█", wh),
|
||||||
(true, false) => ("▀", wh),
|
|
||||||
(false, true) => ("▄", wh),
|
(false, true) => ("▄", wh),
|
||||||
|
(true, false) => ("▀", wh),
|
||||||
(false, false) => ("·", bw),
|
(false, false) => ("·", bw),
|
||||||
};
|
};
|
||||||
let y = y as usize + k;
|
let y = y + height.saturating_sub(index+2) as u16;
|
||||||
character.blit(buf, x as u16, y as u16, Some(style));
|
character.blit(buf, x, y, Some(style));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -121,13 +151,13 @@ pub fn cursor (
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn footer (
|
pub fn footer (
|
||||||
buf: &mut Buffer,
|
buf: &mut Buffer,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
note0: usize,
|
note0: usize,
|
||||||
note: usize,
|
note: usize,
|
||||||
time0: usize,
|
time0: usize,
|
||||||
time: usize,
|
time: usize,
|
||||||
timeZ: usize,
|
time_z: usize,
|
||||||
) {
|
) {
|
||||||
let Rect { mut x, y, width, height } = area;
|
let Rect { mut x, y, width, height } = area;
|
||||||
buf.set_string(x, y + height, format!("├{}┤", "-".repeat((width - 2).into())),
|
buf.set_string(x, y + height, format!("├{}┤", "-".repeat((width - 2).into())),
|
||||||
|
|
@ -138,7 +168,7 @@ pub fn footer (
|
||||||
{
|
{
|
||||||
for (_, [letter, title, value]) in [
|
for (_, [letter, title, value]) in [
|
||||||
["S", &format!("ync"), &format!("<4/4>")],
|
["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")],
|
["N", &format!("ote"), &format!("{} ({}-{})", note0 + note, note0, "X")],
|
||||||
["T", &format!("ime"), &format!("{} ({}-{})", time0 + time, time0 + 1, "X")],
|
["T", &format!("ime"), &format!("{} ({}-{})", time0 + time, time0 + 1, "X")],
|
||||||
].iter().enumerate() {
|
].iter().enumerate() {
|
||||||
|
|
|
||||||
|
|
@ -22,5 +22,5 @@ pub const KEY_STYLE: [Style;12] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
pub const KEYS_VERTICAL: [&'static str; 6] = [
|
pub const KEYS_VERTICAL: [&'static str; 6] = [
|
||||||
"▀", "▀", "▀", "█", "▄", "▄",
|
"▄", "▄", "█", "▀", "▀", "▀",
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ impl Sequencer {
|
||||||
|
|
||||||
view: SequencerView::Horizontal,
|
view: SequencerView::Horizontal,
|
||||||
notes_on: vec![false;128],
|
notes_on: vec![false;128],
|
||||||
note_start: 36,
|
note_start: 12,
|
||||||
note_cursor: 0,
|
note_cursor: 0,
|
||||||
time_zoom: 24,
|
time_zoom: 24,
|
||||||
time_start: 0,
|
time_start: 0,
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ pub fn draw_bpm (buf: &mut Buffer, x: u16, y: u16, bpm: usize) {
|
||||||
let style = Style::default().not_dim();
|
let style = Style::default().not_dim();
|
||||||
"BPM"
|
"BPM"
|
||||||
.blit(buf, x, y, Some(style));
|
.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()));
|
.blit(buf, x + 4, y, Some(style.bold()));
|
||||||
"SYNC"
|
"SYNC"
|
||||||
.blit(buf, x + 13, y, Some(style));
|
.blit(buf, x + 13, y, Some(style));
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ fn main () -> Result<(), Box<dyn Error>> {
|
||||||
let input = ".*nanoKEY.*";
|
let input = ".*nanoKEY.*";
|
||||||
let output = ["Komplete.*:playback_FL", "Komplete.*:playback_FR"];
|
let output = ["Komplete.*:playback_FL", "Komplete.*:playback_FR"];
|
||||||
let (client, _) = Client::new("init", ClientOptions::NO_START_SERVER)?;
|
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;
|
let ppq = timebase.ppq() as usize;
|
||||||
macro_rules! play {
|
macro_rules! play {
|
||||||
($t1:expr => [ $($msg:expr),* $(,)? ]) => {
|
($t1:expr => [ $($msg:expr),* $(,)? ]) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue