From 7ef97bcf3a1d4d58e21b81a2534cad0466b50de5 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Sat, 13 Jul 2024 22:30:29 +0300 Subject: [PATCH] wip: fix keys rendering (notes still offset though) --- demos/project.edn | 10 ++++----- src/control.rs | 1 + src/core/render.rs | 2 +- src/model.rs | 4 ++-- src/model/arranger.rs | 2 +- src/model/sequencer.rs | 47 +++++++++++++++++++++++++++++++++++++----- src/view/sequencer.rs | 13 +++++++----- 7 files changed, 60 insertions(+), 19 deletions(-) diff --git a/demos/project.edn b/demos/project.edn index a0183597..badf0102 100644 --- a/demos/project.edn +++ b/demos/project.edn @@ -3,11 +3,11 @@ (midi-in "nanoKEY Studio.*capture.*") (audio-out "Komplete.+:playback_FL", "Komplete.+:playback_FR") -(scene { :name "Intro" } _ 0 _ _) -(scene { :name "Hook" } 0 1 0 _) -(scene { :name "Verse" } 1 2 1 _) -(scene { :name "Chorus" } 2 3 2 _) -(scene { :name "Bridge" } 3 4 3 _) +(scene { :name "Intro" } 0 0 _ _) +(scene { :name "Hook" } 1 1 0 _) +(scene { :name "Verse" } 2 2 1 _) +(scene { :name "Chorus" } 3 3 2 _) +(scene { :name "Bridge" } _ 4 3 _) (scene { :name "Outro" } 4 1 4 _) (track { :name "Drums" :gain +0.0 } diff --git a/src/control.rs b/src/control.rs index 604384c0..b10e4a2a 100644 --- a/src/control.rs +++ b/src/control.rs @@ -92,6 +92,7 @@ pub const KEYMAP_GLOBAL: &'static [KeyBinding] = keymap!(App { phrase.notes = notes; phrase.length = phrase.length * 2; }); + app.sequencer.show(app.arranger.phrase())?; Ok(true) }], [Char('l'), NONE, "loop_toggle", "toggle looping", |_app: &mut App| { diff --git a/src/core/render.rs b/src/core/render.rs index 908e6003..027579b9 100644 --- a/src/core/render.rs +++ b/src/core/render.rs @@ -1,6 +1,6 @@ use crate::core::*; pub(crate) use ratatui::prelude::CrosstermBackend; -pub(crate) use ratatui::style::{Stylize, Style, Color}; +pub(crate) use ratatui::style::{Stylize, Style, Color, Modifier}; pub(crate) use ratatui::layout::Rect; pub(crate) use ratatui::buffer::{Buffer, Cell}; use ratatui::widgets::WidgetRef; diff --git a/src/model.rs b/src/model.rs index 99be44a6..cee5db78 100644 --- a/src/model.rs +++ b/src/model.rs @@ -28,7 +28,7 @@ pub struct App { /// Display mode of chain section pub chain_mode: bool, /// Paths to user directories - xdg: Option>, + _xdg: Option>, /// Main audio outputs. pub audio_outs: Vec>>, /// Number of frames requested by process callback @@ -56,7 +56,7 @@ impl App { chunk_size: 0, midi_in: None, midi_ins: vec![], - xdg: Some(xdg), + _xdg: Some(xdg), }) } } diff --git a/src/model/arranger.rs b/src/model/arranger.rs index c99f08df..6980aaec 100644 --- a/src/model/arranger.rs +++ b/src/model/arranger.rs @@ -19,7 +19,7 @@ impl Arranger { pub fn new () -> Self { Self { mode: false, - selected: ArrangerFocus::Mix, + selected: ArrangerFocus::Clip(0, 0), scenes: vec![], tracks: vec![], entered: true, diff --git a/src/model/sequencer.rs b/src/model/sequencer.rs index 1bd5096f..9394f219 100644 --- a/src/model/sequencer.rs +++ b/src/model/sequencer.rs @@ -66,23 +66,48 @@ fn keys_vert () -> Buffer { let area = Rect { x: 0, y: 0, width: 5, height: 64 }; let mut buffer = Buffer::empty(area); buffer_update(&mut buffer, area, &|cell, x, y| { - cell.set_char('▀'); + let y = 63 - y; match x { 0 => { - let (fg, bg) = key_colors(y); + cell.set_char('▀'); + let (fg, bg) = key_colors(6 - y % 6); cell.set_fg(fg); cell.set_bg(bg); }, 1 => { + cell.set_char('▀'); cell.set_fg(Color::White); cell.set_bg(Color::White); - } + }, + 2 => if y % 6 == 0 { + cell.set_char('C'); + }, + 3 => if y % 6 == 0 { + cell.set_symbol(nth_octave(y / 6)); + }, _ => {} } }); buffer } +fn nth_octave (index: u16) -> &'static str { + match index { + 0 => "-1", + 1 => "0", + 2 => "1", + 3 => "2", + 4 => "3", + 5 => "4", + 6 => "5", + 7 => "6", + 8 => "7", + 9 => "8", + 10 => "9", + _ => unreachable!() + } +} + fn key_colors (index: u16) -> (Color, Color) { match index % 6 { 0 => (Color::White, Color::Black), @@ -104,16 +129,28 @@ fn fill_seq_bg (buf: &mut Buffer, length: usize, ppq: usize) -> Usually<()> { let cell = buf.get_mut(x, buf.area.y); cell.set_char('-'); cell.set_style(style); - let character = if ppq > 0 && x as usize % ppq == 0 { '|' } else { '·' }; for y in 0 .. buf.area.height - buf.area.y { let cell = buf.get_mut(x, y); - cell.set_char(character); + cell.set_char(char_seq_bg(ppq, x)); cell.set_fg(Color::Gray); + cell.modifier = Modifier::DIM; } } Ok(()) } +fn char_seq_bg (ppq: usize, x: u16) -> char { + if ppq == 0 { + '·' + } else if x % (4 * ppq as u16) == 0 { + '│' + } else if x % ppq as u16 == 0 { + '╎' + } else { + '·' + } +} + fn fill_seq_fg (buf: &mut Buffer, phrase: &Phrase) -> Usually<()> { let mut notes_on = [false;128]; for x in 0 .. buf.area.width - buf.area.x { diff --git a/src/view/sequencer.rs b/src/view/sequencer.rs index 1e9e03bc..826a043c 100644 --- a/src/view/sequencer.rs +++ b/src/view/sequencer.rs @@ -59,13 +59,13 @@ impl Sequencer { x: area.x + Self::H_KEYS_OFFSET, y: area.y + 1, width: area.width - Self::H_KEYS_OFFSET, - height: area.height - 1 + height: area.height - 2 }; buffer_update(buf, area, &|cell, x, y|{ let src_x = (x + self.time_axis.start) * self.time_axis.scale; let src_y = y + self.note_axis.start; - if src_x < self.buffer.area.width && src_y < self.buffer.area.height { - let src = self.buffer.get(src_x, src_y); + if src_x < self.buffer.area.width && src_y < self.buffer.area.height - 1 { + let src = self.buffer.get(src_x, self.buffer.area.height - src_y); cell.set_symbol(src.symbol()); cell.set_fg(src.fg); } @@ -77,11 +77,14 @@ impl Sequencer { let area = Rect { x: area.x, y: area.y + 1, - width: 2, + width: 5, height: area.height - 2 }; buffer_update(buf, area, &|cell, x, y|{ - *cell = self.keys.get(x, y % 6).clone() + let y = y + self.note_axis.start; + if x < self.keys.area.width && y < self.keys.area.height { + *cell = self.keys.get(x, y).clone() + } }); Ok(area) }