mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +01:00
nice top level command dispatch
This commit is contained in:
parent
aad7aa6c5e
commit
8dcf73c18c
8 changed files with 137 additions and 144 deletions
|
|
@ -152,11 +152,6 @@ pub enum MidiEditCommand {
|
|||
SetTimeLock(bool),
|
||||
Show(Option<Arc<RwLock<MidiClip>>>),
|
||||
}
|
||||
impl MidiEditCommand {
|
||||
pub fn from_edn <'a> (head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
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),
|
||||
|
|
@ -217,3 +212,8 @@ impl Command<MidiEditor> for MidiEditCommand {
|
|||
Ok(None)
|
||||
}
|
||||
}
|
||||
impl EdnCommand<MidiEditor> for MidiEditCommand {
|
||||
fn from_edn <'a> (state: &MidiEditor, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ from!(|clip:&Arc<RwLock<MidiClip>>|PoolModel = {
|
|||
pub enum PoolCommand {
|
||||
Show(bool),
|
||||
/// Update the contents of the clip pool
|
||||
Clip(MidiPoolCommand),
|
||||
Clip(PoolClipCommand),
|
||||
/// Select a clip from the clip pool
|
||||
Select(usize),
|
||||
/// Rename a clip
|
||||
|
|
@ -68,13 +68,13 @@ pub enum PoolCommand {
|
|||
/// Export to file
|
||||
Export(FileBrowserCommand),
|
||||
}
|
||||
impl PoolCommand {
|
||||
pub fn from_edn <'a> (head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
impl EdnCommand<PoolModel> for PoolCommand {
|
||||
fn from_edn <'a> (state: &PoolModel, head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum MidiPoolCommand {
|
||||
pub enum PoolClipCommand {
|
||||
Add(usize, MidiClip),
|
||||
Delete(usize),
|
||||
Swap(usize, usize),
|
||||
|
|
@ -84,7 +84,7 @@ pub enum MidiPoolCommand {
|
|||
SetLength(usize, usize),
|
||||
SetColor(usize, ItemColor),
|
||||
}
|
||||
impl MidiPoolCommand {
|
||||
impl PoolClipCommand {
|
||||
pub fn from_edn <'a> (head: &EdnItem<&str>, tail: &'a [EdnItem<String>]) -> Self {
|
||||
todo!()
|
||||
}
|
||||
|
|
@ -104,9 +104,9 @@ pub enum PoolMode {
|
|||
}
|
||||
|
||||
|
||||
impl<T: HasClips> Command<T> for MidiPoolCommand {
|
||||
impl<T: HasClips> Command<T> for PoolClipCommand {
|
||||
fn execute (self, model: &mut T) -> Perhaps<Self> {
|
||||
use MidiPoolCommand::*;
|
||||
use PoolClipCommand::*;
|
||||
Ok(match self {
|
||||
Add(mut index, clip) => {
|
||||
let clip = Arc::new(RwLock::new(clip));
|
||||
|
|
@ -268,7 +268,7 @@ fn to_clips_command (state: &PoolModel, input: &Event) -> Option<PoolCommand> {
|
|||
kpat!(Char('t')) => Cmd::Length(ClipLengthCommand::Begin),
|
||||
kpat!(Char('m')) => Cmd::Import(FileBrowserCommand::Begin),
|
||||
kpat!(Char('x')) => Cmd::Export(FileBrowserCommand::Begin),
|
||||
kpat!(Char('c')) => Cmd::Clip(MidiPoolCommand::SetColor(index, ItemColor::random())),
|
||||
kpat!(Char('c')) => Cmd::Clip(PoolClipCommand::SetColor(index, ItemColor::random())),
|
||||
kpat!(Char('[')) | kpat!(Up) => Cmd::Select(
|
||||
index.overflowing_sub(1).0.min(state.clips().len() - 1)
|
||||
),
|
||||
|
|
@ -277,32 +277,32 @@ fn to_clips_command (state: &PoolModel, input: &Event) -> Option<PoolCommand> {
|
|||
),
|
||||
kpat!(Char('<')) => if index > 1 {
|
||||
state.set_clip_index(state.clip_index().saturating_sub(1));
|
||||
Cmd::Clip(MidiPoolCommand::Swap(index - 1, index))
|
||||
Cmd::Clip(PoolClipCommand::Swap(index - 1, index))
|
||||
} else {
|
||||
return None
|
||||
},
|
||||
kpat!(Char('>')) => if index < count.saturating_sub(1) {
|
||||
state.set_clip_index(state.clip_index() + 1);
|
||||
Cmd::Clip(MidiPoolCommand::Swap(index + 1, index))
|
||||
Cmd::Clip(PoolClipCommand::Swap(index + 1, index))
|
||||
} else {
|
||||
return None
|
||||
},
|
||||
kpat!(Delete) => if index > 0 {
|
||||
state.set_clip_index(index.min(count.saturating_sub(1)));
|
||||
Cmd::Clip(MidiPoolCommand::Delete(index))
|
||||
Cmd::Clip(PoolClipCommand::Delete(index))
|
||||
} else {
|
||||
return None
|
||||
},
|
||||
kpat!(Char('a')) | kpat!(Shift-Char('A')) => Cmd::Clip(MidiPoolCommand::Add(count, MidiClip::new(
|
||||
kpat!(Char('a')) | kpat!(Shift-Char('A')) => Cmd::Clip(PoolClipCommand::Add(count, MidiClip::new(
|
||||
"Clip", true, 4 * PPQ, None, Some(ItemPalette::random())
|
||||
))),
|
||||
kpat!(Char('i')) => Cmd::Clip(MidiPoolCommand::Add(index + 1, MidiClip::new(
|
||||
kpat!(Char('i')) => Cmd::Clip(PoolClipCommand::Add(index + 1, MidiClip::new(
|
||||
"Clip", true, 4 * PPQ, None, Some(ItemPalette::random())
|
||||
))),
|
||||
kpat!(Char('d')) | kpat!(Shift-Char('D')) => {
|
||||
let mut clip = state.clips()[index].read().unwrap().duplicate();
|
||||
clip.color = ItemPalette::random_near(clip.color, 0.25);
|
||||
Cmd::Clip(MidiPoolCommand::Add(index + 1, clip))
|
||||
Cmd::Clip(PoolClipCommand::Add(index + 1, clip))
|
||||
},
|
||||
_ => return None
|
||||
})
|
||||
|
|
@ -343,7 +343,7 @@ command!(|self: FileBrowserCommand, state: PoolModel|{
|
|||
let index = *index;
|
||||
let path = browser.path();
|
||||
*mode = None;
|
||||
MidiPoolCommand::Import(index, path).execute(state)?;
|
||||
PoolClipCommand::Import(index, path).execute(state)?;
|
||||
} else if browser.is_dir() {
|
||||
*mode = Some(Import(*index, browser.chdir()?));
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue