editor: remove InputMap

This commit is contained in:
🪞👃🪞 2025-05-02 17:38:27 +03:00
parent a22a793c31
commit 457e6bb7eb
2 changed files with 54 additions and 69 deletions

View file

@ -567,13 +567,6 @@ atom_command!(MidiEditCommand: |state: MidiEditor| {
Show(Option<Arc<RwLock<MidiClip>>>),
}
handle!(TuiIn: |self: MidiEditor, input|Ok(if let Some(command) = self.keys.command(self, input) {
command.execute(self)?;
Some(true)
} else {
None
}));
impl Command<MidiEditor> for MidiEditCommand {
fn execute (self, state: &mut MidiEditor) -> Perhaps<Self> {
use MidiEditCommand::*;

View file

@ -516,7 +516,7 @@ impl Selection {
pub fn scene_next (&self, len: usize) -> Self {
use Selection::*;
match self {
Mix => Scene(0),
Mix => Scene(0),
Track(t) => TrackClip { track: *t, scene: 0 },
Scene(s) => if s + 1 < len {
Scene(s + 1)
@ -546,9 +546,11 @@ impl Selection {
use Selection::*;
format!("{}", match self {
Mix => "Everything".to_string(),
Scene(s) => scenes.get(*s).map(|scene|format!("S{s}: {}", &scene.name))
Scene(s) => scenes.get(*s)
.map(|scene|format!("S{s}: {}", &scene.name))
.unwrap_or_else(||"S??".into()),
Track(t) => tracks.get(*t).map(|track|format!("T{t}: {}", &track.name))
Track(t) => tracks.get(*t)
.map(|track|format!("T{t}: {}", &track.name))
.unwrap_or_else(||"T??".into()),
TrackClip { track, scene } => match (tracks.get(*track), scenes.get(*scene)) {
(Some(_), Some(s)) => match s.clip(*track) {
@ -799,10 +801,6 @@ pub struct MidiPool {
pub mode: Option<PoolMode>,
pub keys: InputMap<'static, Self, PoolCommand, TuiIn, SourceIter<'static>>,
//pub keys: SourceIter<'static>,
//pub keys_rename: SourceIter<'static>,
//pub keys_length: SourceIter<'static>,
//pub keys_file: SourceIter<'static>,
}
impl Default for MidiPool {
@ -932,10 +930,12 @@ pub enum ClipLengthFocus {
impl ClipLengthFocus {
pub fn next (&mut self) {
*self = match self { Self::Bar => Self::Beat, Self::Beat => Self::Tick, Self::Tick => Self::Bar, }
use ClipLengthFocus::*;
*self = match self { Bar => Beat, Beat => Tick, Tick => Bar, }
}
pub fn prev (&mut self) {
*self = match self { Self::Bar => Self::Tick, Self::Beat => Self::Bar, Self::Tick => Self::Beat, }
use ClipLengthFocus::*;
*self = match self { Bar => Tick, Beat => Bar, Tick => Beat, }
}
}
@ -943,9 +943,9 @@ impl ClipLengthFocus {
#[derive(Clone)]
pub struct ClipLength {
/// Pulses per beat (quaver)
ppq: usize,
ppq: usize,
/// Beats per bar
bpb: usize,
bpb: usize,
/// Length of clip in pulses
pulses: usize,
/// Selected subdivision
@ -1001,14 +1001,42 @@ pub trait HasClips {
}
}
pub trait HasEditor {
fn editor (&self) -> &Option<MidiEditor>;
fn editor_mut (&mut self) -> &Option<MidiEditor>;
fn is_editing (&self) -> bool { true }
fn editor_w (&self) -> usize { 0 }
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 {
/// Size of editor on screen
pub size: Measure<TuiOut>,
/// View mode and state of editor
pub mode: PianoHorizontal,
/// Input keymap
pub keys: InputMap<'static, Self, MidiEditCommand, TuiIn, SourceIter<'static>>
}
impl std::fmt::Debug for MidiEditor {
@ -1024,7 +1052,6 @@ impl Default for MidiEditor {
Self {
size: Measure::new(),
mode: PianoHorizontal::new(None),
keys: InputMap::new(SourceIter(include_str!("../../../config/keys_editor.edn"))),
}
}
}
@ -1052,7 +1079,6 @@ from!(|clip: Option<Arc<RwLock<MidiClip>>>|MidiEditor = {
});
impl MidiEditor {
/// Put note at current position
pub fn put_note (&mut self, advance: bool) {
let mut redraw = false;
@ -1109,71 +1135,37 @@ impl MidiEditor {
FieldH(color, "Note", format!("{note_name} {note_pos} {note_len}")),
)
}
//fn clip_length (&self) -> usize {
//self.clip().as_ref().map(|p|p.read().unwrap().length).unwrap_or(1)
//}
}
impl TimeRange for MidiEditor {
fn time_len (&self) -> &AtomicUsize { self.mode.time_len() }
fn time_zoom (&self) -> &AtomicUsize { self.mode.time_zoom() }
fn time_lock (&self) -> &AtomicBool { self.mode.time_lock() }
fn time_len (&self) -> &AtomicUsize { self.mode.time_len() }
fn time_zoom (&self) -> &AtomicUsize { self.mode.time_zoom() }
fn time_lock (&self) -> &AtomicBool { self.mode.time_lock() }
fn time_start (&self) -> &AtomicUsize { self.mode.time_start() }
fn time_axis (&self) -> &AtomicUsize { self.mode.time_axis() }
fn time_axis (&self) -> &AtomicUsize { self.mode.time_axis() }
}
impl NoteRange for MidiEditor {
fn note_lo (&self) -> &AtomicUsize { self.mode.note_lo() }
fn note_axis (&self) -> &AtomicUsize { self.mode.note_axis() }
fn note_lo (&self) -> &AtomicUsize { self.mode.note_lo() }
fn note_axis (&self) -> &AtomicUsize { self.mode.note_axis() }
}
impl NotePoint for MidiEditor {
fn note_len (&self) -> usize { self.mode.note_len() }
fn note_len (&self) -> usize { self.mode.note_len() }
fn set_note_len (&self, x: usize) -> usize { self.mode.set_note_len(x) }
fn note_pos (&self) -> usize { self.mode.note_pos() }
fn note_pos (&self) -> usize { self.mode.note_pos() }
fn set_note_pos (&self, x: usize) -> usize { self.mode.set_note_pos(x) }
}
impl TimePoint for MidiEditor {
fn time_pos (&self) -> usize { self.mode.time_pos() }
fn time_pos (&self) -> usize { self.mode.time_pos() }
fn set_time_pos (&self, x: usize) -> usize { self.mode.set_time_pos(x) }
}
impl MidiViewer for MidiEditor {
fn buffer_size (&self, clip: &MidiClip) -> (usize, usize) { self.mode.buffer_size(clip) }
fn redraw (&self) { self.mode.redraw() }
fn clip (&self) -> &Option<Arc<RwLock<MidiClip>>> { self.mode.clip() }
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) }
}
pub trait HasEditor {
fn editor (&self) -> &Option<MidiEditor>;
fn editor_mut (&mut self) -> &Option<MidiEditor>;
fn is_editing (&self) -> bool { true }
fn editor_w (&self) -> usize { 0 }
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 }
}
};
fn redraw (&self) { self.mode.redraw() }
fn clip (&self) -> &Option<Arc<RwLock<MidiClip>>> { self.mode.clip() }
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) }
}