display arranger size; io selector pt.1

This commit is contained in:
🪞👃🪞 2024-10-30 21:58:45 +02:00
parent 9531d0e09d
commit 426d2ab89d
3 changed files with 82 additions and 73 deletions

View file

@ -66,6 +66,10 @@ pub struct Arrangement<E: Engine> {
pub focused: bool,
/// Background color of arrangement
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
pub struct ArrangementTrack<E: Engine> {
@ -234,6 +238,8 @@ impl<E: Engine> Arrangement<E> {
tracks: vec![],
focused: false,
color: Color::Rgb(28, 35, 25),
width: 0.into(),
height: 0.into(),
}
}
pub fn activate (&mut self) {
@ -534,18 +540,11 @@ impl<E: Engine> ArrangementTrack<E> {
}
}
pub fn longest_name (tracks: &[Self]) -> usize {
tracks.iter()
.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;
}
tracks.iter().map(|s|s.name.read().unwrap().len()).fold(0, usize::max)
}
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
impl ArrangementFocus {
@ -580,24 +579,12 @@ impl ArrangementFocus {
}
})
}
pub fn is_mix (&self) -> bool {
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_clip (&self) -> bool {
match self { Self::Clip(_, _) => true, _ => false }
}
pub fn is_mix (&self) -> bool { 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_clip (&self) -> bool { match self { Self::Clip(_, _) => true, _ => false } }
pub fn track (&self) -> Option<usize> {
match self {
Self::Clip(t, _) => Some(*t),
Self::Track(t) => Some(*t),
_ => None
}
match self { Self::Clip(t, _) => Some(*t), Self::Track(t) => Some(*t), _ => None }
}
pub fn track_next (&mut self, last_track: usize) {
*self = match self {
@ -624,11 +611,7 @@ impl ArrangementFocus {
}
}
pub fn scene (&self) -> Option<usize> {
match self {
Self::Clip(_, s) => Some(*s),
Self::Scene(s) => Some(*s),
_ => None
}
match self { Self::Clip(_, s) => Some(*s), Self::Scene(s) => Some(*s), _ => None }
}
pub fn scene_next (&mut self, last_scene: usize) {
*self = match self {
@ -682,7 +665,9 @@ impl Scene {
}
/// Returns the pulse length of the longest phrase in the scene
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
pub fn is_playing <E: Engine> (&self, tracks: &[ArrangementTrack<E>]) -> bool {
@ -714,15 +699,9 @@ impl Scene {
}
}
pub fn longest_name (scenes: &[Self]) -> usize {
scenes.iter()
.map(|s|s.name.read().unwrap().len())
.fold(0, usize::max)
scenes.iter().map(|s|s.name.read().unwrap().len()).fold(0, usize::max)
}
pub fn clip (&self, index: usize) -> Option<&Arc<RwLock<Phrase>>> {
if let Some(Some(clip)) = self.clips.get(index) {
Some(clip)
} else {
None
}
match self.clips.get(index) { Some(Some(clip)) => Some(clip), _ => None }
}
}