wip: arranger: colors

This commit is contained in:
🪞👃🪞 2024-08-23 00:09:13 +03:00
parent 70b1ec5a02
commit 08327d2ec0
5 changed files with 120 additions and 99 deletions

View file

@ -34,13 +34,13 @@ pub fn draw (
let tracks = state.tracks.as_ref();
let scenes = state.scenes.as_ref();
Layered::new()
.add(FillBg(Nord::bg_lo(state.focused, state.entered)))
.add(ColumnSeparators(offset, cols))
.add(CursorFocus(focus_sequencer, focused, entered, selected, offset, cols, rows))
.add(Split::down()
.add(TracksHeader(offset, cols, tracks))
.add(SceneRows(offset, cols, rows, tracks, scenes)))
.add(RowSeparators(rows))
//.add_ref(&FillBg(Color::Rgb(30, 33, 36)))//COLOR_BG1))//bg_lo(state.focused, state.entered)))
.add_ref(&ColumnSeparators(offset, cols))
.add_ref(&Split::down()
.add_ref(&TracksHeader(offset, cols, tracks))
.add_ref(&SceneRows(offset, cols, rows, tracks, scenes)))
.add_ref(&CursorFocus(focus_sequencer, focused, entered, selected, offset, cols, rows))
.add_ref(&RowSeparators(rows))
.render(buf, area)
}
@ -87,60 +87,43 @@ struct CursorFocus<'a>(
impl<'a> Render for CursorFocus<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let Self(focus_sequencer, focused, entered, selected, offset, cols, rows) = *self;
let 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 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 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 area = match selected {
ArrangerFocus::Mix => if focused
&& entered
&& selected == ArrangerFocus::Mix
{
fill_bg(buf, area, Nord::bg_hi(focused, entered));
ArrangerFocus::Mix => if focused && entered && selected == ArrangerFocus::Mix {
fill_bg(buf, area, COLOR_BG3);
area
} else {
area
},
ArrangerFocus::Track(t) => {
let area = Rect {
x: offset + area.x + cols[t].1 as u16 - 1,
y: area.y,
width: cols[t].0 as u16,
height: area.height
};
fill_bg(buf, area, Nord::bg_hi(focused, entered));
fill_bg(buf, track_area(t), COLOR_BG3);
area
},
ArrangerFocus::Scene(s) => {
let area = Rect {
x: area.x,
y: 2 + area.y + (rows[s].1 / 96) as u16,
width: area.width,
height: (rows[s].0 / 96) as u16
};
fill_bg(buf, area, Nord::bg_hi(focused, entered));
fill_bg(buf, scene_area(s), COLOR_BG3);
area
},
ArrangerFocus::Clip(t, s) => {
let track_area = Rect {
x: offset + area.x + cols[t].1 as u16 - 1,
y: area.y,
width: cols[t].0 as u16,
height: area.height
};
let scene_area = 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 area = 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 lo = Nord::bg_hi(focused, entered);
let hi = Nord::bg_hier(focused, entered);
fill_bg(buf, track_area, lo);
fill_bg(buf, scene_area, lo);
fill_bg(buf, area, hi);
fill_bg(buf, track_area(t), COLOR_BG2);
fill_bg(buf, scene_area(s), COLOR_BG2);
fill_bg(buf, clip_area(t, s), COLOR_BG3);
area
},
};
@ -157,12 +140,14 @@ impl<'a> Render for TracksHeader<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let Self(offset, track_cols, tracks) = *self;
let Rect { y, width, .. } = area;
for (track, (_, x)) in tracks.iter().zip(track_cols) {
for (track, (w, x)) in tracks.iter().zip(track_cols) {
let x = *x as u16;
if x > width {
break
}
track.name.read().unwrap().blit(buf, offset + x + 1, y, Some(Style::default()))?;
let name = track.name.read().unwrap();
fill_bg(buf, Rect { x: offset + x, y, width: *w as u16, height: 2 }, COLOR_BG1);
name.blit(buf, offset + x + 1, y, Some(Style::default().white()))?;
}
Ok(Rect { x: area.x, y, width, height: 2 })
}
@ -184,56 +169,69 @@ impl<'a> Render for SceneRows<'a> {
}
}
for (scene, (pulses, _)) in scenes.iter().zip(scene_rows) {
if y > height {
break
}
//if y > height {
//break
//}
let h = 1.max((pulses / 96) as u16);
scene_row(tracks, buf, Rect {
SceneRow(tracks, scene, track_cols, offset).render(buf, Rect {
x: area.x,
y,
width: area.width,
height: h,//.min(area.height - y)
}, scene, track_cols, offset)?;
})?;
y = y + h
}
Ok(area)
}
}
fn scene_row <'a> (
tracks: &'a[Sequencer],
buf: &mut Buffer,
area: Rect,
scene: &Scene,
track_cols: &[(usize, usize)],
offset: u16
) -> Usually<u16> {
let Rect { y, width, .. } = area;
let playing = scene.is_playing(tracks);
(if playing { "" } else { " " }).blit(buf, area.x, y, None)?;
scene.name.read().unwrap().blit(buf, area.x + 1, y, None)?;
let style = Some(Style::default().white());
for (track, (w, x)) in track_cols.iter().enumerate() {
let x = *x as u16 + offset;
if x > width {
break
}
if let (Some(track), Some(Some(clip))) = (
tracks.get(track), scene.clips.get(track)
) {
if let Some(phrase) = track.phrases.get(*clip) {
let phrase = phrase.read().unwrap();
phrase.name.read().unwrap().blit(buf, x + 1, y, style)?;
if track.sequence == Some(*clip) {
fill_bg(buf, Rect {
x: x - 1,
y,
width: *w as u16,
height: area.height,
}, Nord::PLAYING);
}
struct SceneRow<'a>(&'a[Sequencer], &'a Scene, &'a[(usize, usize)], u16);
impl<'a> Render for SceneRow<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
let Self(tracks, scene, track_cols, offset) = self;
let Rect { x, y, width, .. } = area;
let playing = scene.is_playing(tracks);
(if playing { "" } else { " " }).blit(buf, x, y, None)?;
scene.name.read().unwrap().blit(buf, x + 1, y, Some(Style::default().white()))?;
fill_bg(buf, Rect { x: x, y, width: offset.saturating_sub(1), height: 2 }, COLOR_BG1);
for (track, (w, x)) in track_cols.iter().enumerate() {
let x = *x as u16 + offset;
if x > width {
break
}
if let (Some(track), Some(Some(clip))) = (
tracks.get(track), scene.clips.get(track)
) {
let area = Rect { x, y, width: *w as u16, height: area.height, };
SceneClip(track, *clip).render(buf, area)?;
}
}
Ok(area)
}
}
struct SceneClip<'a>(&'a Sequencer, usize);
impl<'a> Render for SceneClip<'a> {
fn render (&self, buf: &mut Buffer, area: Rect) -> Usually<Rect> {
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();
name.blit(buf, area.x + 1, area.y, style)?;
fill_bg(buf, area, if track.sequence == Some(*clip) {
Nord::PLAYING
} else {
COLOR_BG1
});
} else {
fill_bg(buf, area, COLOR_BG0)
}
Ok(area)
}
Ok((scene.pulses(tracks) / 96) as u16)
}