mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
remove old input macros
This commit is contained in:
parent
6fd87ce4ed
commit
ca1fb3c414
11 changed files with 218 additions and 247 deletions
|
|
@ -34,6 +34,33 @@ pub struct MidiEditor {
|
|||
pub mode: PianoHorizontal,
|
||||
pub size: Measure<TuiOut>,
|
||||
}
|
||||
has_size!(<TuiOut>|self: MidiEditor|&self.size);
|
||||
content!(TuiOut: |self: MidiEditor| {
|
||||
self.autoscroll();
|
||||
//self.autozoom();
|
||||
self.size.of(&self.mode)
|
||||
});
|
||||
from!(|clip: &Arc<RwLock<MidiClip>>|MidiEditor = {
|
||||
let model = Self::from(Some(clip.clone()));
|
||||
model.redraw();
|
||||
model
|
||||
});
|
||||
from!(|clip: Option<Arc<RwLock<MidiClip>>>|MidiEditor = {
|
||||
let mut model = Self::default();
|
||||
*model.clip_mut() = clip;
|
||||
model.redraw();
|
||||
model
|
||||
});
|
||||
edn_provide!(bool: |self: MidiEditor| {
|
||||
":true" => true,
|
||||
":false" => false
|
||||
});
|
||||
edn_provide!(usize: |self: MidiEditor| {
|
||||
":note-length" => self.note_len(),
|
||||
":note-point" => self.note_point(),
|
||||
":time-point" => self.time_point(),
|
||||
":time-zoom" => self.time_zoom().get(),
|
||||
});
|
||||
impl std::fmt::Debug for MidiEditor {
|
||||
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
||||
f.debug_struct("MidiEditor")
|
||||
|
|
@ -84,17 +111,6 @@ impl MidiEditor {
|
|||
}
|
||||
}
|
||||
}
|
||||
from!(|clip: &Arc<RwLock<MidiClip>>|MidiEditor = {
|
||||
let model = Self::from(Some(clip.clone()));
|
||||
model.redraw();
|
||||
model
|
||||
});
|
||||
from!(|clip: Option<Arc<RwLock<MidiClip>>>|MidiEditor = {
|
||||
let mut model = Self::default();
|
||||
*model.clip_mut() = clip;
|
||||
model.redraw();
|
||||
model
|
||||
});
|
||||
impl TimeRange for MidiEditor {
|
||||
fn time_len (&self) -> &AtomicUsize { self.mode.time_len() }
|
||||
fn time_zoom (&self) -> &AtomicUsize { self.mode.time_zoom() }
|
||||
|
|
@ -123,12 +139,6 @@ impl MidiViewer for MidiEditor {
|
|||
fn clip_mut (&mut self) -> &mut Option<Arc<RwLock<MidiClip>>> { self.mode.clip_mut() }
|
||||
fn set_clip (&mut self, p: Option<&Arc<RwLock<MidiClip>>>) { self.mode.set_clip(p) }
|
||||
}
|
||||
has_size!(<TuiOut>|self: MidiEditor|&self.size);
|
||||
content!(TuiOut: |self: MidiEditor| {
|
||||
self.autoscroll();
|
||||
//self.autozoom();
|
||||
self.size.of(&self.mode)
|
||||
});
|
||||
impl MidiEditor {
|
||||
pub fn clip_status (&self) -> impl Content<TuiOut> + '_ {
|
||||
let (color, name, length, looped) = if let Some(clip) = self.clip().as_ref().map(|p|p.read().unwrap()) {
|
||||
|
|
@ -159,16 +169,6 @@ impl MidiEditor {
|
|||
)
|
||||
}
|
||||
}
|
||||
edn_provide!(bool: |self: MidiEditor|{
|
||||
":true" => true,
|
||||
":false" => false
|
||||
});
|
||||
edn_provide!(usize: |self: MidiEditor|{
|
||||
":note-length" => self.note_len(),
|
||||
":note-point" => self.note_point(),
|
||||
":time-point" => self.time_point(),
|
||||
":time-zoom" => self.time_zoom().get(),
|
||||
});
|
||||
edn_command!(MidiEditCommand: |state: MidiEditor| {
|
||||
("note/put" [a: bool] Self::PutNote)
|
||||
("note/del" [a: bool] Self::PutNote)
|
||||
|
|
@ -207,42 +207,68 @@ edn_command!(MidiEditCommand: |state: MidiEditor| {
|
|||
SetTimeLock(bool),
|
||||
Show(Option<Arc<RwLock<MidiClip>>>),
|
||||
}
|
||||
handle!(TuiIn: |self: MidiEditor, input|MidiEditCommand::execute_with_state(self, input.event()));
|
||||
keymap!(KEYS_MIDI_EDITOR = |s: MidiEditor, _input: Event| MidiEditCommand {
|
||||
key(Up) => SetNoteCursor(s.note_point() + 1),
|
||||
key(Char('w')) => SetNoteCursor(s.note_point() + 1),
|
||||
key(Down) => SetNoteCursor(s.note_point().saturating_sub(1)),
|
||||
key(Char('s')) => SetNoteCursor(s.note_point().saturating_sub(1)),
|
||||
key(Left) => SetTimeCursor(s.time_point().saturating_sub(s.note_len())),
|
||||
key(Char('a')) => SetTimeCursor(s.time_point().saturating_sub(s.note_len())),
|
||||
key(Right) => SetTimeCursor((s.time_point() + s.note_len()) % s.clip_length()),
|
||||
ctrl(alt(key(Up))) => SetNoteScroll(s.note_point() + 3),
|
||||
ctrl(alt(key(Down))) => SetNoteScroll(s.note_point().saturating_sub(3)),
|
||||
ctrl(alt(key(Left))) => SetTimeScroll(s.time_point().saturating_sub(s.time_zoom().get())),
|
||||
ctrl(alt(key(Right))) => SetTimeScroll((s.time_point() + s.time_zoom().get()) % s.clip_length()),
|
||||
ctrl(key(Up)) => SetNoteScroll(s.note_lo().get() + 1),
|
||||
ctrl(key(Down)) => SetNoteScroll(s.note_lo().get().saturating_sub(1)),
|
||||
ctrl(key(Left)) => SetTimeScroll(s.time_start().get().saturating_sub(s.note_len())),
|
||||
ctrl(key(Right)) => SetTimeScroll(s.time_start().get() + s.note_len()),
|
||||
alt(key(Up)) => SetNoteCursor(s.note_point() + 3),
|
||||
alt(key(Down)) => SetNoteCursor(s.note_point().saturating_sub(3)),
|
||||
alt(key(Left)) => SetTimeCursor(s.time_point().saturating_sub(s.time_zoom().get())),
|
||||
alt(key(Right)) => SetTimeCursor((s.time_point() + s.time_zoom().get()) % s.clip_length()),
|
||||
key(Char('d')) => SetTimeCursor((s.time_point() + s.note_len()) % s.clip_length()),
|
||||
key(Char('z')) => SetTimeLock(!s.time_lock().get()),
|
||||
key(Char('-')) => SetTimeZoom(if s.time_lock().get() { s.time_zoom().get() } else { NoteDuration::next(s.time_zoom().get()) }),
|
||||
key(Char('_')) => SetTimeZoom(if s.time_lock().get() { s.time_zoom().get() } else { NoteDuration::next(s.time_zoom().get()) }),
|
||||
key(Char('=')) => SetTimeZoom(if s.time_lock().get() { s.time_zoom().get() } else { NoteDuration::prev(s.time_zoom().get()) }),
|
||||
key(Char('+')) => SetTimeZoom(if s.time_lock().get() { s.time_zoom().get() } else { NoteDuration::prev(s.time_zoom().get()) }),
|
||||
key(Enter) => PutNote,
|
||||
ctrl(key(Enter)) => AppendNote,
|
||||
key(Char(',')) => SetNoteLength(NoteDuration::prev(s.note_len())),
|
||||
key(Char('.')) => SetNoteLength(NoteDuration::next(s.note_len())),
|
||||
key(Char('<')) => SetNoteLength(NoteDuration::prev(s.note_len())),
|
||||
key(Char('>')) => SetNoteLength(NoteDuration::next(s.note_len())),
|
||||
//// TODO: kpat!(Char('/')) => // toggle 3plet
|
||||
//// TODO: kpat!(Char('?')) => // toggle dotted
|
||||
impl MidiEditCommand {
|
||||
pub fn from_tui_event (state: &MidiEditor, input: &impl EdnInput) -> Usually<Option<Self>> {
|
||||
use EdnItem::*;
|
||||
let edns = EdnItem::<&str>::read_all(KEYS_EDIT)?;
|
||||
for item in edns.iter() {
|
||||
if let Exp(e) = item {
|
||||
match e.as_slice() {
|
||||
[Sym(key), command, args @ ..] if input.matches_edn(key) => {
|
||||
return Ok(MidiEditCommand::from_edn(state, command, args))
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else {
|
||||
panic!("invalid config")
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
handle!(TuiIn: |self: MidiEditor, input|{
|
||||
Ok(if let Some(command) = MidiEditCommand::from_tui_event(self, input)? {
|
||||
let _undo = command.execute(self)?;
|
||||
Some(true)
|
||||
} else {
|
||||
None
|
||||
})
|
||||
});
|
||||
//keymap!(KEYS_MIDI_EDITOR = |s: MidiEditor, _input: Event| MidiEditCommand {
|
||||
//key(Up) => SetNoteCursor(s.note_point() + 1),
|
||||
//key(Char('w')) => SetNoteCursor(s.note_point() + 1),
|
||||
//key(Down) => SetNoteCursor(s.note_point().saturating_sub(1)),
|
||||
//key(Char('s')) => SetNoteCursor(s.note_point().saturating_sub(1)),
|
||||
//key(Left) => SetTimeCursor(s.time_point().saturating_sub(s.note_len())),
|
||||
//key(Char('a')) => SetTimeCursor(s.time_point().saturating_sub(s.note_len())),
|
||||
//key(Right) => SetTimeCursor((s.time_point() + s.note_len()) % s.clip_length()),
|
||||
//ctrl(alt(key(Up))) => SetNoteScroll(s.note_point() + 3),
|
||||
//ctrl(alt(key(Down))) => SetNoteScroll(s.note_point().saturating_sub(3)),
|
||||
//ctrl(alt(key(Left))) => SetTimeScroll(s.time_point().saturating_sub(s.time_zoom().get())),
|
||||
//ctrl(alt(key(Right))) => SetTimeScroll((s.time_point() + s.time_zoom().get()) % s.clip_length()),
|
||||
//ctrl(key(Up)) => SetNoteScroll(s.note_lo().get() + 1),
|
||||
//ctrl(key(Down)) => SetNoteScroll(s.note_lo().get().saturating_sub(1)),
|
||||
//ctrl(key(Left)) => SetTimeScroll(s.time_start().get().saturating_sub(s.note_len())),
|
||||
//ctrl(key(Right)) => SetTimeScroll(s.time_start().get() + s.note_len()),
|
||||
//alt(key(Up)) => SetNoteCursor(s.note_point() + 3),
|
||||
//alt(key(Down)) => SetNoteCursor(s.note_point().saturating_sub(3)),
|
||||
//alt(key(Left)) => SetTimeCursor(s.time_point().saturating_sub(s.time_zoom().get())),
|
||||
//alt(key(Right)) => SetTimeCursor((s.time_point() + s.time_zoom().get()) % s.clip_length()),
|
||||
//key(Char('d')) => SetTimeCursor((s.time_point() + s.note_len()) % s.clip_length()),
|
||||
//key(Char('z')) => SetTimeLock(!s.time_lock().get()),
|
||||
//key(Char('-')) => SetTimeZoom(if s.time_lock().get() { s.time_zoom().get() } else { NoteDuration::next(s.time_zoom().get()) }),
|
||||
//key(Char('_')) => SetTimeZoom(if s.time_lock().get() { s.time_zoom().get() } else { NoteDuration::next(s.time_zoom().get()) }),
|
||||
//key(Char('=')) => SetTimeZoom(if s.time_lock().get() { s.time_zoom().get() } else { NoteDuration::prev(s.time_zoom().get()) }),
|
||||
//key(Char('+')) => SetTimeZoom(if s.time_lock().get() { s.time_zoom().get() } else { NoteDuration::prev(s.time_zoom().get()) }),
|
||||
//key(Enter) => PutNote,
|
||||
//ctrl(key(Enter)) => AppendNote,
|
||||
//key(Char(',')) => SetNoteLength(NoteDuration::prev(s.note_len())),
|
||||
//key(Char('.')) => SetNoteLength(NoteDuration::next(s.note_len())),
|
||||
//key(Char('<')) => SetNoteLength(NoteDuration::prev(s.note_len())),
|
||||
//key(Char('>')) => SetNoteLength(NoteDuration::next(s.note_len())),
|
||||
////// TODO: kpat!(Char('/')) => // toggle 3plet
|
||||
////// TODO: kpat!(Char('?')) => // toggle dotted
|
||||
//});
|
||||
impl Command<MidiEditor> for MidiEditCommand {
|
||||
fn execute (self, state: &mut MidiEditor) -> Perhaps<Self> {
|
||||
use MidiEditCommand::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue