wip: down to 25 errors woo

This commit is contained in:
🪞👃🪞 2025-05-14 02:13:13 +03:00
parent 89288f2920
commit 6ce83fb27a
25 changed files with 688 additions and 620 deletions

View file

@ -1,5 +1,42 @@
use crate::*;
impl<T: Has<Selection>> HasSelection for T {}
pub trait HasSelection: Has<Selection> {
fn selection (&self) -> &Selection {
self.get()
}
fn selection_mut (&mut self) -> &mut Selection {
self.get_mut()
}
}
impl Has<Option<Track>> for Arrangement {
fn get (&self) -> &Option<Track> {
Has::<Option<Selection>>::get(self)
.and_then(|selection|selection.track())
.and_then(|index|Has::<Vec<Track>>::get(self).get(index))
}
fn get_mut (&mut self) -> &mut Option<Track> {
Has::<Option<Selection>>::get(self)
.and_then(|selection|selection.track())
.and_then(|index|Has::<Vec<Track>>::get_mut(self).get_mut(index))
}
}
impl Has<Option<Scene>> for Arrangement {
fn get (&self) -> &Option<Scene> {
Has::<Option<Selection>>::get(self)
.and_then(|selection|selection.track())
.and_then(|index|Has::<Vec<Scene>>::get(self).get(index))
}
fn get_mut (&mut self) -> &mut Option<Scene> {
Has::<Option<Selection>>::get(self)
.and_then(|selection|selection.track())
.and_then(|index|Has::<Vec<Scene>>::get_mut(self).get_mut(index))
}
}
/// Represents the current user selection in the arranger
#[derive(PartialEq, Clone, Copy, Debug, Default)]
pub enum Selection {
@ -147,69 +184,4 @@ impl Selection {
}
impl Arrangement {
/// Set the selection
pub(crate) fn select (&mut self, s: Selection) {
self.selected = s;
// autoedit: load focused clip in editor.
if let Some(ref mut editor) = self.editor {
editor.set_clip(match self.selected {
Selection::TrackClip { track, scene }
if let Some(Some(Some(clip))) = self
.scenes.get(scene)
.map(|s|s.clips.get(track)) => Some(clip),
_ => None
});
}
}
/// Launch a clip or scene
pub(crate) fn launch (&mut self) {
use Selection::*;
match self.selected {
Track(t) => {
self.tracks[t].sequencer.enqueue_next(None)
},
TrackClip { track, scene } => {
self.tracks[track].sequencer.enqueue_next(self.scenes[scene].clips[track].as_ref())
},
Scene(s) => {
for t in 0..self.tracks.len() {
self.tracks[t].sequencer.enqueue_next(self.scenes[s].clips[t].as_ref())
}
},
_ => {}
};
}
/// Set the color of the selected entity
pub fn set_color (&mut self, palette: Option<ItemTheme>) -> Option<ItemTheme> {
use Selection::*;
let palette = palette.unwrap_or_else(||ItemTheme::random());
Some(match self.selected {
Mix => {
let old = self.color;
self.color = palette;
old
},
Scene(s) => {
let old = self.scenes[s].color;
self.scenes[s].color = palette;
old
}
Track(t) => {
let old = self.tracks[t].color;
self.tracks[t].color = palette;
old
}
TrackClip { track, scene } => {
if let Some(ref clip) = self.scenes[scene].clips[track] {
let mut clip = clip.write().unwrap();
let old = clip.color;
clip.color = palette;
old
} else {
return None
}
},
_ => todo!()
})
}
}