mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
103 lines
3.2 KiB
Rust
103 lines
3.2 KiB
Rust
use crate::*;
|
|
|
|
#[derive(Clone, PartialEq)]
|
|
pub enum ArrangerCommand {
|
|
Focus(FocusCommand),
|
|
Transport(TransportCommand),
|
|
Phrases(PhrasePoolCommand),
|
|
Editor(PhraseEditorCommand),
|
|
Arrangement(ArrangementCommand),
|
|
EditPhrase,
|
|
}
|
|
#[derive(Clone, PartialEq)]
|
|
pub enum ArrangementCommand {
|
|
New,
|
|
Load,
|
|
Save,
|
|
ToggleViewMode,
|
|
Delete,
|
|
Activate,
|
|
Increment,
|
|
Decrement,
|
|
ZoomIn,
|
|
ZoomOut,
|
|
MoveBack,
|
|
MoveForward,
|
|
RandomColor,
|
|
Put,
|
|
Get,
|
|
AddScene,
|
|
AddTrack,
|
|
ToggleLoop,
|
|
GoUp,
|
|
GoDown,
|
|
GoLeft,
|
|
GoRight,
|
|
Edit,
|
|
}
|
|
|
|
impl<E: Engine> Command<Arranger<E>> for ArrangerCommand {
|
|
fn execute (self, state: &mut Arranger<E>) -> Perhaps<Self> {
|
|
let undo = match self {
|
|
Self::Focus(cmd) => {
|
|
delegate(cmd, Self::Focus, state)
|
|
},
|
|
Self::Phrases(cmd) => {
|
|
delegate(cmd, Self::Phrases, &mut*state.phrases.write().unwrap())
|
|
},
|
|
Self::Editor(cmd) => {
|
|
delegate(cmd, Self::Editor, &mut state.editor)
|
|
},
|
|
Self::Arrangement(cmd) => {
|
|
delegate(cmd, Self::Arrangement, &mut state.arrangement)
|
|
},
|
|
Self::Transport(cmd) => if let Some(ref transport) = state.transport {
|
|
delegate(cmd, Self::Transport, &mut*transport.write().unwrap())
|
|
} else {
|
|
Ok(None)
|
|
},
|
|
Self::EditPhrase => if let Some(phrase) = state.arrangement.phrase() {
|
|
state.editor.phrase = Some(phrase.clone());
|
|
state.focus(ArrangerFocus::PhraseEditor);
|
|
state.focus_enter();
|
|
Ok(None)
|
|
} else {
|
|
Ok(None)
|
|
}
|
|
}?;
|
|
state.show_phrase();
|
|
state.update_status();
|
|
return Ok(undo);
|
|
}
|
|
}
|
|
impl<E: Engine> Command<Arrangement<E>> for ArrangementCommand {
|
|
fn execute (self, state: &mut Arrangement<E>) -> Perhaps<Self> {
|
|
use ArrangementCommand::*;
|
|
match self {
|
|
New => todo!(),
|
|
Load => todo!(),
|
|
Save => todo!(),
|
|
Edit => todo!(),
|
|
ToggleViewMode => { state.mode.to_next(); },
|
|
Delete => { state.delete(); },
|
|
Activate => { state.activate(); },
|
|
Increment => { state.increment(); },
|
|
Decrement => { state.decrement(); },
|
|
ZoomIn => { state.zoom_in(); },
|
|
ZoomOut => { state.zoom_out(); },
|
|
MoveBack => { state.move_back(); },
|
|
MoveForward => { state.move_forward(); },
|
|
RandomColor => { state.randomize_color(); },
|
|
Put => { state.phrase_put(); },
|
|
Get => { state.phrase_get(); },
|
|
AddScene => { state.scene_add(None, None)?; },
|
|
AddTrack => { state.track_add(None, None)?; },
|
|
ToggleLoop => { state.toggle_loop() },
|
|
GoUp => { state.go_up() },
|
|
GoDown => { state.go_down() },
|
|
GoLeft => { state.go_left() },
|
|
GoRight => { state.go_right() },
|
|
};
|
|
Ok(None)
|
|
}
|
|
}
|