mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
wip: reenable standalone sequencer
This commit is contained in:
parent
690a8e8f24
commit
0eb063db1c
7 changed files with 125 additions and 37 deletions
|
|
@ -1,4 +1,72 @@
|
|||
use crate::*;
|
||||
impl Content for Sequencer<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
Stack::down(move|add|{
|
||||
add(&self.transport)?;
|
||||
add(&self.phrases.clone()
|
||||
.split(Direction::Right, 20, &self.editor as &dyn Widget<Engine = Tui>)
|
||||
.min_y(20)
|
||||
.fill_y())
|
||||
})
|
||||
}
|
||||
}
|
||||
/// Focusable items in standalone arranger.
|
||||
impl Focus<3, Tui> for Sequencer<Tui> {
|
||||
fn focus (&self) -> usize {
|
||||
self.focus
|
||||
}
|
||||
fn focus_mut (&mut self) -> &mut usize {
|
||||
&mut self.focus
|
||||
}
|
||||
fn focusable (&self) -> [&dyn Focusable<Tui>;3] {
|
||||
focusables!(self.transport, self.phrases, self.editor)
|
||||
}
|
||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;3] {
|
||||
focusables_mut!(self.transport, self.phrases, self.editor)
|
||||
}
|
||||
}
|
||||
/// Handle top-level events in standalone arranger.
|
||||
impl Handle<Tui> for Sequencer<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
let focus = self.focus;
|
||||
let is_first_row = false;
|
||||
let is_last_row = false;
|
||||
match from.event() {
|
||||
key!(KeyCode::Char(' ')) => {
|
||||
if let Some(ref mut transport) = self.transport {
|
||||
transport.write().unwrap().toggle_play()?;
|
||||
} else {
|
||||
return Ok(None)
|
||||
}
|
||||
},
|
||||
key!(KeyCode::Tab) => {
|
||||
self.focus_next();
|
||||
},
|
||||
key!(KeyCode::BackTab) => {
|
||||
self.focus_prev();
|
||||
},
|
||||
key!(KeyCode::Down) => {
|
||||
if focus == 0 {
|
||||
self.focus_next();
|
||||
} else if focus == 1 && is_last_row {
|
||||
self.focus_next();
|
||||
} else {
|
||||
return self.focused_mut().handle(from)
|
||||
}
|
||||
},
|
||||
key!(KeyCode::Up) => {
|
||||
if focus == 1 && is_first_row {
|
||||
self.focus_prev();
|
||||
} else {
|
||||
return self.focused_mut().handle(from)
|
||||
}
|
||||
},
|
||||
_ => return self.focused_mut().handle(from)
|
||||
}
|
||||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
// TODO: Display phrases always in order of appearance
|
||||
impl Content for PhrasePool<Tui> {
|
||||
type Engine = Tui;
|
||||
|
|
@ -14,6 +82,24 @@ impl Content for PhrasePool<Tui> {
|
|||
.fg(Color::Rgb(70, 80, 50))))
|
||||
}
|
||||
}
|
||||
impl Focusable<Tui> for PhrasePool<Tui> {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
fn set_focused (&mut self, focused: bool) {
|
||||
self.focused = focused
|
||||
}
|
||||
}
|
||||
impl Handle<Tui> for PhrasePool<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
match from.event() {
|
||||
key!(KeyCode::Up) => todo!(),
|
||||
key!(KeyCode::Down) => todo!(),
|
||||
_ => return Ok(None),
|
||||
}
|
||||
return Ok(Some(true))
|
||||
}
|
||||
}
|
||||
impl Content for PhraseEditor<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
|
|
@ -21,7 +107,7 @@ impl Content for PhraseEditor<Tui> {
|
|||
let toolbar = Stack::down(move|add|{
|
||||
//let name = format!("{:>9}", self.name.read().unwrap().as_str());
|
||||
//add(&col!("Track:", TuiStyle::bg(name.as_str(), field_bg)))?;
|
||||
if let Some(phrase) = self.phrase {
|
||||
if let Some(phrase) = &self.phrase {
|
||||
let phrase = phrase.read().unwrap();
|
||||
let length = format!("{}q{}p", phrase.length / PPQ, phrase.length % PPQ);
|
||||
let length = format!("{:>9}", &length);
|
||||
|
|
@ -49,10 +135,10 @@ impl Content for PhraseEditor<Tui> {
|
|||
}).fill_y(),
|
||||
// playhead
|
||||
CustomWidget::new(|_|Ok(Some([32,2])), |to: &mut TuiOutput|{
|
||||
if let Some(phrase) = self.phrase {
|
||||
if let Some(phrase) = &self.phrase {
|
||||
let time_0 = self.time_axis.start;
|
||||
let time_z = self.time_axis.scale;
|
||||
let now = self.now % phrase.read().unwrap().length;
|
||||
let now = 0; // TODO FIXME: self.now % phrase.read().unwrap().length;
|
||||
let [x, y, width, _] = to.area();
|
||||
let x2 = x as usize + Self::H_KEYS_OFFSET;
|
||||
let x3 = x as usize + width as usize;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue