merge SceneClip and SceneRow into SceneRows

This commit is contained in:
🪞👃🪞 2024-09-17 00:48:30 +03:00
parent 2352b72377
commit 647cd06060

View file

@ -519,57 +519,43 @@ impl<'a> Content for SceneRows<'a> {
let Self(offset, columns, rows, tracks, scenes) = *self;
Split::down(move |add| {
for (scene, (pulses, _)) in scenes.iter().zip(rows) {
add(&SceneRow(tracks, scene, columns, offset, 1.max((pulses / 96) as u16)))?;
let height = 1.max((pulses / 96) as u16);
let playing = scene.is_playing(tracks);
add(&Fixed::Y(height, Split::right(move |add| {
add(&Fixed::XY(offset.saturating_sub(1), height, Split::right(|add|{
add(&if playing { "" } else { " " })?;
add(&scene.name.read().unwrap().as_str())
})))?;
for (track, (w, _x)) in columns.iter().enumerate() {
add(&Fixed::XY(*w as u16, height, Layers::new(move |add|{
let mut color = COLOR_BG0;
if let (Some(track), Some(Some(clip))) = (
tracks.get(track),
scene.clips.get(track),
) {
if let Some(phrase) = track.phrases.get(*clip) {
add(&Plus::X(1, format!(
"{clip:02} {}",
phrase.read().unwrap().name.read().unwrap()
).as_str()))?;
color = if track.sequence == Some(*clip) {
Nord::PLAYING
} else {
COLOR_BG1
};
}
}
add(&Background(color))
})))?;
}
Ok(())
})))?;
}
Ok(())
})
}
}
struct SceneRow<'a>(
&'a[Sequencer<Tui>], &'a Scene, &'a[(usize, usize)], u16, u16
);
impl<'a> Content for SceneRow<'a> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
let Self(tracks, scene, columns, offset, height) = self;
let playing = scene.is_playing(tracks);
Fixed::Y(*height, Split::right(move |add| {
add(&Fixed::XY(offset.saturating_sub(1), *height, Split::right(|add|{
add(&if playing { "" } else { " " })?;
add(&scene.name.read().unwrap().as_str())
})))?;
for (track, (_w, _x)) in columns.iter().enumerate() {
add(&SceneClip(tracks.get(track), scene.clips.get(track)))?;
}
Ok(())
}))
}
}
struct SceneClip<'a>(Option<&'a Sequencer<Tui>>, Option<&'a Option<usize>>);
impl<'a> Content for SceneClip<'a> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
let Self(track, clip) = self;
Layers::new(move |add|{
let mut color = COLOR_BG0;
if let (Some(track), Some(Some(clip))) = (track, clip) {
if let Some(phrase) = track.phrases.get(*clip) {
add(&format!(
"{clip:02} {}",
phrase.read().unwrap().name.read().unwrap()
).as_str())?;
color = if track.sequence == Some(*clip) { Nord::PLAYING } else { COLOR_BG1 };
}
}
add(&Background(color))
})
}
}
struct ArrangerViewHorizontal<'a, E: Engine>(
&'a Arranger<E>
);