use crate::*; #[derive(Clone, PartialEq)] pub enum ArrangerCommand { FocusNext, FocusPrev, FocusUp, FocusDown, FocusLeft, FocusRight, Transport(TransportCommand), Phrases(PhrasePoolCommand), Editor(PhraseEditorCommand), Arrangement(ArrangementCommand), } #[derive(Clone, PartialEq)] pub enum ArrangementCommand { ToggleViewMode, Delete, Activate, Increment, Decrement, ZoomIn, ZoomOut, MoveBack, MoveForward, RandomColor, Put, Get, AddScene, AddTrack, ToggleLoop, GoUp, GoDown, GoLeft, GoRight, } impl Command> for ArrangerCommand { fn run (&self, state: &mut Arranger) -> Perhaps { use ArrangerCommand::*; match self { FocusNext => { state.focus_next(); }, FocusPrev => { state.focus_prev(); }, FocusUp => { state.focus_up(); }, FocusDown => { state.focus_down(); }, FocusLeft => { state.focus_left(); }, FocusRight => { state.focus_right(); }, Transport(command) => if let Some(ref transport) = state.transport { return command.run(&mut*transport.write().unwrap()).map(|x|x.map(Transport)) }, Phrases(command) => { return command.run(&mut*state.phrases.write().unwrap()).map(|x|x.map(Phrases)) }, Editor(command) => { return command.run(&mut state.editor).map(|x|x.map(Editor)) }, Arrangement(command) => { return command.run(&mut state.arrangement).map(|x|x.map(Arrangement)) }, } state.show_phrase(); state.update_status(); Ok(None) } } impl Command> for ArrangementCommand { fn run (&self, state: &mut Arrangement) -> Perhaps { use ArrangementCommand::*; match self { 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) } }