mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 05:06:43 +01:00
cmdsys: menubar pt.1
This commit is contained in:
parent
2b163e9e27
commit
38e8cfc214
7 changed files with 180 additions and 136 deletions
|
|
@ -24,6 +24,8 @@ pub enum PhrasePoolCommand {
|
|||
Duplicate,
|
||||
RandomColor,
|
||||
Edit,
|
||||
Import,
|
||||
Export,
|
||||
Rename(PhraseRenameCommand),
|
||||
Length(PhraseLengthCommand),
|
||||
}
|
||||
|
|
@ -91,89 +93,65 @@ impl<E: Engine> Command<Sequencer<E>> for SequencerCommand {
|
|||
}
|
||||
impl<E: Engine> Command<PhrasePool<E>> for PhrasePoolCommand {
|
||||
fn run (&self, state: &mut PhrasePool<E>) -> Perhaps<Self> {
|
||||
use PhrasePoolCommand::*;
|
||||
use PhraseRenameCommand as Rename;
|
||||
use PhraseLengthCommand as Length;
|
||||
match self {
|
||||
Self::Prev => {
|
||||
state.select_prev()
|
||||
},
|
||||
Self::Next => {
|
||||
state.select_next()
|
||||
},
|
||||
Self::Delete => {
|
||||
state.delete_selected()
|
||||
},
|
||||
Self::Append => {
|
||||
state.append_new(None, None)
|
||||
},
|
||||
Self::Insert => {
|
||||
state.insert_new(None, None)
|
||||
},
|
||||
Self::Duplicate => {
|
||||
state.insert_dup()
|
||||
},
|
||||
Self::Edit => {
|
||||
todo!();
|
||||
}
|
||||
Self::RandomColor => {
|
||||
state.randomize_color()
|
||||
},
|
||||
Self::MoveUp => {
|
||||
state.move_up()
|
||||
},
|
||||
Self::MoveDown => {
|
||||
state.move_down()
|
||||
},
|
||||
Self::Rename(PhraseRenameCommand::Begin) => {
|
||||
state.begin_rename()
|
||||
},
|
||||
Self::Rename(_) => {
|
||||
unreachable!()
|
||||
},
|
||||
Self::Length(PhraseLengthCommand::Begin) => {
|
||||
state.begin_length()
|
||||
},
|
||||
Self::Length(_) => {
|
||||
unreachable!()
|
||||
},
|
||||
Prev => { state.select_prev() },
|
||||
Next => { state.select_next() },
|
||||
Delete => { state.delete_selected() },
|
||||
Append => { state.append_new(None, None) },
|
||||
Insert => { state.insert_new(None, None) },
|
||||
Duplicate => { state.insert_dup() },
|
||||
Edit => { todo!(); }
|
||||
RandomColor => { state.randomize_color() },
|
||||
MoveUp => { state.move_up() },
|
||||
MoveDown => { state.move_down() },
|
||||
Rename(Rename::Begin) => { state.begin_rename() },
|
||||
Rename(_) => { unreachable!() },
|
||||
Length(Length::Begin) => { state.begin_length() },
|
||||
Length(_) => { unreachable!() },
|
||||
Import => todo!(),
|
||||
Export => todo!(),
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
impl<E: Engine> Command<PhrasePool<E>> for PhraseRenameCommand {
|
||||
fn run (&self, state: &mut PhrasePool<E>) -> Perhaps<Self> {
|
||||
use PhraseRenameCommand::*;
|
||||
if let Some(PhrasePoolMode::Rename(phrase, ref mut old_name)) = state.mode {
|
||||
match self {
|
||||
Self::Begin => {
|
||||
unreachable!();
|
||||
},
|
||||
Self::Backspace => {
|
||||
Begin => { unreachable!(); },
|
||||
Backspace => {
|
||||
let mut phrase = state.phrases[phrase].write().unwrap();
|
||||
let old_name = phrase.name.clone();
|
||||
phrase.name.pop();
|
||||
return Ok(Some(Self::Set(old_name)))
|
||||
},
|
||||
Self::Append(c) => {
|
||||
Append(c) => {
|
||||
let mut phrase = state.phrases[phrase].write().unwrap();
|
||||
let old_name = phrase.name.clone();
|
||||
phrase.name.push(*c);
|
||||
return Ok(Some(Self::Set(old_name)))
|
||||
},
|
||||
Self::Set(s) => {
|
||||
Set(s) => {
|
||||
let mut phrase = state.phrases[phrase].write().unwrap();
|
||||
phrase.name = s.into();
|
||||
return Ok(Some(Self::Set(old_name.clone())))
|
||||
},
|
||||
Self::Confirm => {
|
||||
Confirm => {
|
||||
let old_name = old_name.clone();
|
||||
state.mode = None;
|
||||
return Ok(Some(Self::Set(old_name)))
|
||||
},
|
||||
Self::Cancel => {
|
||||
Cancel => {
|
||||
let mut phrase = state.phrases[phrase].write().unwrap();
|
||||
phrase.name = old_name.clone();
|
||||
}
|
||||
};
|
||||
Ok(None)
|
||||
} else if *self == Self::Begin {
|
||||
} else if *self == Begin {
|
||||
todo!()
|
||||
} else {
|
||||
unreachable!()
|
||||
|
|
@ -182,46 +160,31 @@ impl<E: Engine> Command<PhrasePool<E>> for PhraseRenameCommand {
|
|||
}
|
||||
impl<E: Engine> Command<PhrasePool<E>> for PhraseLengthCommand {
|
||||
fn run (&self, state: &mut PhrasePool<E>) -> Perhaps<Self> {
|
||||
use PhraseLengthCommand::*;
|
||||
if let Some(PhrasePoolMode::Length(phrase, ref mut length, ref mut focus)) = state.mode {
|
||||
match self {
|
||||
Self::Begin => {
|
||||
unreachable!();
|
||||
Begin => { unreachable!(); },
|
||||
Cancel => { state.mode = None; },
|
||||
Confirm => { return Self::Set(*length).run(state) },
|
||||
Prev => { focus.prev() },
|
||||
Next => { focus.next() },
|
||||
Inc => {
|
||||
use PhraseLengthFocus::*;
|
||||
match focus {
|
||||
Bar => { *length += 4 * PPQ },
|
||||
Beat => { *length += PPQ },
|
||||
Tick => { *length += 1 },
|
||||
}
|
||||
},
|
||||
Self::Prev => {
|
||||
focus.prev()
|
||||
Dec => {
|
||||
use PhraseLengthFocus::*;
|
||||
match focus {
|
||||
Bar => { *length = length.saturating_sub(4 * PPQ) },
|
||||
Beat => { *length = length.saturating_sub(PPQ) },
|
||||
Tick => { *length = length.saturating_sub(1) },
|
||||
}
|
||||
},
|
||||
Self::Next => {
|
||||
focus.next()
|
||||
},
|
||||
Self::Inc => match focus {
|
||||
PhraseLengthFocus::Bar => {
|
||||
*length += 4 * PPQ
|
||||
},
|
||||
PhraseLengthFocus::Beat => {
|
||||
*length += PPQ
|
||||
},
|
||||
PhraseLengthFocus::Tick => {
|
||||
*length += 1
|
||||
},
|
||||
},
|
||||
Self::Dec => match focus {
|
||||
PhraseLengthFocus::Bar => {
|
||||
*length = length.saturating_sub(4 * PPQ)
|
||||
},
|
||||
PhraseLengthFocus::Beat => {
|
||||
*length = length.saturating_sub(PPQ)
|
||||
},
|
||||
PhraseLengthFocus::Tick => {
|
||||
*length = length.saturating_sub(1)
|
||||
},
|
||||
},
|
||||
Self::Cancel => {
|
||||
state.mode = None;
|
||||
},
|
||||
Self::Confirm => {
|
||||
return Self::Set(*length).run(state)
|
||||
},
|
||||
Self::Set(length) => {
|
||||
Set(length) => {
|
||||
let mut phrase = state.phrases[phrase].write().unwrap();
|
||||
let old_length = phrase.length;
|
||||
phrase.length = *length;
|
||||
|
|
@ -230,7 +193,7 @@ impl<E: Engine> Command<PhrasePool<E>> for PhraseLengthCommand {
|
|||
},
|
||||
}
|
||||
Ok(None)
|
||||
} else if *self == Self::Begin {
|
||||
} else if *self == Begin {
|
||||
todo!()
|
||||
} else {
|
||||
unreachable!()
|
||||
|
|
@ -239,54 +202,35 @@ impl<E: Engine> Command<PhrasePool<E>> for PhraseLengthCommand {
|
|||
}
|
||||
impl<E: Engine> Command<PhraseEditor<E>> for PhraseEditorCommand {
|
||||
fn run (&self, state: &mut PhraseEditor<E>) -> Perhaps<Self> {
|
||||
use PhraseEditorCommand::*;
|
||||
match self {
|
||||
Self::ToggleDirection => {
|
||||
state.mode = !state.mode;
|
||||
},
|
||||
Self::EnterEditMode => {
|
||||
state.entered = true;
|
||||
},
|
||||
Self::ExitEditMode => {
|
||||
state.entered = false;
|
||||
},
|
||||
Self::TimeZoomOut => {
|
||||
state.time_zoom_out()
|
||||
},
|
||||
Self::TimeZoomIn => {
|
||||
state.time_zoom_in()
|
||||
},
|
||||
Self::NoteLengthDec => {
|
||||
state.note_length_dec()
|
||||
},
|
||||
Self::NoteLengthInc => {
|
||||
state.note_length_inc()
|
||||
},
|
||||
Self::NotePageUp => {
|
||||
state.note_page_up()
|
||||
},
|
||||
Self::NotePageDown => {
|
||||
state.note_page_down()
|
||||
},
|
||||
Self::NoteAppend => if state.entered {
|
||||
ToggleDirection => { state.mode = !state.mode; },
|
||||
EnterEditMode => { state.entered = true; },
|
||||
ExitEditMode => { state.entered = false; },
|
||||
TimeZoomOut => { state.time_zoom_out() },
|
||||
TimeZoomIn => { state.time_zoom_in() },
|
||||
NoteLengthDec => { state.note_length_dec() },
|
||||
NoteLengthInc => { state.note_length_inc() },
|
||||
NotePageUp => { state.note_page_up() },
|
||||
NotePageDown => { state.note_page_down() },
|
||||
NoteAppend => if state.entered {
|
||||
state.put();
|
||||
state.time_cursor_advance();
|
||||
},
|
||||
Self::NoteSet => if state.entered {
|
||||
state.put();
|
||||
},
|
||||
Self::GoUp => match state.entered {
|
||||
NoteSet => if state.entered { state.put(); },
|
||||
GoUp => match state.entered {
|
||||
true => state.note_cursor_inc(),
|
||||
false => state.note_scroll_inc(),
|
||||
},
|
||||
Self::GoDown => match state.entered {
|
||||
GoDown => match state.entered {
|
||||
true => state.note_cursor_dec(),
|
||||
false => state.note_scroll_dec(),
|
||||
},
|
||||
Self::GoLeft => match state.entered {
|
||||
GoLeft => match state.entered {
|
||||
true => state.time_cursor_dec(),
|
||||
false => state.time_scroll_dec(),
|
||||
},
|
||||
Self::GoRight => match state.entered {
|
||||
GoRight => match state.entered {
|
||||
true => state.time_cursor_inc(),
|
||||
false => state.time_scroll_inc(),
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue