mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
Arranger -> Arrangement; ArrangerStandalone -> Arranger
This commit is contained in:
parent
11a66ee415
commit
a6b08a3249
5 changed files with 166 additions and 165 deletions
|
|
@ -1,26 +1,34 @@
|
|||
use crate::*;
|
||||
|
||||
impl Arranger<Tui> {
|
||||
pub fn rename_selected (&mut self) {
|
||||
self.modal = Some(Box::new(ArrangerRenameModal::new(
|
||||
self.selected,
|
||||
&match self.selected {
|
||||
ArrangerFocus::Mix => self.name.clone(),
|
||||
ArrangerFocus::Track(t) => self.tracks[t].name.clone(),
|
||||
ArrangerFocus::Scene(s) => self.scenes[s].name.clone(),
|
||||
ArrangerFocus::Clip(t, s) => self.tracks[t].phrases[s].read().unwrap().name.clone(),
|
||||
/// The standalone arranger consists of transport, clip grid, and sequencer.
|
||||
impl Content for Arranger<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
Layers::new(move|add|{
|
||||
add(&Stack::down(move|add|{
|
||||
add(&self.transport)?;
|
||||
if let (Some(direction), Some(sequencer)) = (
|
||||
self.show_sequencer,
|
||||
self.arrangement.sequencer(),
|
||||
) {
|
||||
let arrangement = &self.arrangement as &dyn Widget<Engine = Tui>;
|
||||
let sequencer = sequencer as &dyn Widget<Engine = Tui>;
|
||||
add(&Split::new(direction, 20, arrangement, sequencer.min_y(20)))
|
||||
} else {
|
||||
add(&self.arrangement)
|
||||
}
|
||||
}))?;
|
||||
if let Some(ref modal) = self.modal {
|
||||
add(&Background(COLOR_BG1))?;
|
||||
add(&Foreground(COLOR_BG2))?;
|
||||
//add(modal as &dyn Widget<Engine = Tui>)?;
|
||||
}
|
||||
)));
|
||||
}
|
||||
}
|
||||
impl Focusable<Tui> for Arranger<Tui> {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
fn set_focused (&mut self, focused: bool) {
|
||||
self.focused = focused
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle top-level events in standalone arranger.
|
||||
impl Handle<Tui> for Arranger<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
if let Some(modal) = self.modal.as_mut() {
|
||||
|
|
@ -30,6 +38,93 @@ impl Handle<Tui> for Arranger<Tui> {
|
|||
}
|
||||
return Ok(result)
|
||||
}
|
||||
let focus = self.focus;
|
||||
let is_first_row = self.arrangement.is_first_row();
|
||||
let is_last_row = self.arrangement.is_last_row();
|
||||
let mut focused_handle = || {
|
||||
if focus == 2 {
|
||||
self.arrangement.sequencer_mut().handle(from)
|
||||
} else {
|
||||
self.focused_mut().handle(from)
|
||||
}
|
||||
};
|
||||
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 focused_handle()
|
||||
}
|
||||
},
|
||||
key!(KeyCode::Up) => {
|
||||
if focus == 1 && is_first_row {
|
||||
self.focus_prev();
|
||||
} else {
|
||||
return focused_handle()
|
||||
}
|
||||
},
|
||||
_ => return focused_handle()
|
||||
}
|
||||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
|
||||
/// Focusable items in standalone arranger.
|
||||
impl Focus<3, Tui> for Arranger<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.arrangement, self.sequencer_proxy)
|
||||
}
|
||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;3] {
|
||||
focusables_mut!(self.transport, self.arrangement, self.sequencer_proxy)
|
||||
}
|
||||
}
|
||||
|
||||
impl Arranger<Tui> {
|
||||
pub fn rename_selected (&mut self) {
|
||||
self.modal = Some(Box::new(ArrangerRenameModal::new(
|
||||
self.arrangement.selected,
|
||||
&match self.arrangement.selected {
|
||||
ArrangerFocus::Mix => self.arrangement.name.clone(),
|
||||
ArrangerFocus::Track(t) => self.arrangement.tracks[t].name.clone(),
|
||||
ArrangerFocus::Scene(s) => self.arrangement.scenes[s].name.clone(),
|
||||
ArrangerFocus::Clip(t, s) => self.arrangement.tracks[t].phrases[s].read().unwrap().name.clone(),
|
||||
}
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
impl Focusable<Tui> for Arrangement<Tui> {
|
||||
fn is_focused (&self) -> bool {
|
||||
self.focused
|
||||
}
|
||||
fn set_focused (&mut self, focused: bool) {
|
||||
self.focused = focused
|
||||
}
|
||||
}
|
||||
|
||||
impl Handle<Tui> for Arrangement<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
match from.event() {
|
||||
// mode_switch: switch the display mode
|
||||
key!(KeyCode::Char('`')) => {
|
||||
|
|
@ -95,9 +190,9 @@ impl Handle<Tui> for Arranger<Tui> {
|
|||
self.track_add(None)?;
|
||||
},
|
||||
// rename: add a new scene
|
||||
key!(KeyCode::Char('n')) => {
|
||||
self.rename_selected();
|
||||
},
|
||||
//key!(KeyCode::Char('n')) => {
|
||||
//self.rename_selected();
|
||||
//},
|
||||
// length: add a new scene
|
||||
key!(KeyCode::Char('l')) => if let Some(phrase) = self.phrase() {
|
||||
phrase.write().unwrap().toggle_loop()
|
||||
|
|
@ -111,7 +206,8 @@ impl Handle<Tui> for Arranger<Tui> {
|
|||
Ok(Some(true))
|
||||
}
|
||||
}
|
||||
impl Content for Arranger<Tui> {
|
||||
|
||||
impl Content for Arrangement<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
Layers::new(move |add|{
|
||||
|
|
@ -341,7 +437,7 @@ impl<'a> Widget for VerticalArrangerCursor<'a> {
|
|||
impl<'a> Content for HorizontalArranger<'a, Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
let Arranger { tracks, focused, selected, scenes, .. } = self.0;
|
||||
let Arrangement { tracks, focused, selected, scenes, .. } = self.0;
|
||||
let _tracks = tracks.as_slice();
|
||||
lay!(
|
||||
focused.then_some(Background(Color::Rgb(40, 50, 30))),
|
||||
|
|
@ -510,7 +606,7 @@ impl<'a> Content for HorizontalArranger<'a, Tui> {
|
|||
CustomWidget::new(|_|{
|
||||
todo!()
|
||||
}, |to: &mut TuiOutput|{
|
||||
let Arranger { tracks, scenes, selected, .. } = self.0;
|
||||
let Arrangement { tracks, scenes, selected, .. } = self.0;
|
||||
let area = to.area();
|
||||
let mut x2 = 0;
|
||||
let [x, y, _, height] = area;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue