wip(p60,e90): impl macros

This commit is contained in:
🪞👃🪞 2024-11-20 20:46:20 +01:00
parent f4a4b08c8a
commit 9d4fcaa32b
17 changed files with 748 additions and 1083 deletions

View file

@ -38,7 +38,7 @@ pub enum SequencerCommand {
impl<T> Command<T> for SequencerCommand
where
T: PhrasesControl + PhraseControl + ClockApi + PlayheadApi
T: PhrasesControl + PhraseControl + PlayheadApi
+ FocusGrid<Item = SequencerFocus> + FocusEnter<Item = SequencerFocus>
{
fn execute (self, state: &mut T) -> Perhaps<Self> {
@ -62,6 +62,7 @@ pub enum ArrangerCommand {
Undo,
Redo,
Clear,
Color(ItemColor),
Clock(ClockCommand),
Playhead(PlayheadCommand),
Scene(ArrangerSceneCommand),
@ -74,12 +75,8 @@ pub enum ArrangerCommand {
EditPhrase(Option<Arc<RwLock<Phrase>>>),
}
impl<T> Command<T> for ArrangerCommand
where
T: ArrangerControl + HasPhrases + PhraseControl + ClockApi + PlayheadApi
+ FocusGrid<Item = ArrangerFocus> + FocusEnter<Item = ArrangerFocus>
{
fn execute (self, state: &mut T) -> Perhaps<Self> {
impl Command<ArrangerTui> for ArrangerCommand {
fn execute (self, state: &mut ArrangerTui) -> Perhaps<Self> {
use ArrangerCommand::*;
Ok(match self {
Focus(cmd) => cmd.execute(state)?.map(Focus),
@ -92,35 +89,33 @@ where
Playhead(cmd) => cmd.execute(state)?.map(Playhead),
Zoom(zoom) => { todo!(); },
Select(selected) => {
state.selected = selected;
*state.selected_mut() = selected;
None
},
EditPhrase(phrase) => {
state.editor.phrase = phrase.clone();
state.focus(ArrangerFocus::PhraseEditor);
state.focus_enter();
state.show_phrase(phrase);
None
}
})
}
}
impl<T: ArrangerControl> Command<T> for ArrangerSceneCommand {
fn execute (self, state: &mut T) -> Perhaps<Self> {
impl Command<ArrangerTui> for ArrangerSceneCommand {
fn execute (self, state: &mut ArrangerTui) -> Perhaps<Self> {
todo!();
Ok(None)
}
}
impl<T: ArrangerControl> Command<T> for ArrangerTrackCommand {
fn execute (self, state: &mut T) -> Perhaps<Self> {
impl Command<ArrangerTui> for ArrangerTrackCommand {
fn execute (self, state: &mut ArrangerTui) -> Perhaps<Self> {
todo!();
Ok(None)
}
}
impl<T: ArrangerControl> Command<T> for ArrangerClipCommand {
fn execute (self, state: &mut T) -> Perhaps<Self> {
impl Command<ArrangerTui> for ArrangerClipCommand {
fn execute (self, state: &mut ArrangerTui) -> Perhaps<Self> {
todo!();
Ok(None)
}
@ -141,7 +136,7 @@ impl<T: PhrasesControl> Command<T> for PhrasesCommand {
Self::Rename(command) => command.execute(state)?.map(Self::Rename),
Self::Length(command) => command.execute(state)?.map(Self::Length),
Self::Select(phrase) => {
*state.phrase_index_mut() = phrase;
state.set_phrase_index(phrase);
None
},
})
@ -268,118 +263,34 @@ impl<T> Command<T> for PhraseCommand
where
T: PhraseControl + FocusEnter
{
//fn translate (self, state: &PhraseTui<E>) -> Self {
//use PhraseCommand::*;
//match self {
//GoUp => match state.entered { true => NoteCursorInc, false => NoteScrollInc, },
//GoDown => match state.entered { true => NoteCursorDec, false => NoteScrollDec, },
//GoLeft => match state.entered { true => TimeCursorDec, false => TimeScrollDec, },
//GoRight => match state.entered { true => TimeCursorInc, false => TimeScrollInc, },
//_ => self
//}
//}
fn execute (self, state: &mut T) -> Perhaps<Self> {
use PhraseCommand::*;
Ok(match self {
ToggleDirection => {
state.phrase_mode_mut() = !state.mode;
ToggleDirection => { todo!() },
EnterEditMode => { state.focus_enter(); None },
ExitEditMode => { state.focus_exit(); None },
NoteAppend => {
if state.phrase_entered() {
state.put_note();
state.time_cursor_advance();
}
None
},
EnterEditMode => {
state.focus_enter();
None
},
ExitEditMode => {
state.focus_exit();
None
},
TimeZoomOut => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().scale = next_note_length(scale);
None
},
TimeZoomIn => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().scale = prev_note_length(scale);
None
},
TimeCursorDec => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().point_dec(scale);
None
},
TimeCursorInc => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().point_inc(scale);
None
},
TimeScrollDec => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().start_dec(scale);
None
},
TimeScrollInc => {
let scale = state.time_axis().read().unwrap().scale;
state.time_axis().write().unwrap().start_inc(scale);
None
},
NoteCursorDec => {
let mut axis = state.note_axis().write().unwrap();
axis.point_inc(1);
NoteSet => { if state.phrase_entered() { state.put_note(); } None },
TimeCursorSet(time) => { state.time_axis().write().unwrap().point_set(time); None },
TimeScrollSet(time) => { state.time_axis().write().unwrap().start_set(time); None },
TimeZoomSet(zoom) => { state.time_axis().write().unwrap().scale_set(zoom); None },
NoteScrollSet(note) => { state.note_axis().write().unwrap().start_set(note); None },
NoteLengthSet(time) => { *state.note_len_mut() = time; None },
NoteCursorSet(note) => {
let axis = state.note_axis().write().unwrap();
axis.point_set(note);
if let Some(point) = axis.point {
if point > 73 { axis.point = Some(73); }
}
None
},
NoteCursorInc => {
let mut axis = state.note_axis().write().unwrap();
axis.point_dec(1);
if let Some(point) = axis.point {
if point < axis.start { axis.start = (point / 2) * 2; }
}
None
},
NoteScrollDec => {
state.note_axis().write().unwrap().start_inc(1);
None
},
NoteScrollInc => {
state.note_axis().write().unwrap().start_dec(1);
None
},
NoteLengthDec => {
*state.note_len_mut() = prev_note_length(state.note_len());
None
},
NoteLengthInc => {
*state.note_len_mut() = next_note_length(state.note_len());
None
},
NotePageUp => {
let mut axis = state.note_axis().write().unwrap();
axis.start_dec(3);
axis.point_dec(3);
None
},
NotePageDown => {
let mut axis = state.note_axis().write().unwrap();
axis.start_inc(3);
axis.point_inc(3);
None
},
NoteAppend => if state.focus_entered() {
state.put();
state.time_cursor_advance();
None
} else {
None
},
NoteSet => if state.focus_entered() {
state.put();
None
} else {
None
},
_ => unreachable!()
})
}