mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
wip: clip launcher
This commit is contained in:
parent
2f52e97c58
commit
90998b1c6e
3 changed files with 78 additions and 52 deletions
|
|
@ -95,9 +95,9 @@ pub fn process (_: &mut Launcher, _: &Client, _: &ProcessScope) -> Control {
|
||||||
}
|
}
|
||||||
pub fn render (state: &Launcher, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
pub fn render (state: &Launcher, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
|
||||||
let Rect { x, y, width, height } = area;
|
let Rect { x, y, width, height } = area;
|
||||||
let track_area = Rect { x: 0, y: 0, width, height: 22 };
|
let track_area = Rect { x: x, y: y, width, height: 22 };
|
||||||
let seq_area = Rect { x: 0, y: 23, width, height: 18 };
|
let seq_area = Rect { x: x, y: y+21, width, height: 20 };
|
||||||
let chain_area = Rect { x: 0, y: 40, width, height: 22 };
|
let chain_area = Rect { x: x, y: y+40, width, height: 22 };
|
||||||
let separator = format!("├{}┤", "-".repeat((width - 2).into()));
|
let separator = format!("├{}┤", "-".repeat((width - 2).into()));
|
||||||
let scenes = draw_scenes(state, buf, x, y);
|
let scenes = draw_scenes(state, buf, x, y);
|
||||||
separator.blit(buf, x, y + 2, Some(Style::default().dim()));
|
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<Rect>
|
||||||
highlight = Some(scenes);
|
highlight = Some(scenes);
|
||||||
}
|
}
|
||||||
draw_crossings(state, buf, x + w - 2, y);
|
draw_crossings(state, buf, x + w - 2, y);
|
||||||
draw_sequencer(state, buf, x, y + 21, width, height - 22)?;
|
|
||||||
draw_box(buf, area);
|
draw_box(buf, area);
|
||||||
draw_highlight(state, buf, &highlight);
|
let style = Some(Style::default().green().dim());
|
||||||
let style = Some(Style::default().green().not_dim());
|
|
||||||
crate::device::chain::draw_as_row(
|
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 {
|
match state.view {
|
||||||
LauncherView::Tracks => draw_box_styled(buf, track_area, style),
|
LauncherView::Tracks => draw_box_styled(buf, track_area, style),
|
||||||
LauncherView::Sequencer => draw_box_styled(buf, seq_area, style),
|
LauncherView::Sequencer => draw_box_styled(buf, seq_area, style),
|
||||||
LauncherView::Chains => draw_box_styled(buf, chain_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 {
|
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());
|
||||||
//" [Tab] ".blit(buf, 1, match state.view {
|
//" [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
|
state: &Launcher, buf: &mut Buffer, x: u16, y: u16, width: u16, height: u16
|
||||||
) -> Usually<()> {
|
) -> Usually<()> {
|
||||||
if let Some(sequencer) = state.tracks.get(state.col().saturating_sub(1)) {
|
if let Some(sequencer) = state.tracks.get(state.col().saturating_sub(1)) {
|
||||||
crate::device::sequencer::horizontal::footer(
|
//crate::device::sequencer::horizontal::footer(
|
||||||
&sequencer.state(), buf, 0, y, width, 0
|
//&sequencer.state(), buf, 0, y, width, 0
|
||||||
);
|
//);
|
||||||
crate::device::sequencer::horizontal::keys(
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
@ -252,18 +258,35 @@ fn draw_highlight (
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle (state: &mut Launcher, event: &AppEvent) -> Usually<bool> {
|
pub fn handle (state: &mut Launcher, event: &AppEvent) -> Usually<bool> {
|
||||||
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<Launcher>] = keymap!(Launcher {
|
pub const KEYMAP: &'static [KeyBinding<Launcher>] = 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],
|
[Char('r'), NONE, "rename", "rename current element", rename],
|
||||||
[F(1), NONE, "toggle_help", "toggle help", toggle_help],
|
[F(1), NONE, "toggle_help", "toggle help", toggle_help],
|
||||||
[Tab, SHIFT, "focus_prev", "focus previous area", focus_prev],
|
[Tab, SHIFT, "focus_prev", "focus previous area", focus_prev],
|
||||||
[Tab, NONE, "focus_next", "focus next area", focus_next],
|
[Tab, NONE, "focus_next", "focus next area", focus_next],
|
||||||
});
|
});
|
||||||
|
pub const KEYMAP_TRACKS: &'static [KeyBinding<Launcher>] = 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<bool> {
|
fn rename (_: &mut Launcher) -> Usually<bool> {
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,8 @@ pub fn process (_: &mut Plugin, _: &Client, _: &ProcessScope) -> Control {
|
||||||
pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
|
pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
|
||||||
-> Usually<Rect>
|
-> Usually<Rect>
|
||||||
{
|
{
|
||||||
let header = draw_header(state, buf, area)?;
|
|
||||||
let Rect { x, y, width, height } = 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 style = Style::default().gray();
|
||||||
let mut width = 40u16;
|
let mut width = 40u16;
|
||||||
match &state.plugin {
|
match &state.plugin {
|
||||||
|
|
@ -58,6 +57,8 @@ pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
|
||||||
width = width.max(label.len() as u16);
|
width = width.max(label.len() as u16);
|
||||||
label.blit(buf, x + 2, y + 3 + i as u16, None);
|
label.blit(buf, x + 2, y + 3 + i as u16, None);
|
||||||
}
|
}
|
||||||
|
draw_box(buf, Rect { x, y, width, height });
|
||||||
|
|
||||||
//let mut height = 3;
|
//let mut height = 3;
|
||||||
//for (i, port) in ports
|
//for (i, port) in ports
|
||||||
//.iter()
|
//.iter()
|
||||||
|
|
@ -78,27 +79,29 @@ pub fn render (state: &Plugin, buf: &mut Buffer, area: Rect)
|
||||||
//});
|
//});
|
||||||
//height = height + 1;
|
//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 + 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 + 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 + 5, &format!(" Parameter 3 0.0"), style);
|
||||||
buf.set_string(x + 1, y + 6, &format!(" Parameter 4 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<Rect> {
|
fn draw_header (state: &Plugin, buf: &mut Buffer, x: u16, y: u16, w: u16) -> Usually<Rect> {
|
||||||
let style = Style::default().gray();
|
let style = Style::default().gray();
|
||||||
buf.set_string(x + 1, y + 1,
|
buf.set_string(x + 1, y + 1,
|
||||||
&format!(" {}", state.name), style.white().bold());
|
&format!(" {}", state.name), style.white().bold());
|
||||||
buf.set_string(x + 13, y + 1,
|
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,
|
buf.set_string(x + 0, y + 2,
|
||||||
&format!("├{}┤", "-".repeat(width as usize - 2)), style.dim());
|
&format!("├{}┤", "-".repeat(w as usize - 2)), style.dim());
|
||||||
Ok(Rect { x, y, width, height: 3 })
|
Ok(Rect { x, y, width: w, height: 3 })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
|
pub fn handle (s: &mut Plugin, event: &AppEvent) -> Usually<bool> {
|
||||||
|
|
|
||||||
|
|
@ -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<Rect> {
|
||||||
|
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) {
|
pub fn lanes (s: &Sequencer, buf: &mut Buffer, x: u16, y: u16, width: u16) {
|
||||||
let bw = Style::default().dim();
|
let bw = Style::default().dim();
|
||||||
let bg = Style::default();
|
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) {
|
pub fn footer (s: &Sequencer, buf: &mut Buffer, mut x: u16, y: u16, width: u16, height: u16) {
|
||||||
let bw = Style::default().dim();
|
let bw = Style::default().dim();
|
||||||
let bg = Style::default();
|
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<Rect> {
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue