collect tek_view, tek_ctrl

This commit is contained in:
i do not exist 2026-09-21 00:16:58 +03:00
parent c5d6ce24b2
commit 186b81f29c
47 changed files with 2665 additions and 2893 deletions

View file

@ -19,140 +19,17 @@ pub trait HasEditor: AsRef<Option<MidiEditor>> + AsMut<Option<MidiEditor>> {
}
}
impl<T> HasEditor for T where T:
AsRef<Option<MidiEditor>> +
AsMut<Option<MidiEditor>> {}
impl<T: HasEditor
+ Namespace<u32>
+ Namespace<f64>
+ Namespace<bool>
+ Namespace<usize>
+ Namespace<Option<u32>>
+ Namespace<Option<Arc<RwLock<MidiClip>>>>
> MidiEditController for T {}
#[tek_proc::commands(MidiEditCommand)]
pub trait MidiEditController: HasEditor
+ Namespace<u32>
+ Namespace<f64>
+ Namespace<bool>
+ Namespace<usize>
+ Namespace<Option<u32>>
+ Namespace<Option<Arc<RwLock<MidiClip>>>>
{
#[command(Toggle = "toggle")]
fn edit_toggle (&mut self) -> Perhaps<MidiEditCommand> {
if self.is_editing() {
*self.editor_mut() = None;
} else {
todo!()
}
Ok(Some(MidiEditCommand::Toggle))
}
#[command(Show = "show")]
fn edit_show (&mut self, clip: Option<Arc<RwLock<MidiClip>>>) -> Perhaps<MidiEditCommand> {
Ok(self.editor_mut().as_mut().map(|mut editor|{
editor.set_clip(clip.as_ref());
editor.redraw();
None
}).flatten())
}
#[command(DeleteNote = "delete")]
fn edit_note_delete (&mut self) -> Perhaps<MidiEditCommand> {
Ok(self.editor_mut().as_mut().map(|editor|{
editor.redraw();
todo!()
}).flatten())
}
#[command(AppendNote = "append")]
fn edit_note_append (&mut self, advance: bool) -> Perhaps<MidiEditCommand> {
Ok(self.editor_mut().as_mut().map(|mut editor|{
editor.put_note(advance);
editor.redraw();
None
}).flatten())
}
#[command(SetNotePos = "note-pos")]
fn edit_note_set_pos (&mut self, pos: usize) -> Perhaps<MidiEditCommand> {
Ok(self.editor_mut().as_mut().map(|editor|{
editor.set_note_pos((pos).min(127));
editor.redraw();
None
}).flatten())
}
#[command(SetNoteLen = "note-len")]
fn edit_note_set_len (&mut self, len: usize) -> Perhaps<MidiEditCommand> {
Ok(self.editor_mut().as_mut().map(|editor|{
editor.set_note_len(len);
editor.redraw();
None
}).flatten())
}
#[command(SetNoteScroll = "note-scroll")]
fn edit_note_set_scroll (&mut self, scroll: usize) -> Perhaps<MidiEditCommand> {
Ok(self.editor_mut().as_mut().map(|editor|{
editor.set_note_lo((scroll).min(127));
editor.redraw();
None
}).flatten())
}
#[command(SetTimePos = "time-pos")]
fn edit_time_set_pos (&mut self, pos: usize) -> Perhaps<MidiEditCommand> {
Ok(self.editor_mut().as_mut().map(|editor|{
editor.set_time_pos(pos);
editor.redraw();
None
}).flatten())
}
#[command(SetTimeScroll = "time-scroll")]
fn edit_time_set_scroll (&mut self, scroll: usize) -> Perhaps<MidiEditCommand> {
Ok(self.editor_mut().as_mut().map(|editor|{
editor.set_time_start(scroll);
editor.redraw();
None
}).flatten())
}
#[command(SetTimeZoom = "time-zoom")]
fn edit_time_set_zoom (&mut self, zoom: usize) -> Perhaps<MidiEditCommand> {
Ok(self.editor_mut().as_mut().map(|editor|{
editor.set_time_zoom(zoom);
editor.redraw();
None
}).flatten())
}
#[command(SetTimeLock = "time-lock")]
fn edit_time_set_lock (&mut self, lock: bool) -> Perhaps<MidiEditCommand> {
Ok(self.editor_mut().as_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
}
impl<T> HasEditor for T where T: AsRef<Option<MidiEditor>> + AsMut<Option<MidiEditor>> {}
/// Contains state for viewing and editing a clip.
///
/// ```
/// use std::sync::{Arc, RwLock};
/// use std::sync::Arc;
/// use parking_lot::RwLock;
/// let clip = tek::MidiClip::stop_all();
/// let mut editor = tek::MidiEditor {
/// mode: tek::PianoHorizontal::new(Some(&Arc::new(RwLock::new(clip)))),
/// size: Default::default(),
/// //keys: Default::default(),
/// };
/// let mode = tek::PianoHorizontal::new(Some(&Arc::new(RwLock::new(clip))));
/// let mut editor = tek::MidiEditor { mode, size: Default::default() };
///
/// let _ = editor.put_note(true);
/// let _ = editor.put_note(false);
/// let _ = editor.clip_status();
@ -275,8 +152,8 @@ impl MidiEditor {
/// use tek::{*, tengri::*};
///
/// struct Test(Option<MidiEditor>);
/// impl_as_ref_opt!(MidiEditor: |self: Test|self.0.as_ref());
/// impl_as_mut_opt!(MidiEditor: |self: Test|self.0.as_mut());
/// impl_as_ref!(Option<MidiEditor>: |self: Test|&self.0);
/// impl_as_mut!(Option<MidiEditor>: |self: Test|&mut self.0);
///
/// let mut host = Test(Some(MidiEditor::default()));
/// let _ = host.editor();
@ -427,7 +304,7 @@ impl App {
&& slot.is_none()
&& let Some(track) = self.project.tracks.get_mut(track)
{
let (_index, clip) = self.pool.add_new_clip();
let (_index, clip) = self.project.pool.add_new_clip();
// autocolor: new clip colors from scene and track color
let color = track.color.base.mix(scene.color.base, 0.5);
clip.try_write().unwrap().color = ItemColor::random_near(color, 0.2).into();
@ -450,7 +327,7 @@ impl App {
std::mem::swap(&mut swapped, slot);
}
if let Some(clip) = swapped {
self.pool.delete_clip(&clip.try_read().unwrap());
self.project.pool.delete_clip(&clip.try_read().unwrap());
}
}
}