mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
wip: replacing Rect with [u16;4] in mixer and sequencer
This commit is contained in:
parent
fa739a49b2
commit
06f8bd1116
14 changed files with 106 additions and 106 deletions
|
|
@ -3,7 +3,7 @@ use crate::*;
|
|||
/// Draw arranger with 1 row per scene.
|
||||
pub fn draw_compact_1 <'a> (
|
||||
state: &Arranger<Tui>, to: &mut Tui
|
||||
) -> Perhaps<Rect> {
|
||||
) -> Perhaps<[u16;4]> {
|
||||
let track_cols = track_clip_name_lengths(state.tracks.as_slice());
|
||||
let scene_rows = (0..=state.scenes.len()).map(|i|(96, 96*i)).collect::<Vec<_>>();
|
||||
draw(state, to, track_cols.as_slice(), scene_rows.as_slice())
|
||||
|
|
@ -12,7 +12,7 @@ pub fn draw_compact_1 <'a> (
|
|||
/// Draw arranger with 2 rows per scene.
|
||||
pub fn draw_compact_2 <'a> (
|
||||
state: &Arranger<Tui>, to: &mut Tui
|
||||
) -> Perhaps<Rect> {
|
||||
) -> Perhaps<[u16;4]> {
|
||||
let track_cols = track_clip_name_lengths(state.tracks.as_slice());
|
||||
let scene_rows = (0..=state.scenes.len()).map(|i|(192, 192*i)).collect::<Vec<_>>();
|
||||
draw(state, to, track_cols.as_slice(), scene_rows.as_slice())
|
||||
|
|
@ -21,7 +21,7 @@ pub fn draw_compact_2 <'a> (
|
|||
/// Draw arranger with number of rows per scene proportional to duration of scene.
|
||||
pub fn draw_expanded <'a> (
|
||||
state: &Arranger<Tui>, to: &mut Tui
|
||||
) -> Perhaps<Rect> {
|
||||
) -> Perhaps<[u16;4]> {
|
||||
let track_cols = track_clip_name_lengths(state.tracks.as_slice());
|
||||
let scene_rows = scene_ppqs(state.tracks.as_slice(), state.scenes.as_slice());
|
||||
draw(state, to, track_cols.as_slice(), scene_rows.as_slice())
|
||||
|
|
@ -32,7 +32,7 @@ pub fn draw <'a, 'b> (
|
|||
to: &mut Tui,
|
||||
cols: &'b [(usize, usize)],
|
||||
rows: &'b [(usize, usize)],
|
||||
) -> Perhaps<Rect> {
|
||||
) -> Perhaps<[u16;4]> {
|
||||
let mut area = to.area();
|
||||
area.height = 2 + (rows[rows.len() - 1].1 / 96) as u16;
|
||||
let offset = 3 + scene_name_max_len(state.scenes.as_ref()) as u16;
|
||||
|
|
@ -52,7 +52,7 @@ pub fn draw <'a, 'b> (
|
|||
struct ColumnSeparators<'a>(u16, &'a [(usize, usize)]);
|
||||
|
||||
impl<'a> Render<Tui> for ColumnSeparators<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
let area = to.area();
|
||||
let Self(offset, cols) = self;
|
||||
let style = Some(Style::default().fg(Nord::SEPARATOR));
|
||||
|
|
@ -69,7 +69,7 @@ impl<'a> Render<Tui> for ColumnSeparators<'a> {
|
|||
struct RowSeparators<'a>(&'a [(usize, usize)]);
|
||||
|
||||
impl<'a> Render<Tui> for RowSeparators<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
let area = to.area();
|
||||
let Self(rows) = self;
|
||||
for (_, y) in rows.iter() {
|
||||
|
|
@ -92,30 +92,30 @@ struct CursorFocus<'a>(
|
|||
);
|
||||
|
||||
impl<'a> Render<Tui> for CursorFocus<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
let mut area = to.area();
|
||||
let Self(selected, offset, cols, rows) = *self;
|
||||
let get_track_area = |t: usize| Rect {
|
||||
x: offset + area.x + cols[t].1 as u16 - 1,
|
||||
y: area.y,
|
||||
width: cols[t].0 as u16,
|
||||
height: area.height
|
||||
};
|
||||
let get_scene_area = |s: usize| Rect {
|
||||
x: area.x,
|
||||
y: 2 + area.y + (rows[s].1 / 96) as u16,
|
||||
width: area.width,
|
||||
height: (rows[s].0 / 96) as u16
|
||||
};
|
||||
let get_clip_area = |t: usize, s: usize| Rect {
|
||||
x: offset + area.x + cols[t].1 as u16 - 1,
|
||||
y: 2 + area.y + (rows[s].1 / 96) as u16,
|
||||
width: cols[t].0 as u16,
|
||||
height: (rows[s].0 / 96) as u16
|
||||
};
|
||||
let mut track_area: Option<Rect> = None;
|
||||
let mut scene_area: Option<Rect> = None;
|
||||
let mut clip_area: Option<Rect> = None;
|
||||
let get_track_area = |t: usize| [
|
||||
offset + area.x() + cols[t].1 as u16 - 1,
|
||||
area.y(),
|
||||
cols[t].0 as u16,
|
||||
area.h()
|
||||
];
|
||||
let get_scene_area = |s: usize| [
|
||||
area.x(),
|
||||
2 + area.y() + (rows[s].1 / 96) as u16,
|
||||
area.w(),
|
||||
(rows[s].0 / 96) as u16
|
||||
];
|
||||
let get_clip_area = |t: usize, s: usize| [
|
||||
offset + area.x() + cols[t].1 as u16 - 1,
|
||||
2 + area.y() + (rows[s].1 / 96) as u16,
|
||||
cols[t].0 as u16,
|
||||
(rows[s].0 / 96) as u16
|
||||
];
|
||||
let mut track_area: Option<[u16;4]> = None;
|
||||
let mut scene_area: Option<[u16;4]> = None;
|
||||
let mut clip_area: Option<[u16;4]> = None;
|
||||
let area = match selected {
|
||||
ArrangerFocus::Mix => {
|
||||
to.fill_bg(area, COLOR_BG0);
|
||||
|
|
@ -132,17 +132,17 @@ impl<'a> Render<Tui> for CursorFocus<'a> {
|
|||
ArrangerFocus::Clip(t, s) => {
|
||||
track_area = Some(get_track_area(t));
|
||||
scene_area = Some(get_scene_area(s));
|
||||
clip_area = Some(get_clip_area(t, s));
|
||||
clip_area = Some(get_clip_area(t, s));
|
||||
area
|
||||
},
|
||||
};
|
||||
if let Some(Rect { x, y, width, height }) = track_area {
|
||||
to.fill_fg(Rect { x, y, width: 1, height }, COLOR_BG5);
|
||||
to.fill_fg(Rect { x: x + width, y, width: 1, height }, COLOR_BG5);
|
||||
if let Some([x, y, width, height]) = track_area {
|
||||
to.fill_fg([x, y, 1, height], COLOR_BG5);
|
||||
to.fill_fg([x + width, y, 1, height], COLOR_BG5);
|
||||
}
|
||||
if let Some(Rect { y, height, .. }) = scene_area {
|
||||
to.fill_ul(Rect { x: area.x, y: y - 1, width: area.width, height: 1 }, COLOR_BG5);
|
||||
to.fill_ul(Rect { x: area.x, y: y + height - 1, width: area.width, height: 1 }, COLOR_BG5);
|
||||
if let Some([_, y, _, height]) = scene_area {
|
||||
to.fill_ul([area.x(), y - 1, area.w(), 1], COLOR_BG5);
|
||||
to.fill_ul([area.x(), y + height - 1, area.w(), 1], COLOR_BG5);
|
||||
}
|
||||
if let Some(clip_area) = clip_area {
|
||||
to.fill_bg(clip_area, COLOR_BG0);
|
||||
|
|
@ -158,35 +158,35 @@ impl<'a> Render<Tui> for CursorFocus<'a> {
|
|||
struct TracksHeader<'a>(u16, &'a[(usize, usize)], &'a [Sequencer]);
|
||||
|
||||
impl<'a> Render<Tui> for TracksHeader<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
let area = to.area();
|
||||
let Self(offset, track_cols, tracks) = *self;
|
||||
let Rect { y, width, .. } = area;
|
||||
let [x, y, width, _] = area;
|
||||
for (track, (w, x)) in tracks.iter().zip(track_cols) {
|
||||
let x = *x as u16;
|
||||
if x > width {
|
||||
break
|
||||
}
|
||||
let name = track.name.read().unwrap();
|
||||
to.fill_bg(Rect { x: offset + x, y, width: *w as u16, height: 2 }, COLOR_BG1);
|
||||
to.fill_bg([offset + x, y, *w as u16, 2], COLOR_BG1);
|
||||
to.blit(&*name, offset + x + 1, y, Some(Style::default().white()))?;
|
||||
}
|
||||
Ok(Some(Rect { x: area.x, y, width, height: 2 }))
|
||||
Ok(Some([x, y, width, 2]))
|
||||
}
|
||||
}
|
||||
|
||||
struct SceneRows<'a>(u16, &'a[(usize, usize)], &'a[(usize, usize)], &'a[Sequencer], &'a[Scene]);
|
||||
|
||||
impl<'a> Render<Tui> for SceneRows<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
let area = to.area();
|
||||
let Self(offset, track_cols, scene_rows, tracks, scenes) = *self;
|
||||
let black = Some(Style::default().fg(Nord::SEPARATOR));
|
||||
let Rect { mut y, height: _height, .. } = area;
|
||||
let [_, mut y, _, _height] = area;
|
||||
for (_, x) in track_cols.iter() {
|
||||
let x = *x as u16;
|
||||
if x > 0 {
|
||||
for y in area.y-2..y-2 {
|
||||
for y in area.y()-2..y-2 {
|
||||
to.blit(&"▎", x - 1, y, black)?;
|
||||
}
|
||||
}
|
||||
|
|
@ -197,7 +197,7 @@ impl<'a> Render<Tui> for SceneRows<'a> {
|
|||
//}
|
||||
let h = 1.max((pulses / 96) as u16);
|
||||
SceneRow(tracks, scene, track_cols, offset)
|
||||
.render(to.with_area(area.x, y, area.width, h))?;
|
||||
.render(to.with_area(area.x(), y, area.w(), h))?;
|
||||
y = y + h
|
||||
}
|
||||
Ok(Some(area))
|
||||
|
|
@ -207,14 +207,14 @@ impl<'a> Render<Tui> for SceneRows<'a> {
|
|||
struct SceneRow<'a>(&'a[Sequencer], &'a Scene, &'a[(usize, usize)], u16);
|
||||
|
||||
impl<'a> Render<Tui> for SceneRow<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
let area = to.area();
|
||||
let Self(tracks, scene, track_cols, offset) = self;
|
||||
let Rect { x, y, width, .. } = area;
|
||||
let [x, y, width, _] = area;
|
||||
let playing = scene.is_playing(tracks);
|
||||
to.blit(&if playing { "▶" } else { " " }, x, y, None)?;
|
||||
to.blit(&*scene.name.read().unwrap(), x + 1, y, Some(Style::default().white()))?;
|
||||
to.fill_bg(Rect { x: x, y, width: offset.saturating_sub(1), height: area.height }, COLOR_BG1);
|
||||
to.fill_bg([x, y, offset.saturating_sub(1), area.h()], COLOR_BG1);
|
||||
for (track, (w, x)) in track_cols.iter().enumerate() {
|
||||
let x = *x as u16 + offset;
|
||||
if x > width {
|
||||
|
|
@ -223,7 +223,7 @@ impl<'a> Render<Tui> for SceneRow<'a> {
|
|||
if let (Some(track), Some(Some(clip))) = (
|
||||
tracks.get(track), scene.clips.get(track)
|
||||
) {
|
||||
SceneClip(track, *clip).render(to.with_area(x, y, *w as u16, area.height))?;
|
||||
SceneClip(track, *clip).render(to.with_area(x, y, *w as u16, area.h()))?;
|
||||
}
|
||||
}
|
||||
Ok(Some(area))
|
||||
|
|
@ -233,14 +233,14 @@ impl<'a> Render<Tui> for SceneRow<'a> {
|
|||
struct SceneClip<'a>(&'a Sequencer, usize);
|
||||
|
||||
impl<'a> Render<Tui> for SceneClip<'a> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<Rect> {
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
let area = to.area();
|
||||
let Self(track, clip) = self;
|
||||
let style = Some(Style::default().white());
|
||||
if let Some(phrase) = track.phrases.get(*clip) {
|
||||
let phrase = phrase.read().unwrap();
|
||||
let name = phrase.name.read().unwrap();
|
||||
to.blit(&format!("{clip:02} {name}"), area.x + 1, area.y, style)?;
|
||||
to.blit(&format!("{clip:02} {name}"), area.x() + 1, area.y(), style)?;
|
||||
to.fill_bg(area, if track.sequence == Some(*clip) {
|
||||
Nord::PLAYING
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue