mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
extract _cmd modules
This commit is contained in:
parent
e20f195c20
commit
60c129d868
7 changed files with 270 additions and 267 deletions
|
|
@ -10,36 +10,6 @@ impl Content for Sequencer<Tui> {
|
|||
})
|
||||
}
|
||||
}
|
||||
/// Handle top-level events in standalone arranger.
|
||||
impl Handle<Tui> for Sequencer<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
if !match self.focused() {
|
||||
SequencerFocus::Transport => self.transport.handle(from)?,
|
||||
SequencerFocus::PhrasePool => self.phrases.handle(from)?,
|
||||
SequencerFocus::PhraseEditor => self.editor.handle(from)?
|
||||
}.unwrap_or(false) {
|
||||
match from.event() {
|
||||
// Tab navigation
|
||||
key!(KeyCode::Tab) => { self.focus_next(); },
|
||||
key!(Shift-KeyCode::Tab) => { self.focus_prev(); },
|
||||
key!(KeyCode::BackTab) => { self.focus_prev(); },
|
||||
key!(Shift-KeyCode::BackTab) => { self.focus_prev(); },
|
||||
// Directional navigation
|
||||
key!(KeyCode::Up) => { self.focus_up(); },
|
||||
key!(KeyCode::Down) => { self.focus_down(); },
|
||||
key!(KeyCode::Left) => { self.focus_left(); },
|
||||
key!(KeyCode::Right) => { self.focus_right(); },
|
||||
// Global play/pause binding
|
||||
key!(KeyCode::Char(' ')) => match self.transport {
|
||||
Some(ref mut transport) => { transport.write().unwrap().toggle_play()?; },
|
||||
None => { return Ok(None) }
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
// TODO: Display phrases always in order of appearance
|
||||
impl Content for PhrasePool<Tui> {
|
||||
type Engine = Tui;
|
||||
|
|
@ -82,64 +52,6 @@ impl Content for PhrasePool<Tui> {
|
|||
}).push_x(1))
|
||||
}
|
||||
}
|
||||
impl Handle<Tui> for PhrasePool<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
match self.mode {
|
||||
Some(PhrasePoolMode::Rename(phrase, ref mut old_name)) => {
|
||||
let mut phrase = self.phrases[phrase].write().unwrap();
|
||||
match from.event() {
|
||||
key!(KeyCode::Backspace) => { phrase.name.pop(); },
|
||||
key!(KeyCode::Char(c)) => { phrase.name.push(*c); },
|
||||
key!(Shift-KeyCode::Char(c)) => { phrase.name.push(*c); },
|
||||
key!(KeyCode::Esc) => { phrase.name = old_name.clone(); self.mode = None; },
|
||||
key!(KeyCode::Enter) => { self.mode = None; },
|
||||
_ => return Ok(None)
|
||||
}
|
||||
},
|
||||
None => match from.event() {
|
||||
key!(KeyCode::Up) => self.phrase = if self.phrase > 0 {
|
||||
self.phrase - 1
|
||||
} else {
|
||||
self.phrases.len() - 1
|
||||
},
|
||||
key!(KeyCode::Down) => {
|
||||
self.phrase = (self.phrase + 1) % self.phrases.len()
|
||||
},
|
||||
key!(KeyCode::Char('a')) => { // append new
|
||||
let mut phrase = Phrase::default();
|
||||
phrase.name = String::from("(no name)");
|
||||
phrase.color = random_color();
|
||||
self.phrases.push(Arc::new(RwLock::new(phrase)));
|
||||
self.phrase = self.phrases.len() - 1;
|
||||
},
|
||||
key!(KeyCode::Char('i')) => { // insert new
|
||||
let mut phrase = Phrase::default();
|
||||
phrase.name = String::from("(no name)");
|
||||
phrase.color = random_color();
|
||||
self.phrases.insert(self.phrase + 1, Arc::new(RwLock::new(phrase)));
|
||||
self.phrase += 1;
|
||||
},
|
||||
key!(KeyCode::Char('d')) => { // insert duplicate
|
||||
let mut phrase = (*self.phrases[self.phrase].read().unwrap()).clone();
|
||||
phrase.color = random_color_near(phrase.color, 0.2);
|
||||
self.phrases.insert(self.phrase + 1, Arc::new(RwLock::new(phrase)));
|
||||
self.phrase += 1;
|
||||
},
|
||||
key!(KeyCode::Char('c')) => { // change color
|
||||
let mut phrase = self.phrases[self.phrase].write().unwrap();
|
||||
phrase.color = random_color();
|
||||
},
|
||||
key!(KeyCode::Char('n')) => { // change name
|
||||
let phrase = self.phrases[self.phrase].read().unwrap();
|
||||
self.mode = Some(PhrasePoolMode::Rename(self.phrase, phrase.name.clone()));
|
||||
},
|
||||
_ => return Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(Some(true))
|
||||
}
|
||||
}
|
||||
impl Content for PhraseEditor<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
|
|
@ -247,35 +159,6 @@ impl Content for PhraseEditor<Tui> {
|
|||
}).push_x(1))
|
||||
}
|
||||
}
|
||||
impl Handle<Tui> for PhraseEditor<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
match from.event() {
|
||||
key!(KeyCode::Char('`')) => {
|
||||
self.mode = !self.mode;
|
||||
},
|
||||
key!(KeyCode::Up) => match self.entered {
|
||||
true => { self.note_axis.point_dec(); },
|
||||
false => { self.note_axis.start_dec(); },
|
||||
},
|
||||
key!(KeyCode::Down) => match self.entered {
|
||||
true => { self.note_axis.point_inc(); },
|
||||
false => { self.note_axis.start_inc(); },
|
||||
},
|
||||
key!(KeyCode::Left) => match self.entered {
|
||||
true => { self.time_axis.point_dec(); },
|
||||
false => { self.time_axis.start_dec(); },
|
||||
},
|
||||
key!(KeyCode::Right) => match self.entered {
|
||||
true => { self.time_axis.point_inc(); },
|
||||
false => { self.time_axis.start_inc(); },
|
||||
},
|
||||
_ => {
|
||||
return Ok(None)
|
||||
}
|
||||
}
|
||||
return Ok(Some(true))
|
||||
}
|
||||
}
|
||||
impl PhraseEditor<Tui> {
|
||||
const H_KEYS_OFFSET: usize = 5;
|
||||
/// Select which pattern to display. This pre-renders it to the buffer at full resolution.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue