wip: refactor pt.10, 165 errors

This commit is contained in:
🪞👃🪞 2024-11-10 19:58:16 +01:00
parent 1405b82341
commit 355b34c738
9 changed files with 96 additions and 204 deletions

View file

@ -447,28 +447,6 @@ impl<E: Engine> Arrangement<E> {
}
}
impl ArrangementTrack {
pub fn new (
jack: &Arc<RwLock<JackClient>>,
clock: &Arc<Clock>,
name: &str,
color: Option<ItemColor>
) -> Usually<Self> {
Ok(Self {
name: Arc::new(RwLock::new(name.into())),
width: name.len() + 2,
color: color.unwrap_or_else(ItemColor::random),
player: PhrasePlayer::new(&jack, clock, name)?,
})
}
pub fn longest_name (tracks: &[Self]) -> usize {
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; } }
}
/// Arranger display mode can be cycled
impl ArrangementEditorMode {
/// Cycle arranger display mode
@ -482,33 +460,3 @@ impl ArrangementEditorMode {
}
}
}
impl ArrangementScene {
pub fn new (
name: impl AsRef<str>,
clips: impl AsRef<[Option<Arc<RwLock<Phrase>>>]>,
color: Option<ItemColor>,
) -> Self {
Self {
name: Arc::new(RwLock::new(name.as_ref().into())),
clips: clips.as_ref().iter().map(|x|x.clone()).collect(),
color: color.unwrap_or_else(ItemColor::random),
}
}
pub fn ppqs (scenes: &[Self], factor: usize) -> Vec<(usize, usize)> {
let mut total = 0;
if factor == 0 {
scenes.iter().map(|scene|{
let pulses = scene.pulses().max(PPQ);
total = total + pulses;
(pulses, total - pulses)
}).collect()
} else {
(0..=scenes.len()).map(|i|{
(factor*PPQ, factor*PPQ*i)
}).collect()
}
}
pub fn longest_name (scenes: &[Self]) -> usize {
scenes.iter().map(|s|s.name.read().unwrap().len()).fold(0, usize::max)
}
}