mirror of
https://codeberg.org/unspeaker/tek.git
synced 2026-08-28 21:06:56 +02:00
This commit is contained in:
parent
a4931d8e4f
commit
def7a1b210
17 changed files with 2209 additions and 1790 deletions
|
|
@ -56,66 +56,121 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait HasEditor: AsRefOpt<MidiEditor> + AsMutOpt<MidiEditor> {
|
||||
fn editor (&self) -> Option<&MidiEditor> { self.as_ref_opt() }
|
||||
fn editor_mut (&mut self) -> Option<&mut MidiEditor> { self.as_mut_opt() }
|
||||
fn is_editing (&self) -> bool { self.editor().is_some() }
|
||||
fn editor_w (&self) -> usize { self.editor().map(|e|e.size.w()).unwrap_or(0) as usize }
|
||||
fn editor_h (&self) -> usize { self.editor().map(|e|e.size.h()).unwrap_or(0) as usize }
|
||||
}
|
||||
|
||||
impl<T: AsRefOpt<MidiEditor>+AsMutOpt<MidiEditor>> HasEditor for T {}
|
||||
|
||||
impl<T: HasEditor
|
||||
+ for<'a> Namespace<'a, u32>
|
||||
+ for<'a> Namespace<'a, f64>
|
||||
+ for<'a> Namespace<'a, bool>
|
||||
+ for<'a> Namespace<'a, usize>
|
||||
+ for<'a> Namespace<'a, Option<u32>>
|
||||
+ for<'a> Namespace<'a, Option<Arc<RwLock<MidiClip>>>>
|
||||
> MidiEditController for T {}
|
||||
|
||||
#[tek_proc::commands(MidiEditCommand = "edit")]
|
||||
impl MidiEditor {
|
||||
pub trait MidiEditController: HasEditor
|
||||
+ for<'a> Namespace<'a, u32>
|
||||
+ for<'a> Namespace<'a, f64>
|
||||
+ for<'a> Namespace<'a, bool>
|
||||
+ for<'a> Namespace<'a, usize>
|
||||
+ for<'a> Namespace<'a, Option<u32>>
|
||||
+ for<'a> Namespace<'a, Option<Arc<RwLock<MidiClip>>>>
|
||||
{
|
||||
#[command(Show = "show")]
|
||||
fn show (&mut self, clip: Option<Arc<RwLock<MidiClip>>>) -> Perhaps<MidiEditCommand> {
|
||||
self.set_clip(clip.as_ref());
|
||||
self.redraw();
|
||||
Ok(None)
|
||||
Ok(self.editor_mut().map(|editor|{
|
||||
editor.set_clip(clip.as_ref());
|
||||
editor.redraw();
|
||||
None
|
||||
}).flatten())
|
||||
}
|
||||
|
||||
#[command(DeleteNote = "delete")]
|
||||
fn note_delete (&mut self) -> Perhaps<MidiEditCommand> {
|
||||
self.redraw();
|
||||
todo!()
|
||||
Ok(self.editor_mut().map(|editor|{
|
||||
editor.redraw();
|
||||
todo!()
|
||||
}).flatten())
|
||||
}
|
||||
|
||||
#[command(AppendNote = "append")]
|
||||
fn note_append (&mut self, advance: bool) -> Perhaps<MidiEditCommand> {
|
||||
self.put_note(advance);
|
||||
self.redraw();
|
||||
Ok(None)
|
||||
Ok(self.editor_mut().map(|editor|{
|
||||
editor.put_note(advance);
|
||||
editor.redraw();
|
||||
None
|
||||
}).flatten())
|
||||
}
|
||||
|
||||
#[command(SetNotePos = "note-pos")]
|
||||
fn note_set_pos (&mut self, pos: usize) -> Perhaps<MidiEditCommand> {
|
||||
self.set_note_pos((pos).min(127));
|
||||
self.redraw();
|
||||
Ok(None)
|
||||
Ok(self.editor_mut().map(|editor|{
|
||||
editor.set_note_pos((pos).min(127));
|
||||
editor.redraw();
|
||||
None
|
||||
}).flatten())
|
||||
}
|
||||
|
||||
#[command(SetNoteLen = "note-len")]
|
||||
fn note_set_len (&mut self, len: usize) -> Perhaps<MidiEditCommand> {
|
||||
self.set_note_len(len);
|
||||
self.redraw();
|
||||
Ok(None)
|
||||
Ok(self.editor_mut().map(|editor|{
|
||||
editor.set_note_len(len);
|
||||
editor.redraw();
|
||||
None
|
||||
}).flatten())
|
||||
}
|
||||
|
||||
#[command(SetNoteScroll = "note-scroll")]
|
||||
fn note_set_scroll (&mut self, scroll: usize) -> Perhaps<MidiEditCommand> {
|
||||
self.set_note_lo((scroll).min(127));
|
||||
self.redraw();
|
||||
Ok(None)
|
||||
Ok(self.editor_mut().map(|editor|{
|
||||
editor.set_note_lo((scroll).min(127));
|
||||
editor.redraw();
|
||||
None
|
||||
}).flatten())
|
||||
}
|
||||
|
||||
#[command(SetTimePos = "time-pos")]
|
||||
fn time_set_pos (&mut self, pos: usize) -> Perhaps<MidiEditCommand> {
|
||||
self.set_time_pos(pos);
|
||||
self.redraw();
|
||||
Ok(None)
|
||||
Ok(self.editor_mut().map(|editor|{
|
||||
editor.set_time_pos(pos);
|
||||
editor.redraw();
|
||||
None
|
||||
}).flatten())
|
||||
}
|
||||
|
||||
#[command(SetTimeScroll = "time-scroll")]
|
||||
fn time_set_scroll (&mut self, scroll: usize) -> Perhaps<MidiEditCommand> {
|
||||
self.set_time_start(scroll);
|
||||
self.redraw();
|
||||
Ok(None)
|
||||
Ok(self.editor_mut().map(|editor|{
|
||||
editor.set_time_start(scroll);
|
||||
editor.redraw();
|
||||
None
|
||||
}).flatten())
|
||||
}
|
||||
|
||||
#[command(SetTimeZoom = "time-zoom")]
|
||||
fn time_set_zoom (&mut self, zoom: usize) -> Perhaps<MidiEditCommand> {
|
||||
self.set_time_zoom(zoom);
|
||||
self.redraw();
|
||||
Ok(None)
|
||||
Ok(self.editor_mut().map(|editor|{
|
||||
editor.set_time_zoom(zoom);
|
||||
editor.redraw();
|
||||
None
|
||||
}).flatten())
|
||||
}
|
||||
|
||||
#[command(SetTimeLock = "time-lock")]
|
||||
fn time_set_lock (&mut self, lock: bool) -> Perhaps<MidiEditCommand> {
|
||||
self.set_time_lock(lock);
|
||||
self.redraw();
|
||||
Ok(None)
|
||||
Ok(self.editor_mut().map(|editor|{
|
||||
editor.set_time_lock(lock);
|
||||
editor.redraw();
|
||||
None
|
||||
}).flatten())
|
||||
}
|
||||
// TODO: 1-9 seek markers that by default start every 8th of the clip
|
||||
}
|
||||
|
|
@ -263,20 +318,11 @@ impl MidiEditor {
|
|||
/// let _ = host.editor_w();
|
||||
/// let _ = host.editor_h();
|
||||
/// ```
|
||||
pub trait HasEditor: AsRefOpt<MidiEditor> + AsMutOpt<MidiEditor> {
|
||||
fn editor (&self) -> Option<&MidiEditor> { self.as_ref_opt() }
|
||||
fn editor_mut (&mut self) -> Option<&mut MidiEditor> { self.as_mut_opt() }
|
||||
fn is_editing (&self) -> bool { self.editor().is_some() }
|
||||
fn editor_w (&self) -> usize { self.editor().map(|e|e.size.w()).unwrap_or(0) as usize }
|
||||
fn editor_h (&self) -> usize { self.editor().map(|e|e.size.h()).unwrap_or(0) as usize }
|
||||
}
|
||||
|
||||
impl <T: NotePoint+TimePoint> MidiPoint for T {}
|
||||
|
||||
impl <T: TimeRange+NoteRange> MidiRange for T {}
|
||||
|
||||
impl <T: AsRefOpt<MidiEditor>+AsMutOpt<MidiEditor>> HasEditor for T {}
|
||||
|
||||
pub trait MidiViewer: MidiRange + MidiPoint + Debug + Send + Sync {
|
||||
fn buffer_size (&self, clip: &MidiClip) -> (usize, usize);
|
||||
fn redraw (&self);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue