mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-10 21:56:42 +01:00
wip: p.55, e=95
This commit is contained in:
parent
54fb5b6ece
commit
37ac7823af
10 changed files with 272 additions and 219 deletions
|
|
@ -97,20 +97,26 @@ impl<T: TransportControl> Command<T> for TransportCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl Command<SequencerTui> for SequencerCommand {
|
||||
fn execute (self, state: &mut SequencerTui) -> Perhaps<Self> {
|
||||
impl<T> Command<T> for SequencerCommand
|
||||
where
|
||||
T: FocusGrid + PhrasesControl + PhraseControl + ClockApi + PlayheadApi
|
||||
{
|
||||
fn execute (self, state: T) -> Perhaps<Self> {
|
||||
use SequencerCommand::*;
|
||||
match self {
|
||||
Focus(cmd) => delegate(cmd, Focus, &mut state),
|
||||
Phrases(cmd) => delegate(cmd, Phrases, &mut state.phrases),
|
||||
Editor(cmd) => delegate(cmd, Editor, &mut state.editor),
|
||||
Clock(cmd) => delegate(cmd, Clock, &mut state.transport),
|
||||
Playhead(cmd) => delegate(cmd, Playhead, &mut state.transport)
|
||||
Focus(cmd) => delegate(cmd, Focus, state),
|
||||
Phrases(cmd) => delegate(cmd, Phrases, state),
|
||||
Editor(cmd) => delegate(cmd, Editor, state),
|
||||
Clock(cmd) => delegate(cmd, Clock, state),
|
||||
Playhead(cmd) => delegate(cmd, Playhead, state)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ArrangerControl + FocusGrid> Command<T> for ArrangerCommand {
|
||||
impl<T> Command<T> for ArrangerCommand
|
||||
where
|
||||
T: FocusGrid + ArrangerControl + HasPhrases + PhraseControl + ClockApi + PlayheadApi
|
||||
{
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use ArrangerCommand::*;
|
||||
match self {
|
||||
|
|
@ -134,71 +140,59 @@ impl<T: ArrangerControl + FocusGrid> Command<T> for ArrangerCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> Command<T> for ArrangerSceneCommand {
|
||||
impl<T: ArrangerControl> Command<T> for ArrangerSceneCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
todo!()
|
||||
todo!();
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Command<T> for ArrangerTrackCommand {
|
||||
impl<T: ArrangerControl> Command<T> for ArrangerTrackCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
todo!()
|
||||
todo!();
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Command<T> for ArrangerClipCommand {
|
||||
impl<T: ArrangerControl> Command<T> for ArrangerClipCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
todo!()
|
||||
todo!();
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl Command<PhrasesTui> for PhrasesCommand {
|
||||
fn execute (self, view: &mut PhrasesTui) -> Perhaps<Self> {
|
||||
impl<T: PhrasesControl> Command<T> for PhrasesCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use PhraseRenameCommand as Rename;
|
||||
use PhraseLengthCommand as Length;
|
||||
match self {
|
||||
Self::Select(phrase) => {
|
||||
view.phrase = phrase
|
||||
state.phrase = phrase
|
||||
},
|
||||
Self::Edit(command) => {
|
||||
return Ok(command.execute(&mut view)?.map(Self::Edit))
|
||||
return Ok(command.execute(&mut state)?.map(Self::Edit))
|
||||
}
|
||||
Self::Rename(command) => match command {
|
||||
Rename::Begin => {
|
||||
view.mode = Some(PhrasesMode::Rename(
|
||||
view.phrase,
|
||||
view.phrases[view.phrase].read().unwrap().name.clone()
|
||||
))
|
||||
},
|
||||
_ => {
|
||||
return Ok(command.execute(view)?.map(Self::Rename))
|
||||
}
|
||||
Rename::Begin => self.phrases_rename_begin(),
|
||||
_ => return Ok(command.execute(state)?.map(Self::Rename)),
|
||||
},
|
||||
Self::Length(command) => match command {
|
||||
Length::Begin => {
|
||||
view.mode = Some(PhrasesMode::Length(
|
||||
view.phrase,
|
||||
view.phrases[view.phrase].read().unwrap().length,
|
||||
PhraseLengthFocus::Bar
|
||||
))
|
||||
},
|
||||
_ => {
|
||||
return Ok(command.execute(view)?.map(Self::Length))
|
||||
}
|
||||
Length::Begin => self.phrases_length_begin(),
|
||||
_ => return Ok(command.execute(state)?.map(Self::Length)),
|
||||
},
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
impl Command<PhrasesTui> for PhraseLengthCommand {
|
||||
fn execute (self, view: &mut PhrasesTui) -> Perhaps<Self> {
|
||||
impl<T: PhrasesControl> Command<T> for PhraseLengthCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use PhraseLengthFocus::*;
|
||||
use PhraseLengthCommand::*;
|
||||
if let Some(PhrasesMode::Length(phrase, ref mut length, ref mut focus)) = view.mode {
|
||||
if let Some(PhrasesMode::Length(phrase, ref mut length, ref mut focus)) = state.mode {
|
||||
match self {
|
||||
Self::Cancel => {
|
||||
view.mode = None;
|
||||
state.mode = None;
|
||||
},
|
||||
Self::Prev => {
|
||||
focus.prev()
|
||||
|
|
@ -217,21 +211,17 @@ impl Command<PhrasesTui> for PhraseLengthCommand {
|
|||
Tick => { *length = length.saturating_sub(1) },
|
||||
},
|
||||
Self::Set(length) => {
|
||||
let mut phrase = view.phrases[phrase].write().unwrap();
|
||||
let mut phrase = state.phrases[phrase].write().unwrap();
|
||||
let old_length = phrase.length;
|
||||
phrase.length = length;
|
||||
view.mode = None;
|
||||
state.mode = None;
|
||||
return Ok(Some(Self::Set(old_length)))
|
||||
},
|
||||
_ => unreachable!()
|
||||
}
|
||||
Ok(None)
|
||||
} else if self == Begin {
|
||||
view.mode = Some(PhrasesMode::Length(
|
||||
view.phrase,
|
||||
view.phrases[view.phrase].read().unwrap().length,
|
||||
PhraseLengthFocus::Bar
|
||||
));
|
||||
self.phrases_length_begin();
|
||||
Ok(None)
|
||||
} else {
|
||||
unreachable!()
|
||||
|
|
@ -239,32 +229,29 @@ impl Command<PhrasesTui> for PhraseLengthCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl Command<PhrasesTui> for PhraseRenameCommand {
|
||||
fn execute (self, view: &mut PhrasesTui) -> Perhaps<Self> {
|
||||
impl<T: PhrasesControl> Command<T> for PhraseRenameCommand {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use PhraseRenameCommand::*;
|
||||
if let Some(PhrasesMode::Rename(phrase, ref mut old_name)) = view.mode {
|
||||
if let Some(PhrasesMode::Rename(phrase, ref mut old_name)) = state.mode {
|
||||
match self {
|
||||
Set(s) => {
|
||||
view.phrases[phrase].write().unwrap().name = s.into();
|
||||
state.phrases[phrase].write().unwrap().name = s.into();
|
||||
return Ok(Some(Self::Set(old_name.clone())))
|
||||
},
|
||||
Confirm => {
|
||||
let old_name = old_name.clone();
|
||||
view.mode = None;
|
||||
state.mode = None;
|
||||
return Ok(Some(Self::Set(old_name)))
|
||||
},
|
||||
Cancel => {
|
||||
let mut phrase = view.phrases[phrase].write().unwrap();
|
||||
let mut phrase = state.phrases[phrase].write().unwrap();
|
||||
phrase.name = old_name.clone();
|
||||
},
|
||||
_ => unreachable!()
|
||||
};
|
||||
Ok(None)
|
||||
} else if self == Begin {
|
||||
view.mode = Some(PhrasesMode::Rename(
|
||||
view.phrase,
|
||||
view.phrases[view.phrase].read().unwrap().name.clone()
|
||||
));
|
||||
self.phrases_rename_begin();
|
||||
Ok(None)
|
||||
} else {
|
||||
unreachable!()
|
||||
|
|
@ -272,7 +259,7 @@ impl Command<PhrasesTui> for PhraseRenameCommand {
|
|||
}
|
||||
}
|
||||
|
||||
impl Command<PhraseTui> for PhraseCommand {
|
||||
impl<T: PhraseControl> Command<T> for PhraseCommand {
|
||||
//fn translate (self, state: &PhraseTui<E>) -> Self {
|
||||
//use PhraseCommand::*;
|
||||
//match self {
|
||||
|
|
@ -283,7 +270,7 @@ impl Command<PhraseTui> for PhraseCommand {
|
|||
//_ => self
|
||||
//}
|
||||
//}
|
||||
fn execute (self, state: &mut PhraseTui) -> Perhaps<Self> {
|
||||
fn execute (self, state: &mut T) -> Perhaps<Self> {
|
||||
use PhraseCommand::*;
|
||||
match self.translate(state) {
|
||||
ToggleDirection => {
|
||||
|
|
@ -296,58 +283,58 @@ impl Command<PhraseTui> for PhraseCommand {
|
|||
state.entered = false;
|
||||
},
|
||||
TimeZoomOut => {
|
||||
let scale = state.time_axis.read().unwrap().scale;
|
||||
state.time_axis.write().unwrap().scale = next_note_length(scale)
|
||||
let scale = state.time_axis().read().unwrap().scale;
|
||||
state.time_axis().write().unwrap().scale = next_note_length(scale)
|
||||
},
|
||||
TimeZoomIn => {
|
||||
let scale = state.time_axis.read().unwrap().scale;
|
||||
state.time_axis.write().unwrap().scale = prev_note_length(scale)
|
||||
let scale = state.time_axis().read().unwrap().scale;
|
||||
state.time_axis().write().unwrap().scale = prev_note_length(scale)
|
||||
},
|
||||
TimeCursorDec => {
|
||||
let scale = state.time_axis.read().unwrap().scale;
|
||||
state.time_axis.write().unwrap().point_dec(scale);
|
||||
let scale = state.time_axis().read().unwrap().scale;
|
||||
state.time_axis().write().unwrap().point_dec(scale);
|
||||
},
|
||||
TimeCursorInc => {
|
||||
let scale = state.time_axis.read().unwrap().scale;
|
||||
state.time_axis.write().unwrap().point_inc(scale);
|
||||
let scale = state.time_axis().read().unwrap().scale;
|
||||
state.time_axis().write().unwrap().point_inc(scale);
|
||||
},
|
||||
TimeScrollDec => {
|
||||
let scale = state.time_axis.read().unwrap().scale;
|
||||
state.time_axis.write().unwrap().start_dec(scale);
|
||||
let scale = state.time_axis().read().unwrap().scale;
|
||||
state.time_axis().write().unwrap().start_dec(scale);
|
||||
},
|
||||
TimeScrollInc => {
|
||||
let scale = state.time_axis.read().unwrap().scale;
|
||||
state.time_axis.write().unwrap().start_inc(scale);
|
||||
let scale = state.time_axis().read().unwrap().scale;
|
||||
state.time_axis().write().unwrap().start_inc(scale);
|
||||
},
|
||||
NoteCursorDec => {
|
||||
let mut axis = state.note_axis.write().unwrap();
|
||||
let mut axis = state.note_axis().write().unwrap();
|
||||
axis.point_inc(1);
|
||||
if let Some(point) = axis.point { if point > 73 { axis.point = Some(73); } }
|
||||
},
|
||||
NoteCursorInc => {
|
||||
let mut axis = state.note_axis.write().unwrap();
|
||||
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; } }
|
||||
},
|
||||
NoteScrollDec => {
|
||||
state.note_axis.write().unwrap().start_inc(1);
|
||||
state.note_axis().write().unwrap().start_inc(1);
|
||||
},
|
||||
NoteScrollInc => {
|
||||
state.note_axis.write().unwrap().start_dec(1);
|
||||
state.note_axis().write().unwrap().start_dec(1);
|
||||
},
|
||||
NoteLengthDec => {
|
||||
state.note_len = prev_note_length(state.note_len)
|
||||
*state.note_len_mut() = prev_note_length(state.note_len())
|
||||
},
|
||||
NoteLengthInc => {
|
||||
state.note_len = next_note_length(state.note_len)
|
||||
*state.note_len_mut() = next_note_length(state.note_len())
|
||||
},
|
||||
NotePageUp => {
|
||||
let mut axis = state.note_axis.write().unwrap();
|
||||
let mut axis = state.note_axis().write().unwrap();
|
||||
axis.start_dec(3);
|
||||
axis.point_dec(3);
|
||||
},
|
||||
NotePageDown => {
|
||||
let mut axis = state.note_axis.write().unwrap();
|
||||
let mut axis = state.note_axis().write().unwrap();
|
||||
axis.start_inc(3);
|
||||
axis.point_inc(3);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue