From 90998b1c6eea0b0e1e9bd09a55f2ff14649d4fa0 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Mon, 24 Jun 2024 23:30:09 +0300 Subject: [PATCH] wip: clip launcher --- src/device/launcher.rs | 55 +++++++++++++++++++++--------- src/device/plugin.rs | 21 +++++++----- src/device/sequencer/horizontal.rs | 54 ++++++++++++++--------------- 3 files changed, 78 insertions(+), 52 deletions(-) diff --git a/src/device/launcher.rs b/src/device/launcher.rs index d1a3f3ae..f5991873 100644 --- a/src/device/launcher.rs +++ b/src/device/launcher.rs @@ -95,9 +95,9 @@ pub fn process (_: &mut Launcher, _: &Client, _: &ProcessScope) -> Control { } pub fn render (state: &Launcher, buf: &mut Buffer, area: Rect) -> Usually { let Rect { x, y, width, height } = area; - let track_area = Rect { x: 0, y: 0, width, height: 22 }; - let seq_area = Rect { x: 0, y: 23, width, height: 18 }; - let chain_area = Rect { x: 0, y: 40, width, height: 22 }; + let track_area = Rect { x: x, y: y, width, height: 22 }; + let seq_area = Rect { x: x, y: y+21, width, height: 20 }; + let chain_area = Rect { x: x, y: y+40, width, height: 22 }; let separator = format!("├{}┤", "-".repeat((width - 2).into())); let scenes = draw_scenes(state, buf, x, y); separator.blit(buf, x, y + 2, Some(Style::default().dim())); @@ -108,18 +108,18 @@ pub fn render (state: &Launcher, buf: &mut Buffer, area: Rect) -> Usually highlight = Some(scenes); } draw_crossings(state, buf, x + w - 2, y); - draw_sequencer(state, buf, x, y + 21, width, height - 22)?; draw_box(buf, area); - draw_highlight(state, buf, &highlight); - let style = Some(Style::default().green().not_dim()); + let style = Some(Style::default().green().dim()); crate::device::chain::draw_as_row( - &*state.chains[0].state(), buf, chain_area, Some(Style::default().green().dim()) + &*state.chains[0].state(), buf, chain_area, style )?; + draw_highlight(state, buf, &highlight); match state.view { LauncherView::Tracks => draw_box_styled(buf, track_area, style), LauncherView::Sequencer => draw_box_styled(buf, seq_area, style), LauncherView::Chains => draw_box_styled(buf, chain_area, style), }; + draw_sequencer(state, buf, seq_area.x, seq_area.y + 1, seq_area.width, seq_area.height - 2)?; if state.show_help { let style = Some(Style::default().bold().white().not_dim().on_black().italic()); //" [Tab] ".blit(buf, 1, match state.view { @@ -234,12 +234,18 @@ fn draw_sequencer ( state: &Launcher, buf: &mut Buffer, x: u16, y: u16, width: u16, height: u16 ) -> Usually<()> { if let Some(sequencer) = state.tracks.get(state.col().saturating_sub(1)) { - crate::device::sequencer::horizontal::footer( - &sequencer.state(), buf, 0, y, width, 0 - ); + //crate::device::sequencer::horizontal::footer( + //&sequencer.state(), buf, 0, y, width, 0 + //); crate::device::sequencer::horizontal::keys( - &sequencer.state(), buf, Rect { x, y: y + 3, width, height } + &sequencer.state(), buf, Rect { x, y: y + 1, width, height } )?; + crate::device::sequencer::horizontal::lanes( + &sequencer.state(), buf, x, y + 1, width, + ); + crate::device::sequencer::horizontal::cursor( + &sequencer.state(), buf, x, y + 1, + ); } Ok(()) } @@ -252,18 +258,35 @@ fn draw_highlight ( } pub fn handle (state: &mut Launcher, event: &AppEvent) -> Usually { - handle_keymap(state, event, KEYMAP) + Ok(handle_keymap(state, event, KEYMAP)? || match state.view { + LauncherView::Tracks => { + handle_keymap(state, event, KEYMAP_TRACKS)? + }, + LauncherView::Sequencer => { + let i = state.col().saturating_sub(1); + if let Some(sequencer) = state.tracks.get_mut(i) { + crate::device::sequencer::handle(&mut *sequencer.state(), event)? + } else { + true + } + }, + LauncherView::Chains => { + true + } + }) } pub const KEYMAP: &'static [KeyBinding] = keymap!(Launcher { - [Up, NONE, "cursor_up", "move cursor up", cursor_up], - [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('r'), NONE, "rename", "rename current element", rename], [F(1), NONE, "toggle_help", "toggle help", toggle_help], [Tab, SHIFT, "focus_prev", "focus previous area", focus_prev], [Tab, NONE, "focus_next", "focus next area", focus_next], }); +pub const KEYMAP_TRACKS: &'static [KeyBinding] = keymap!(Launcher { + [Up, NONE, "cursor_up", "move cursor up", cursor_up], + [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], +}); fn rename (_: &mut Launcher) -> Usually { Ok(true) } diff --git a/src/device/plugin.rs b/src/device/plugin.rs index b5f82475..6a5c40df 100644 --- a/src/device/plugin.rs +++ b/src/device/plugin.rs @@ -45,9 +45,8 @@ pub fn process (_: &mut Plugin, _: &Client, _: &ProcessScope) -> Control { pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect) -> Usually { - let header = draw_header(state, buf, area)?; let Rect { x, y, width, height } = area; - let height = height.saturating_sub(header.height); + let height = height.saturating_sub(3); let style = Style::default().gray(); let mut width = 40u16; match &state.plugin { @@ -58,6 +57,8 @@ pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect) width = width.max(label.len() as u16); label.blit(buf, x + 2, y + 3 + i as u16, None); } + draw_box(buf, Rect { x, y, width, height }); + //let mut height = 3; //for (i, port) in ports //.iter() @@ -78,27 +79,29 @@ pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect) //}); //height = height + 1; //} - Ok(draw_box(buf, Rect { x, y, width, height })) + //Ok(draw_box(buf, rect { x, y, width, height })) }, _ => { buf.set_string(x + 1, y + 3, &format!(" Parameter 1 0.0"), style); buf.set_string(x + 1, y + 4, &format!(" Parameter 2 0.0"), style); buf.set_string(x + 1, y + 5, &format!(" Parameter 3 0.0"), style); buf.set_string(x + 1, y + 6, &format!(" Parameter 4 0.0"), style); - Ok(draw_box(buf, Rect { x, y, width: 40, height: 7 })) + //Ok(draw_box(buf, Rect { x, y, width: 40, height: 7 })) } - } + }; + draw_header(state, buf, area.x, area.y, width); + Ok(area) } -fn draw_header (state: &Plugin, buf: &mut Buffer, Rect {x, y, width, ..}: Rect) -> Usually { +fn draw_header (state: &Plugin, buf: &mut Buffer, x: u16, y: u16, w: u16) -> Usually { let style = Style::default().gray(); buf.set_string(x + 1, y + 1, &format!(" {}", state.name), style.white().bold()); buf.set_string(x + 13, y + 1, - &format!("│ {}...", &HELM[..(width as usize - 20).min(HELM.len())]), style.not_dim()); + &format!("│ {}...", &HELM[..(w as usize - 20).min(HELM.len())]), style.not_dim()); buf.set_string(x + 0, y + 2, - &format!("├{}┤", "-".repeat(width as usize - 2)), style.dim()); - Ok(Rect { x, y, width, height: 3 }) + &format!("├{}┤", "-".repeat(w as usize - 2)), style.dim()); + Ok(Rect { x, y, width: w, height: 3 }) } pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually { diff --git a/src/device/sequencer/horizontal.rs b/src/device/sequencer/horizontal.rs index c8b559d8..b0a99a0a 100644 --- a/src/device/sequencer/horizontal.rs +++ b/src/device/sequencer/horizontal.rs @@ -35,6 +35,24 @@ pub fn timer (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, beat: usize) { } } +pub fn keys (s: &Sequencer, buf: &mut Buffer, mut area: Rect) -> Usually { + let bw = Style::default().dim(); + let Rect { x, y, .. } = area; + let (note0, note1) = s.note_axis; + let (time0, time1) = s.time_axis; + for i in 0..32.max(note1-note0)/2 { + let y = y + i; + buf.set_string(x + 1, y, KEYS_VERTICAL[(i % 6) as usize], bw); + buf.set_string(x + 2, y, "█", bw); + buf.set_string(x + 5, y, &"·".repeat((time1 - time0) as usize), bw.black()); + if i % 6 == 0 { + let octave = format!("C{}", ((note1 - i) / 6) as i8 - 4); + buf.set_string(x + 3, y, &octave, Style::default()); + } + } + Ok(area) +} + pub fn lanes (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, width: u16) { let bw = Style::default().dim(); let bg = Style::default(); @@ -55,6 +73,15 @@ pub fn lanes (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, width: u16) { } } +pub fn cursor (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16) { + buf.set_string( + x + 6 + s.time_cursor, + y + s.note_cursor / 2, + if s.note_cursor % 2 == 0 { "▀" } else { "▄" }, + Style::default().green().not_dim() + ); +} + pub fn footer (s: &Sequencer, buf: &mut Buffer, mut x: u16, y: u16, width: u16, height: u16) { let bw = Style::default().dim(); let bg = Style::default(); @@ -88,30 +115,3 @@ pub fn footer (s: &Sequencer, buf: &mut Buffer, mut x: u16, y: u16, width: u16, } } } - -pub fn cursor (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16) { - buf.set_string( - x + 6 + s.time_cursor, - y + s.note_cursor / 2, - if s.note_cursor % 2 == 0 { "▀" } else { "▄" }, - Style::default() - ); -} - -pub fn keys (s: &Sequencer, buf: &mut Buffer, mut area: Rect) -> Usually { - let bw = Style::default().dim(); - let Rect { x, y, .. } = area; - let (note0, note1) = s.note_axis; - let (time0, time1) = s.time_axis; - for i in 0..32.max(note1-note0)/2 { - let y = y + i; - buf.set_string(x + 1, y, KEYS_VERTICAL[(i % 6) as usize], bw); - buf.set_string(x + 2, y, "█", bw); - buf.set_string(x + 5, y, &"·".repeat((time1 - time0) as usize), bw.black()); - if i % 6 == 0 { - let octave = format!("C{}", ((note1 - i) / 6) as i8 - 4); - buf.set_string(x + 3, y, &octave, Style::default()); - } - } - Ok(area) -}