mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
display arranger size; io selector pt.1
This commit is contained in:
parent
9531d0e09d
commit
426d2ab89d
3 changed files with 82 additions and 73 deletions
|
|
@ -66,6 +66,10 @@ pub struct Arrangement<E: Engine> {
|
||||||
pub focused: bool,
|
pub focused: bool,
|
||||||
/// Background color of arrangement
|
/// Background color of arrangement
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
|
/// Width of arrangement area at last render
|
||||||
|
pub width: AtomicUsize,
|
||||||
|
/// Height of arrangement area at last render
|
||||||
|
pub height: AtomicUsize,
|
||||||
}
|
}
|
||||||
/// Represents a track in the arrangement
|
/// Represents a track in the arrangement
|
||||||
pub struct ArrangementTrack<E: Engine> {
|
pub struct ArrangementTrack<E: Engine> {
|
||||||
|
|
@ -234,6 +238,8 @@ impl<E: Engine> Arrangement<E> {
|
||||||
tracks: vec![],
|
tracks: vec![],
|
||||||
focused: false,
|
focused: false,
|
||||||
color: Color::Rgb(28, 35, 25),
|
color: Color::Rgb(28, 35, 25),
|
||||||
|
width: 0.into(),
|
||||||
|
height: 0.into(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn activate (&mut self) {
|
pub fn activate (&mut self) {
|
||||||
|
|
@ -534,18 +540,11 @@ impl<E: Engine> ArrangementTrack<E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn longest_name (tracks: &[Self]) -> usize {
|
pub fn longest_name (tracks: &[Self]) -> usize {
|
||||||
tracks.iter()
|
tracks.iter().map(|s|s.name.read().unwrap().len()).fold(0, usize::max)
|
||||||
.map(|s|s.name.read().unwrap().len())
|
|
||||||
.fold(0, usize::max)
|
|
||||||
}
|
|
||||||
pub fn width_inc (&mut self) {
|
|
||||||
self.width += 1;
|
|
||||||
}
|
|
||||||
pub fn width_dec (&mut self) {
|
|
||||||
if self.width > 3 {
|
|
||||||
self.width -= 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
pub const MIN_WIDTH: usize = 3;
|
||||||
|
pub fn width_inc (&mut self) { self.width += 1; }
|
||||||
|
pub fn width_dec (&mut self) { if self.width > Self::MIN_WIDTH { self.width -= 1; } }
|
||||||
}
|
}
|
||||||
/// Focus identification methods
|
/// Focus identification methods
|
||||||
impl ArrangementFocus {
|
impl ArrangementFocus {
|
||||||
|
|
@ -580,24 +579,12 @@ impl ArrangementFocus {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn is_mix (&self) -> bool {
|
pub fn is_mix (&self) -> bool { match self { Self::Mix => true, _ => false } }
|
||||||
match self { Self::Mix => true, _ => false }
|
pub fn is_track (&self) -> bool { match self { Self::Track(_) => true, _ => false } }
|
||||||
}
|
pub fn is_scene (&self) -> bool { match self { Self::Scene(_) => true, _ => false } }
|
||||||
pub fn is_track (&self) -> bool {
|
pub fn is_clip (&self) -> bool { match self { Self::Clip(_, _) => true, _ => false } }
|
||||||
match self { Self::Track(_) => true, _ => false }
|
|
||||||
}
|
|
||||||
pub fn is_scene (&self) -> bool {
|
|
||||||
match self { Self::Scene(_) => true, _ => false }
|
|
||||||
}
|
|
||||||
pub fn is_clip (&self) -> bool {
|
|
||||||
match self { Self::Clip(_, _) => true, _ => false }
|
|
||||||
}
|
|
||||||
pub fn track (&self) -> Option<usize> {
|
pub fn track (&self) -> Option<usize> {
|
||||||
match self {
|
match self { Self::Clip(t, _) => Some(*t), Self::Track(t) => Some(*t), _ => None }
|
||||||
Self::Clip(t, _) => Some(*t),
|
|
||||||
Self::Track(t) => Some(*t),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn track_next (&mut self, last_track: usize) {
|
pub fn track_next (&mut self, last_track: usize) {
|
||||||
*self = match self {
|
*self = match self {
|
||||||
|
|
@ -624,11 +611,7 @@ impl ArrangementFocus {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn scene (&self) -> Option<usize> {
|
pub fn scene (&self) -> Option<usize> {
|
||||||
match self {
|
match self { Self::Clip(_, s) => Some(*s), Self::Scene(s) => Some(*s), _ => None }
|
||||||
Self::Clip(_, s) => Some(*s),
|
|
||||||
Self::Scene(s) => Some(*s),
|
|
||||||
_ => None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn scene_next (&mut self, last_scene: usize) {
|
pub fn scene_next (&mut self, last_scene: usize) {
|
||||||
*self = match self {
|
*self = match self {
|
||||||
|
|
@ -682,7 +665,9 @@ impl Scene {
|
||||||
}
|
}
|
||||||
/// Returns the pulse length of the longest phrase in the scene
|
/// Returns the pulse length of the longest phrase in the scene
|
||||||
pub fn pulses (&self) -> usize {
|
pub fn pulses (&self) -> usize {
|
||||||
self.clips.iter().fold(0, |a, p|a.max(p.as_ref().map(|q|q.read().unwrap().length).unwrap_or(0)))
|
self.clips.iter().fold(0, |a, p|{
|
||||||
|
a.max(p.as_ref().map(|q|q.read().unwrap().length).unwrap_or(0))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
/// Returns true if all phrases in the scene are currently playing
|
/// Returns true if all phrases in the scene are currently playing
|
||||||
pub fn is_playing <E: Engine> (&self, tracks: &[ArrangementTrack<E>]) -> bool {
|
pub fn is_playing <E: Engine> (&self, tracks: &[ArrangementTrack<E>]) -> bool {
|
||||||
|
|
@ -714,15 +699,9 @@ impl Scene {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn longest_name (scenes: &[Self]) -> usize {
|
pub fn longest_name (scenes: &[Self]) -> usize {
|
||||||
scenes.iter()
|
scenes.iter().map(|s|s.name.read().unwrap().len()).fold(0, usize::max)
|
||||||
.map(|s|s.name.read().unwrap().len())
|
|
||||||
.fold(0, usize::max)
|
|
||||||
}
|
}
|
||||||
pub fn clip (&self, index: usize) -> Option<&Arc<RwLock<Phrase>>> {
|
pub fn clip (&self, index: usize) -> Option<&Arc<RwLock<Phrase>>> {
|
||||||
if let Some(Some(clip)) = self.clips.get(index) {
|
match self.clips.get(index) { Some(Some(clip)) => Some(clip), _ => None }
|
||||||
Some(clip)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,8 @@ impl Content for ArrangerStatusBar {
|
||||||
let commands = match self {
|
let commands = match self {
|
||||||
Self::ArrangementMix => command(&[
|
Self::ArrangementMix => command(&[
|
||||||
["", "c", "olor"],
|
["", "c", "olor"],
|
||||||
["", ",.", "scale rows"],
|
["", ",.", "resize"],
|
||||||
["", "+-", "resize view"],
|
["", "+-", "zoom"],
|
||||||
["", "Enter", " stop all"],
|
["", "Enter", " stop all"],
|
||||||
]),
|
]),
|
||||||
Self::ArrangementClip => command(&[
|
Self::ArrangementClip => command(&[
|
||||||
|
|
@ -142,12 +142,21 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
||||||
let border = Lozenge(Style::default().bg(border_bg).fg(border_fg));
|
let border = Lozenge(Style::default().bg(border_bg).fg(border_fg));
|
||||||
let track_title_h = 3u16;
|
let track_title_h = 3u16;
|
||||||
let scene_title_w = 3 + Scene::longest_name(scenes) as u16; // x of 1st track
|
let scene_title_w = 3 + Scene::longest_name(scenes) as u16; // x of 1st track
|
||||||
Layers::new(move |add|{
|
let content = Layers::new(move |add|{
|
||||||
let rows: &[(usize, usize)] = rows.as_ref();
|
let rows: &[(usize, usize)] = rows.as_ref();
|
||||||
let cols: &[(usize, usize)] = cols.as_ref();
|
let cols: &[(usize, usize)] = cols.as_ref();
|
||||||
|
let any_size = |_|Ok(Some([0,0]));
|
||||||
|
|
||||||
|
// store render area
|
||||||
|
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
|
||||||
|
let [x, y, w, h] = to.area();
|
||||||
|
self.0.width.store(w as usize, Ordering::Relaxed);
|
||||||
|
self.0.height.store(h as usize, Ordering::Relaxed);
|
||||||
|
Ok(())
|
||||||
|
}))?;
|
||||||
|
|
||||||
// column separators
|
// column separators
|
||||||
add(&CustomWidget::new(|_|Ok(Some([0,0])), move|to: &mut TuiOutput|{
|
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
let style = Some(Style::default().fg(COLOR_SEPARATOR));
|
let style = Some(Style::default().fg(COLOR_SEPARATOR));
|
||||||
for x in cols.iter().map(|col|col.1) {
|
for x in cols.iter().map(|col|col.1) {
|
||||||
|
|
@ -158,7 +167,7 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
||||||
}))?;
|
}))?;
|
||||||
|
|
||||||
// row separators
|
// row separators
|
||||||
add(&CustomWidget::new(|_|Ok(Some([0,0])), move|to: &mut TuiOutput|{
|
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
for y in rows.iter().map(|row|row.1) {
|
for y in rows.iter().map(|row|row.1) {
|
||||||
let y = area.y() + (y / PPQ) as u16 + 1;
|
let y = area.y() + (y / PPQ) as u16 + 1;
|
||||||
|
|
@ -175,7 +184,7 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
||||||
}))?;
|
}))?;
|
||||||
|
|
||||||
// track titles
|
// track titles
|
||||||
let track_titles = row!((track, w) in tracks.iter().zip(cols.iter().map(|col|col.0))=>{
|
let header = row!((track, w) in tracks.iter().zip(cols.iter().map(|col|col.0))=>{
|
||||||
let name = track.name.read().unwrap();
|
let name = track.name.read().unwrap();
|
||||||
let max_w = w.saturating_sub(1).min(name.len()).max(2);
|
let max_w = w.saturating_sub(1).min(name.len()).max(2);
|
||||||
let name = format!("▎{}", &name[0..max_w]);
|
let name = format!("▎{}", &name[0..max_w]);
|
||||||
|
|
@ -188,9 +197,16 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
||||||
.map(|t|format!("▎{t:>}"))
|
.map(|t|format!("▎{t:>}"))
|
||||||
.unwrap_or(String::from("▎"));
|
.unwrap_or(String::from("▎"));
|
||||||
let until_next = player.next_phrase.as_ref()
|
let until_next = player.next_phrase.as_ref()
|
||||||
.map(|(t, _)|format!("▎{:>}", clock.format_beats(t.load(Ordering::Relaxed))))
|
.map(|(t, _)|format!("▎-{:>}", clock.format_beats(t.load(Ordering::Relaxed))))
|
||||||
.unwrap_or(String::from("▎"));
|
.unwrap_or(String::from("▎"));
|
||||||
col!(name, elapsed, until_next)
|
col!(
|
||||||
|
name,
|
||||||
|
"▎> 12345",
|
||||||
|
"▎< 12345",
|
||||||
|
"▎m s r o",
|
||||||
|
elapsed,
|
||||||
|
until_next
|
||||||
|
)
|
||||||
.min_xy(w as u16, track_title_h)
|
.min_xy(w as u16, track_title_h)
|
||||||
.bg(track.color)
|
.bg(track.color)
|
||||||
.push_x(scene_title_w)
|
.push_x(scene_title_w)
|
||||||
|
|
@ -218,7 +234,9 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
||||||
add(&Background(color))
|
add(&Background(color))
|
||||||
}).fixed_xy(w, h);
|
}).fixed_xy(w, h);
|
||||||
|
|
||||||
add(&col!(track_titles, col!(
|
add(&col!(
|
||||||
|
header,
|
||||||
|
col!(
|
||||||
// scenes:
|
// scenes:
|
||||||
(scene, pulses) in scenes.iter().zip(rows.iter().map(|row|row.0)) => {
|
(scene, pulses) in scenes.iter().zip(rows.iter().map(|row|row.0)) => {
|
||||||
let height = 1.max((pulses / PPQ) as u16);
|
let height = 1.max((pulses / PPQ) as u16);
|
||||||
|
|
@ -233,10 +251,11 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}).fixed_y(height)
|
}).fixed_y(height)
|
||||||
}
|
}
|
||||||
)))?;
|
),
|
||||||
|
))?;
|
||||||
|
|
||||||
// cursor
|
// cursor
|
||||||
add(&CustomWidget::new(|_|Ok(Some([0,0])), move|to: &mut TuiOutput|{
|
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{
|
||||||
let area = to.area();
|
let area = to.area();
|
||||||
let focused = state.focused;
|
let focused = state.focused;
|
||||||
let selected = state.selected;
|
let selected = state.selected;
|
||||||
|
|
@ -301,7 +320,18 @@ impl<'a> Content for VerticalArranger<'a, Tui> {
|
||||||
}))?;
|
}))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}).bg(bg).grow_y(1).border(border)
|
}).bg(bg).grow_y(1).border(border);
|
||||||
|
|
||||||
|
let title_color = if self.0.focused {
|
||||||
|
Color::Rgb(150, 160, 90)
|
||||||
|
} else {
|
||||||
|
Color::Rgb(120, 130, 100)
|
||||||
|
};
|
||||||
|
let w = self.0.width.load(Ordering::Relaxed);
|
||||||
|
let h = self.0.height.load(Ordering::Relaxed);
|
||||||
|
let lower_right = TuiStyle::fg(format!("{w}x{h}"), title_color)
|
||||||
|
.pull_x(1).align_se().fill_xy();
|
||||||
|
lay!(content, lower_right)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'a> Content for HorizontalArranger<'a, Tui> {
|
impl<'a> Content for HorizontalArranger<'a, Tui> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue