mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 19:56:42 +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,7 +1,23 @@
|
|||
use crate::*;
|
||||
|
||||
/// Represents the tracks and scenes of the composition.
|
||||
/// Root level object for standalone `tek_arranger`
|
||||
pub struct Arranger<E: Engine> {
|
||||
/// Controls the JACK transport.
|
||||
pub transport: Option<Arc<RwLock<TransportToolbar<E>>>>,
|
||||
/// Contains all the sequencers.
|
||||
pub arrangement: Arrangement<E>,
|
||||
/// This allows the sequencer view to be moved or hidden.
|
||||
pub show_sequencer: Option<tek_core::Direction>,
|
||||
/// Index of currently focused component
|
||||
pub focus: usize,
|
||||
/// Focus target that passes events down to sequencer
|
||||
pub sequencer_proxy: SequencerProxy<E>,
|
||||
/// Slot for modal dialog displayed on top of app.
|
||||
pub modal: Option<Box<dyn ContentComponent<E>>>,
|
||||
}
|
||||
|
||||
/// Represents the tracks and scenes of the composition.
|
||||
pub struct Arrangement<E: Engine> {
|
||||
/// Name of arranger
|
||||
pub name: Arc<RwLock<String>>,
|
||||
/// Collection of tracks.
|
||||
|
|
@ -12,13 +28,11 @@ pub struct Arranger<E: Engine> {
|
|||
pub selected: ArrangerFocus,
|
||||
/// Display mode of arranger
|
||||
pub mode: ArrangerViewMode,
|
||||
/// Slot for modal dialog displayed on top of app.
|
||||
pub modal: Option<Box<dyn ContentComponent<E>>>,
|
||||
/// Whether the arranger is currently focused
|
||||
pub focused: bool
|
||||
}
|
||||
|
||||
impl<E: Engine> Arranger<E> {
|
||||
impl<E: Engine> Arrangement<E> {
|
||||
pub fn new (name: &str) -> Self {
|
||||
Self {
|
||||
name: Arc::new(RwLock::new(name.into())),
|
||||
|
|
@ -26,7 +40,6 @@ impl<E: Engine> Arranger<E> {
|
|||
selected: ArrangerFocus::Clip(0, 0),
|
||||
scenes: vec![],
|
||||
tracks: vec![],
|
||||
modal: None,
|
||||
focused: false
|
||||
}
|
||||
}
|
||||
|
|
@ -345,7 +358,7 @@ impl ArrangerViewMode {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub struct VerticalArranger<'a, E: Engine>(
|
||||
pub &'a Arranger<E>, pub usize
|
||||
pub &'a Arrangement<E>, pub usize
|
||||
);
|
||||
pub struct VerticalArrangerGrid<'a>(
|
||||
pub u16, pub &'a [(usize, usize)], pub &'a [(usize, usize)]
|
||||
|
|
@ -357,7 +370,7 @@ pub struct VerticalArrangerCursor<'a>(
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub struct HorizontalArranger<'a, E: Engine>(
|
||||
pub &'a Arranger<E>
|
||||
pub &'a Arrangement<E>
|
||||
);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
include!("lib.rs");
|
||||
use tek_core::clap::{self, Parser};
|
||||
|
||||
pub fn main () -> Usually<()> { ArrangerCli::parse().run() }
|
||||
|
||||
/// Parses CLI arguments to the `tek_arranger` invocation.
|
||||
|
|
@ -27,14 +26,14 @@ impl ArrangerCli {
|
|||
let jack = JackClient::Inactive(
|
||||
Client::new("tek_arranger", ClientOptions::NO_START_SERVER)?.0
|
||||
);
|
||||
let mut arranger = Arranger::new("");
|
||||
let mut arrangement = Arrangement::new("");
|
||||
let jack_transport = jack.transport();
|
||||
let mut transport = TransportToolbar::new(Some(jack_transport));
|
||||
if let Some(name) = self.name.as_ref() {
|
||||
*arranger.name.write().unwrap() = name.clone();
|
||||
*arrangement.name.write().unwrap() = name.clone();
|
||||
}
|
||||
for _ in 0..self.tracks {
|
||||
let track = arranger.track_add(None)?;
|
||||
let track = arrangement.track_add(None)?;
|
||||
for _ in 0..self.scenes {
|
||||
track.phrases.push(
|
||||
Arc::new(RwLock::new(Phrase::new("", true, PPQ * 4, None)))
|
||||
|
|
@ -42,7 +41,7 @@ impl ArrangerCli {
|
|||
}
|
||||
}
|
||||
for _ in 0..self.scenes {
|
||||
let _scene = arranger.scene_add(None)?;
|
||||
let _scene = arrangement.scene_add(None)?;
|
||||
//for i in 0..self.tracks {
|
||||
//scene.clips[i] = Some(i);
|
||||
//}
|
||||
|
|
@ -57,137 +56,14 @@ impl ArrangerCli {
|
|||
}
|
||||
)?
|
||||
);
|
||||
Tui::run(Arc::new(RwLock::new(ArrangerStandalone {
|
||||
Tui::run(Arc::new(RwLock::new(Arranger {
|
||||
transport: self.transport.then_some(transport),
|
||||
show_sequencer: Some(tek_core::Direction::Down),
|
||||
arranger,
|
||||
arrangement,
|
||||
focus: 0,
|
||||
sequencer_proxy: SequencerProxy(Default::default(), false)
|
||||
sequencer_proxy: SequencerProxy(Default::default(), false),
|
||||
modal: None
|
||||
})))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Root level object for standalone `tek_arranger`
|
||||
struct ArrangerStandalone<E: Engine> {
|
||||
/// Controls the JACK transport.
|
||||
transport: Option<Arc<RwLock<TransportToolbar<E>>>>,
|
||||
/// Contains all the sequencers.
|
||||
arranger: Arranger<E>,
|
||||
/// This allows the sequencer view to be moved or hidden.
|
||||
show_sequencer: Option<tek_core::Direction>,
|
||||
/// Index of currently focused component
|
||||
focus: usize,
|
||||
/// Focus target that passes events down to sequencer
|
||||
sequencer_proxy: SequencerProxy<E>,
|
||||
}
|
||||
|
||||
/// The standalone arranger consists of transport, clip grid, and sequencer.
|
||||
impl Content for ArrangerStandalone<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.arranger.sequencer(),
|
||||
) {
|
||||
let arranger = &self.arranger as &dyn Widget<Engine = Tui>;
|
||||
let sequencer = sequencer as &dyn Widget<Engine = Tui>;
|
||||
add(&Split::new(direction, 20, arranger, sequencer.min_y(20)))
|
||||
} else {
|
||||
add(&self.arranger)
|
||||
}
|
||||
}))?;
|
||||
if let Some(ref modal) = self.arranger.modal {
|
||||
add(&Background(COLOR_BG1))?;
|
||||
add(&Foreground(COLOR_BG2))?;
|
||||
//add(modal as &dyn Widget<Engine = Tui>)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle top-level events in standalone arranger.
|
||||
impl Handle<Tui> for ArrangerStandalone<Tui> {
|
||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||
let focus = self.focus;
|
||||
let is_first_row = self.arranger.is_first_row();
|
||||
let is_last_row = self.arranger.is_last_row();
|
||||
let mut focused_handle = || {
|
||||
if focus == 2 {
|
||||
self.arranger.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 ArrangerStandalone<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.arranger, self.sequencer_proxy)
|
||||
}
|
||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;3] {
|
||||
focusables_mut!(self.transport, self.arranger, self.sequencer_proxy)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct SequencerProxy<E: Engine>(PhantomData<E>, bool);
|
||||
|
||||
impl Handle<Tui> for SequencerProxy<Tui> {
|
||||
fn handle (&mut self, _: &TuiInput) -> Perhaps<bool> { unreachable!() }
|
||||
}
|
||||
|
||||
impl Content for SequencerProxy<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> { "" }
|
||||
}
|
||||
|
||||
impl Focusable<Tui> for SequencerProxy<Tui> {
|
||||
fn is_focused (&self) -> bool { self.1 }
|
||||
fn set_focused (&mut self, focus: bool) { self.1 = focus }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -412,3 +412,20 @@ pub fn write_midi_output (writer: &mut MidiWriter, output: &MIDIChunk, frames: u
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SequencerProxy<E: Engine>(pub PhantomData<E>, pub bool);
|
||||
|
||||
impl Handle<Tui> for SequencerProxy<Tui> {
|
||||
fn handle (&mut self, _: &TuiInput) -> Perhaps<bool> { unreachable!() }
|
||||
}
|
||||
|
||||
impl Content for SequencerProxy<Tui> {
|
||||
type Engine = Tui;
|
||||
fn content (&self) -> impl Widget<Engine = Tui> { "" }
|
||||
}
|
||||
|
||||
impl Focusable<Tui> for SequencerProxy<Tui> {
|
||||
fn is_focused (&self) -> bool { self.1 }
|
||||
fn set_focused (&mut self, focus: bool) { self.1 = focus }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
//! Phrase editor.
|
||||
include!("lib.rs");
|
||||
pub fn main () -> Usually<()> { SequencerCli::parse().run() }
|
||||
|
||||
use tek_core::clap::{self, Parser};
|
||||
pub fn main () -> Usually<()> { SequencerCli::parse().run() }
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue