wip: what nuked the arranger

This commit is contained in:
🪞👃🪞 2025-01-11 17:36:02 +01:00
parent ba0ff4af98
commit a92981bb50
11 changed files with 324 additions and 310 deletions

View file

@ -1,13 +1,13 @@
use crate::*;
pub trait HasMidiClip {
fn clip (&self) -> &Arc<RwLock<MidiClip>>;
fn clip (&self) -> Option<Arc<RwLock<MidiClip>>>;
}
#[macro_export] macro_rules! has_clip {
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
impl $(<$($L),*$($T $(: $U)?),*>)? HasMidiClip for $Struct $(<$($L),*$($T),*>)? {
fn clip (&$self) -> &Arc<RwLock<MidiClip>> { &$cb }
fn clip (&$self) -> Option<Arc<RwLock<MidiClip>>> { $cb }
}
}
}

View file

@ -1,15 +1,21 @@
use crate::*;
pub trait HasPhrases {
fn clips (&self) -> &Vec<Arc<RwLock<MidiClip>>>;
fn clips_mut (&mut self) -> &mut Vec<Arc<RwLock<MidiClip>>>;
pub type ClipPool = Vec<Arc<RwLock<MidiClip>>>;
pub trait HasClips {
fn clips <'a> (&'a self) -> std::sync::RwLockReadGuard<'a, ClipPool>;
fn clips_mut <'a> (&'a self) -> std::sync::RwLockWriteGuard<'a, ClipPool>;
}
#[macro_export] macro_rules! has_clips {
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
impl $(<$($L),*$($T $(: $U)?),*>)? HasPhrases for $Struct $(<$($L),*$($T),*>)? {
fn clips (&$self) -> &Vec<Arc<RwLock<MidiClip>>> { &$cb }
fn clips_mut (&mut $self) -> &mut Vec<Arc<RwLock<MidiClip>>> { &mut$cb }
impl $(<$($L),*$($T $(: $U)?),*>)? HasClips for $Struct $(<$($L),*$($T),*>)? {
fn clips <'a> (&'a $self) -> std::sync::RwLockReadGuard<'a, ClipPool> {
$cb.read().unwrap()
}
fn clips_mut <'a> (&'a $self) -> std::sync::RwLockWriteGuard<'a, ClipPool> {
$cb.write().unwrap()
}
}
}
}
@ -26,13 +32,13 @@ pub enum MidiPoolCommand {
SetColor(usize, ItemColor),
}
impl<T: HasPhrases> Command<T> for MidiPoolCommand {
impl<T: HasClips> Command<T> for MidiPoolCommand {
fn execute (self, model: &mut T) -> Perhaps<Self> {
use MidiPoolCommand::*;
Ok(match self {
Add(mut index, clip) => {
let clip = Arc::new(RwLock::new(clip));
let clips = model.clips_mut();
let mut clips = model.clips_mut();
if index >= clips.len() {
index = clips.len();
clips.push(clip)
@ -72,15 +78,15 @@ impl<T: HasPhrases> Command<T> for MidiPoolCommand {
todo!("export clip to midi file");
},
SetName(index, name) => {
let mut clip = model.clips()[index].write().unwrap();
let old_name = clip.name.clone();
clip.name = name;
let clip = &mut model.clips_mut()[index];
let old_name = clip.read().unwrap().name.clone();
clip.write().unwrap().name = name;
Some(Self::SetName(index, old_name))
},
SetLength(index, length) => {
let mut clip = model.clips()[index].write().unwrap();
let old_len = clip.length;
clip.length = length;
let clip = &mut model.clips_mut()[index];
let old_len = clip.read().unwrap().length;
clip.write().unwrap().length = length;
Some(Self::SetLength(index, old_len))
},
SetColor(index, color) => {