unify edn_view entrypoint

This commit is contained in:
🪞👃🪞 2025-01-14 15:39:28 +01:00
parent df50bb9f47
commit 9cd6e9f195
16 changed files with 603 additions and 541 deletions

View file

@ -1,18 +1,19 @@
use tek::*;
use tek_midi::*;
use std::sync::*;
struct ExampleClips(Vec<Arc<RwLock<Clip>>>);
struct ExampleClips(Arc<RwLock<Vec<Arc<RwLock<MidiClip>>>>>);
impl HasClips for ExampleClips {
fn phrases (&self) -> &Vec<Arc<RwLock<Clip>>> {
&self.0
fn clips (&self) -> RwLockReadGuard<'_, Vec<Arc<RwLock<MidiClip>>>> {
self.0.read().unwrap()
}
fn phrases_mut (&mut self) -> &mut Vec<Arc<RwLock<Clip>>> {
&mut self.0
fn clips_mut (&self) -> RwLockWriteGuard<'_, Vec<Arc<RwLock<MidiClip>>>> {
self.0.write().unwrap()
}
}
fn main () -> Usually<()> {
let mut phrases = ExampleClips(vec![]);
PoolClipCommand::Import(0, String::from("./example.mid")).execute(&mut phrases)?;
fn main () -> Result<(), Box<dyn std::error::Error>> {
let mut clips = ExampleClips(Arc::new(vec![].into()));
PoolClipCommand::Import(0, String::from("./example.mid")).execute(&mut clips)?;
Ok(())
}

View file

@ -7,11 +7,25 @@ pub trait HasEditor {
fn editor_h (&self) -> usize { 0 }
}
#[macro_export] macro_rules! has_editor {
(|$self:ident: $Struct:ident|{
editor = $e0:expr;
editor_w = $e1:expr;
editor_h = $e2:expr;
is_editing = $e3:expr;
}) => {
impl HasEditor for $Struct {
fn editor (&$self) -> &Option<MidiEditor> { &$e0 }
fn editor_mut (&mut $self) -> &Option<MidiEditor> { &mut $e0 }
fn editor_w (&$self) -> usize { $e1 }
fn editor_h (&$self) -> usize { $e2 }
fn is_editing (&$self) -> bool { $e3 }
}
};
(|$self:ident:$Struct:ident$(<$($L:lifetime),*$($T:ident$(:$U:path)?),*>)?|$cb:expr) => {
impl $(<$($L),*$($T $(: $U)?),*>)? HasEditor for $Struct $(<$($L),*$($T),*>)? {
fn editor (&$self) -> &MidiEditor { &$cb }
}
}
};
}
/// Contains state for viewing and editing a clip
pub struct MidiEditor {
@ -32,7 +46,7 @@ impl Default for MidiEditor {
mode: PianoHorizontal::new(None),
size: Measure::new(),
keymap: EdnKeymap(
EdnItem::<String>::read_all(include_str!("../edn/midi-keys.edn"))
EdnItem::<String>::read_all(include_str!("midi_editor_keys.edn"))
.expect("failed to load keymap for MidiEditor")
)
}