down to 3 errors

This commit is contained in:
🪞👃🪞 2025-05-14 14:56:12 +03:00
parent ebdb8881e9
commit 8df49850ae
7 changed files with 84 additions and 81 deletions

View file

@ -119,16 +119,66 @@ impl Arrangement {
2
//1 + self.devices_with_sizes().last().map(|(_, _, _, _, y)|y as u16).unwrap_or(0)
}
/// Get the active track
fn get_track (&self) -> Option<&Track> {
let index = self.selection()?.track()?;
Has::<Vec<Track>>::get(self).get(index)
}
/// Get a mutable reference to the active track
fn get_track_mut (&mut self) -> Option<&mut Track> {
let index = self.selection()?.track()?;
Has::<Vec<Track>>::get_mut(self).get_mut(index)
}
/// Get the active scene
fn get_scene (&self) -> Option<&Scene> {
let index = self.selection()?.scene()?;
Has::<Vec<Scene>>::get(self).get(index)
}
/// Get a mutable reference to the active scene
fn get_scene_mut (&mut self) -> Option<&mut Scene> {
let index = self.selection()?.scene()?;
Has::<Vec<Scene>>::get_mut(self).get_mut(index)
}
/// Get the active clip
fn get_clip (&self) -> Option<Arc<RwLock<MidiClip>>> {
self.get_scene()?.clips.get(self.selection()?.track()?)?.clone()
}
/// Put a clip in a slot
pub(crate) fn clip_put (
&mut self, track: usize, scene: usize, clip: Option<Arc<RwLock<MidiClip>>>
) -> Option<Arc<RwLock<MidiClip>>> {
let old = self.scenes[scene].clips[track].clone();
self.scenes[scene].clips[track] = clip;
old
}
/// Change the color of a clip, returning the previous one
pub(crate) fn clip_set_color (&self, track: usize, scene: usize, color: ItemTheme)
-> Option<ItemTheme>
{
self.scenes[scene].clips[track].as_ref().map(|clip|{
let mut clip = clip.write().unwrap();
let old = clip.color.clone();
clip.color = color.clone();
panic!("{color:?} {old:?}");
old
})
}
/// Toggle looping for the active clip
pub(crate) fn toggle_loop (&mut self) {
if let Some(clip) = self.get_clip() {
clip.write().unwrap().toggle_loop()
}
}
}
#[cfg(feature = "sampler")]
impl Arrangement {
/// Get the first sampler of the active track
pub fn sampler (&self) -> Option<&Sampler> {
self.track().map(|t|t.sampler(0)).flatten()
self.get_track()?.sampler(0)
}
/// Get the first sampler of the active track
pub fn sampler_mut (&mut self) -> Option<&mut Sampler> {
self.track_mut().map(|t|t.sampler_mut(0)).flatten()
self.get_track_mut()?.sampler_mut(0)
}
}