mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: move more view methods to device trait
This commit is contained in:
parent
17abb3d971
commit
b6d1978a55
4 changed files with 166 additions and 143 deletions
|
|
@ -1,8 +1,43 @@
|
|||
use crate::*;
|
||||
|
||||
impl<T: Has<Vec<Scene>> + Send + Sync> HasScenes for T {}
|
||||
|
||||
pub trait HasScenes: Has<Vec<Scene>> + Send + Sync {
|
||||
fn scenes (&self) -> &Vec<Scene> {
|
||||
Has::<Vec<Scene>>::get(self)
|
||||
}
|
||||
fn scenes_mut (&mut self) -> &mut Vec<Scene> {
|
||||
Has::<Vec<Scene>>::get_mut(self)
|
||||
}
|
||||
fn scenes_with_sizes (
|
||||
&self,
|
||||
editing: bool,
|
||||
height: usize,
|
||||
larger: usize,
|
||||
selected_track: Option<usize>,
|
||||
selected_scene: Option<usize>,
|
||||
) -> impl ScenesSizes<'_> {
|
||||
let mut y = 0;
|
||||
self.scenes().iter().enumerate().map(move|(s, scene)|{
|
||||
let active = editing && selected_track.is_some() && selected_scene == Some(s);
|
||||
let height = if active { larger } else { height };
|
||||
let data = (s, scene, y, y + height);
|
||||
y += height;
|
||||
data
|
||||
})
|
||||
}
|
||||
/// Generate the default name for a new scene
|
||||
fn scene_default_name (&self) -> Arc<str> {
|
||||
format!("Sc{:3>}", self.scenes().len() + 1).into()
|
||||
}
|
||||
fn scene_longest_name (&self) -> usize {
|
||||
self.scenes().iter().map(|s|s.name.len()).fold(0, usize::max)
|
||||
}
|
||||
}
|
||||
|
||||
pub type SceneWith<'a, T: Send + Sync> = (usize, &'a Scene, usize, usize, T);
|
||||
|
||||
pub trait ArrangerSceneRows: Send + Sync {
|
||||
pub trait ScenesView: Send + Sync {
|
||||
/// Default scene height.
|
||||
const H_SCENE: usize = 2;
|
||||
/// Default editor height.
|
||||
|
|
@ -49,6 +84,18 @@ pub trait ArrangerSceneRows: Send + Sync {
|
|||
})))
|
||||
}))
|
||||
}
|
||||
fn scenes_names_2 (&self, theme: ItemTheme) -> impl Content<TuiOut> {
|
||||
let h = self.scenes().len() as u16 * 2;
|
||||
let bg = theme.darker.rgb;
|
||||
Fixed::y(h, Tui::bg(bg, Align::w(Fill::x(Map::new(
|
||||
||self.scenes().iter().skip(self.project.scene_scroll),
|
||||
move|scene: &Scene, index|
|
||||
Push::y(index as u16 * 2u16, Fixed::xy(20, 2,
|
||||
Tui::bg(scene.color.dark.rgb, Align::nw(Bsp::e(
|
||||
format!(" {index:2} "),
|
||||
Tui::fg(Rgb(255, 255, 255),
|
||||
Tui::bold(true, format!("{}", scene.name)))))))))))))
|
||||
}
|
||||
fn scenes_with_prev_color (&self) -> impl Iterator<Item=SceneWith<Option<ItemTheme>>> + Send + Sync {
|
||||
self.scenes_iter().map(|(s, scene, y1, y2)|(s, scene, y1, y2,
|
||||
(s>0).then(||self.arrangement().scenes()[s-1].color)))
|
||||
|
|
@ -102,6 +149,28 @@ pub trait ArrangerSceneRows: Send + Sync {
|
|||
)))
|
||||
})))
|
||||
}
|
||||
fn scenes_clips_2 <'a> (&'a self, theme: ItemTheme) -> impl Content<TuiOut> + use<'a> {
|
||||
let h = self.scenes().len() as u16 * 2;
|
||||
let bg = theme.darker.rgb;
|
||||
Fixed::y(h, Tui::bg(bg, Align::w(Fill::x(Map::new(
|
||||
||self.scenes().iter().skip(self.project.scene_scroll),
|
||||
move|scene: &'a Scene, index1|
|
||||
Push::y(index1 as u16 * 2u16, Fixed::xy(20, 2,
|
||||
Map::new(
|
||||
move||scene.clips.iter().skip(self.project.track_scroll),
|
||||
move|clip: &'a Option<Arc<RwLock<MidiClip>>>, index2|{
|
||||
let (theme, text) = if let Some(clip) = clip {
|
||||
let clip = clip.read().unwrap();
|
||||
(clip.color, clip.name.clone())
|
||||
} else {
|
||||
(scene.color, Default::default())
|
||||
};
|
||||
Push::x(index2 as u16 * 14, Tui::bg(theme.dark.rgb, Bsp::e(
|
||||
format!(" {index1:2} {index2:2} "),
|
||||
Tui::fg(Rgb(255, 255, 255),
|
||||
Tui::bold(true, format!("{}", text))))))
|
||||
}))))))))
|
||||
}
|
||||
fn scenes_with_clip (&self, track_index: usize) -> impl Iterator<Item=SceneWith<'_, Option<ItemTheme>>> + Send + Sync {
|
||||
self.scenes_iter().map(move|(s, scene, y1, y2)|(s, scene, y1, y2,
|
||||
(s>0).then(||self.arrangement().scenes()[s-1].clips[track_index].as_ref()
|
||||
|
|
@ -130,7 +199,7 @@ pub trait ArrangerSceneRows: Send + Sync {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> ArrangerSceneRows for ArrangerView<'a> {
|
||||
impl<'a> ScenesView for ArrangerView<'a> {
|
||||
fn arrangement (&self) -> &Arrangement {
|
||||
self.arrangement
|
||||
}
|
||||
|
|
@ -157,41 +226,6 @@ impl<'a> ArrangerSceneRows for ArrangerView<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Has<Vec<Scene>> + Send + Sync> HasScenes for T {}
|
||||
|
||||
pub trait HasScenes: Has<Vec<Scene>> + Send + Sync {
|
||||
fn scenes (&self) -> &Vec<Scene> {
|
||||
Has::<Vec<Scene>>::get(self)
|
||||
}
|
||||
fn scenes_mut (&mut self) -> &mut Vec<Scene> {
|
||||
Has::<Vec<Scene>>::get_mut(self)
|
||||
}
|
||||
fn scenes_with_sizes (
|
||||
&self,
|
||||
editing: bool,
|
||||
height: usize,
|
||||
larger: usize,
|
||||
selected_track: Option<usize>,
|
||||
selected_scene: Option<usize>,
|
||||
) -> impl ScenesSizes<'_> {
|
||||
let mut y = 0;
|
||||
self.scenes().iter().enumerate().map(move|(s, scene)|{
|
||||
let active = editing && selected_track.is_some() && selected_scene == Some(s);
|
||||
let height = if active { larger } else { height };
|
||||
let data = (s, scene, y, y + height);
|
||||
y += height;
|
||||
data
|
||||
})
|
||||
}
|
||||
/// Generate the default name for a new scene
|
||||
fn scene_default_name (&self) -> Arc<str> {
|
||||
format!("Sc{:3>}", self.scenes().len() + 1).into()
|
||||
}
|
||||
fn scene_longest_name (&self) -> usize {
|
||||
self.scenes().iter().map(|s|s.name.len()).fold(0, usize::max)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: HasScenes + HasTracks> AddScene for T {}
|
||||
|
||||
pub trait AddScene: HasScenes + HasTracks {
|
||||
|
|
|
|||
|
|
@ -45,11 +45,9 @@ pub trait HasTracks: Has<Vec<Track>> + Send + Sync {
|
|||
}
|
||||
}
|
||||
/// Iterate over tracks with their corresponding sizes.
|
||||
fn tracks_with_sizes (
|
||||
&self,
|
||||
selection: &Selection,
|
||||
editor_width: Option<usize>
|
||||
) -> impl TracksSizes<'_> {
|
||||
fn tracks_with_sizes (&self, selection: &Selection, editor_width: Option<usize>)
|
||||
-> impl TracksSizes<'_>
|
||||
{
|
||||
let mut x = 0;
|
||||
let active_track = if let Some(width) = editor_width {
|
||||
selection.track()
|
||||
|
|
@ -69,6 +67,92 @@ pub trait HasTracks: Has<Vec<Track>> + Send + Sync {
|
|||
const TRACK_SPACING: usize = 0;
|
||||
}
|
||||
|
||||
pub trait HasTracksScrolled: HasTracks {
|
||||
fn tracks_scroll (&self) -> usize;
|
||||
}
|
||||
impl HasTracksScrolled for Arrangement {
|
||||
fn tracks_scroll (&self) -> usize { self.tracks_scroll }
|
||||
}
|
||||
impl<'a> HasTracksScrolled for ArrangerView<'a> {
|
||||
fn tracks_scroll (&self) -> usize { self.arrangement.tracks_scroll() }
|
||||
}
|
||||
|
||||
impl<T: HasTracksScrolled + HasSelection> TracksView for T {}
|
||||
|
||||
pub trait TracksView: HasTracks + HasSelection {
|
||||
fn view_track_names (&self, theme: ItemTheme) -> impl Content<TuiOut> + use<'_> {
|
||||
let mut max_outputs = 0u16;
|
||||
for track in self.tracks().iter() {
|
||||
max_outputs = max_outputs.max(track.sequencer.midi_outs.len() as u16);
|
||||
}
|
||||
Bsp::w(
|
||||
Fixed::x(20, Tui::bg(theme.darkest.rgb,
|
||||
col!(Tui::bold(true, "[t]rack"), "[T] Add"))),
|
||||
Align::w(Fixed::y(max_outputs + 1, Tui::bg(theme.darker.rgb,
|
||||
Align::w(Fill::x(Map::new(
|
||||
||self.tracks_with_sizes(&self.project.selection, None).skip(self.track_scroll()),
|
||||
move|(index, track, x1, x2): (usize, &Track, usize, usize), _|
|
||||
Push::x(index as u16 * 14, Fixed::xy(track.width as u16, max_outputs + 1,
|
||||
Tui::bg(track.color.dark.rgb, Align::nw(Bsp::s(Tui::fg(
|
||||
Rgb(255, 255, 255),
|
||||
Tui::bold(true, format!("{}", track.name))
|
||||
), format!("{index} {x1} {x2}")))))))))))))
|
||||
}
|
||||
fn view_track_outputs <'a> (&'a self, theme: ItemTheme) -> impl Content<TuiOut> + use<'a> {
|
||||
let mut max_outputs = 0u16;
|
||||
for track in self.tracks().iter() {
|
||||
max_outputs = max_outputs.max(track.sequencer.midi_outs.len() as u16);
|
||||
}
|
||||
Bsp::w(
|
||||
Fixed::x(20, Tui::bg(theme.darkest.rgb,
|
||||
col!(Tui::bold(true, "[o]utput"), "[O] Add"))),
|
||||
Align::w(Fixed::y(max_outputs + 1, Tui::bg(theme.darker.rgb, Align::w(Fill::x(Map::new(
|
||||
||self.tracks_with_sizes(&self.project.selection, None).skip(self.track_scroll()),
|
||||
move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|
|
||||
Push::x(x2 as u16, Tui::bg(track.color.dark.rgb, Fixed::xy(
|
||||
track.width as u16,
|
||||
max_outputs + 1,
|
||||
Align::nw(Bsp::s(
|
||||
format!("[mut] [sol]"),
|
||||
Map::south(1, ||track.sequencer.midi_outs.iter(),
|
||||
|port, index|Tui::fg(Rgb(255, 255, 255),
|
||||
format!("{index}: {}", port.name())))))))))))))))
|
||||
}
|
||||
fn view_track_inputs <'a> (&'a self, theme: ItemTheme) -> impl Content<TuiOut> + use<'a> {
|
||||
let mut max_inputs = 0u16;
|
||||
for track in self.tracks().iter() {
|
||||
max_inputs = max_inputs.max(track.sequencer.midi_ins.len() as u16);
|
||||
}
|
||||
Bsp::w(
|
||||
Fixed::x(20, Tui::bg(theme.darkest.rgb,
|
||||
col!(Tui::bold(true, "[i]nputs"), "[I] Add"))),
|
||||
Fill::x(Align::w(Fixed::y(max_inputs + 1, Tui::bg(theme.darker.rgb, Align::w(Fill::x(Map::new(
|
||||
||self.tracks_with_sizes(&self.project.selection, None).skip(self.track_scroll()),
|
||||
move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|
|
||||
Push::x(x2 as u16, Fixed::xy(track.width as u16, max_inputs + 1,
|
||||
Tui::bg(track.color.dark.rgb, Align::nw(Bsp::s(
|
||||
format!("[rec] [mon]"),
|
||||
Map::south(1, ||track.sequencer.midi_ins.iter(),
|
||||
|port, index|Tui::fg(Rgb(255, 255, 255),
|
||||
format!("{index}: {}", port.name()))))))))))))))))
|
||||
}
|
||||
fn view_track_devices <'a> (&'a self, theme: ItemTheme) -> impl Content<TuiOut> + use<'a> {
|
||||
let mut max_devices = 2u16;
|
||||
for track in self.tracks().iter() {
|
||||
max_devices = max_devices.max(track.devices.len() as u16);
|
||||
}
|
||||
Bsp::w(
|
||||
Fixed::x(20, Tui::bg(theme.darkest.rgb,
|
||||
col!(Tui::bold(true, "[d]evice"), "[D] Add"))),
|
||||
Fixed::y(max_devices, Tui::bg(theme.darker.rgb, Align::w(Fill::x(Map::new(
|
||||
||self.tracks_with_sizes(&self.project.selection, None).skip(self.track_scroll()),
|
||||
move|(index, track, x1, x2): (usize, &'a Track, usize, usize), _|
|
||||
Push::x(x2 as u16, Fixed::xy(track.width as u16, max_devices + 1,
|
||||
Tui::bg(track.color.dark.rgb, Align::nw(Map::south(1, move||0..max_devices,
|
||||
|_, index|format!("{index}: {}", "--------"))))))))))))
|
||||
}
|
||||
}
|
||||
|
||||
impl Arrangement {
|
||||
/// Add multiple tracks
|
||||
pub fn tracks_add (
|
||||
|
|
|
|||
|
|
@ -119,13 +119,13 @@ impl Sampler {
|
|||
}
|
||||
|
||||
pub fn view_sample_status (&self, note_pt: usize) -> impl Content<TuiOut> + use<'_> {
|
||||
Fixed::x(20, Outer(true, Style::default().fg(Tui::g(96))).enclose(draw_info_v(if let Some((_, sample)) = &self.recording {
|
||||
Fixed::x(20, draw_info_v(if let Some((_, sample)) = &self.recording {
|
||||
Some(sample)
|
||||
} else if let Some(sample) = &self.mapped[note_pt] {
|
||||
Some(sample)
|
||||
} else {
|
||||
None
|
||||
})))
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn view_status (&self, index: usize) -> impl Content<TuiOut> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue