mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
fold single-use components into TransportToolbar
This commit is contained in:
parent
267f9f61d5
commit
0574eb79ef
2 changed files with 180 additions and 313 deletions
|
|
@ -118,24 +118,6 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for Option<W> {
|
||||||
self.as_ref().map(|widget|widget.render(to)).unwrap_or(Ok(()))
|
self.as_ref().map(|widget|widget.render(to)).unwrap_or(Ok(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// A [Widget] that contains other [Widget]s
|
|
||||||
pub trait Content: Send + Sync {
|
|
||||||
type Engine: Engine;
|
|
||||||
fn content (&self) -> impl Widget<Engine = <Self as Content>::Engine>;
|
|
||||||
}
|
|
||||||
/// Every struct that has [Content] is a renderable [Widget].
|
|
||||||
impl<E: Engine, W: Content<Engine = E>> Widget for W {
|
|
||||||
type Engine = E;
|
|
||||||
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
|
||||||
self.content().layout(to)
|
|
||||||
}
|
|
||||||
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
|
||||||
match self.layout(to.area().wh().into())? {
|
|
||||||
Some(wh) => to.render_in(to.area().clip(wh).into(), &self.content()),
|
|
||||||
None => Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// A custom [Widget] defined by passing layout and render closures in place.
|
/// A custom [Widget] defined by passing layout and render closures in place.
|
||||||
pub struct CustomWidget<
|
pub struct CustomWidget<
|
||||||
E: Engine,
|
E: Engine,
|
||||||
|
|
@ -164,6 +146,24 @@ impl<
|
||||||
self.1(to)
|
self.1(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// A [Widget] that contains other [Widget]s
|
||||||
|
pub trait Content: Send + Sync {
|
||||||
|
type Engine: Engine;
|
||||||
|
fn content (&self) -> impl Widget<Engine = <Self as Content>::Engine>;
|
||||||
|
}
|
||||||
|
/// Every struct that has [Content] is a renderable [Widget].
|
||||||
|
impl<E: Engine, W: Content<Engine = E>> Widget for W {
|
||||||
|
type Engine = E;
|
||||||
|
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
|
||||||
|
self.content().layout(to)
|
||||||
|
}
|
||||||
|
fn render (&self, to: &mut E::Output) -> Usually<()> {
|
||||||
|
match self.layout(to.area().wh().into())? {
|
||||||
|
Some(wh) => to.render_in(to.area().clip(wh).into(), &self.content()),
|
||||||
|
None => Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/// Handle input
|
/// Handle input
|
||||||
pub trait Handle<E: Engine>: Send + Sync {
|
pub trait Handle<E: Engine>: Send + Sync {
|
||||||
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled>;
|
fn handle (&mut self, context: &E::Input) -> Perhaps<E::Handled>;
|
||||||
|
|
|
||||||
|
|
@ -1447,12 +1447,15 @@ impl Content for Sequencer<Tui> {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
let toolbar = col!(
|
let toolbar = col!(
|
||||||
col! { "Name", self.name.read().unwrap().as_str(), }.min_xy(10, 4),
|
col! { "Name", self.name.read().unwrap().as_str(), },
|
||||||
col! { "Start: ", " 1.1.1", "End: ", " 2.1.1", }.min_xy(10, 6),
|
"",
|
||||||
col! { "Loop [ ]", "From: ", " 1.1.1", "Length: ", " 1.0.0", }.min_xy(10, 7),
|
col! { "Start: ", " 1.1.1", "End: ", " 2.1.1", },
|
||||||
|
"",
|
||||||
|
col! { "Loop [ ]", "From: ", " 1.1.1", "Length: ", " 1.0.0", },
|
||||||
|
"",
|
||||||
col! { "Notes: ", "C#0-C#9 ", "[ /2 ]", "[ x2 ]"
|
col! { "Notes: ", "C#0-C#9 ", "[ /2 ]", "[ x2 ]"
|
||||||
, "[ Rev ]", "[ Inv ]", "[ Dup ]" }.min_xy(10, 9),
|
, "[ Rev ]", "[ Inv ]", "[ Dup ]" },
|
||||||
);
|
).min_x(10);
|
||||||
let content = lay!(
|
let content = lay!(
|
||||||
// keys
|
// keys
|
||||||
CustomWidget::new(|_|Ok(Some([32,4])), |to: &mut TuiOutput|{
|
CustomWidget::new(|_|Ok(Some([32,4])), |to: &mut TuiOutput|{
|
||||||
|
|
@ -1815,6 +1818,8 @@ impl Phrase {
|
||||||
|
|
||||||
/// Stores and displays time-related state.
|
/// Stores and displays time-related state.
|
||||||
pub struct TransportToolbar<E: Engine> {
|
pub struct TransportToolbar<E: Engine> {
|
||||||
|
_engine: PhantomData<E>,
|
||||||
|
|
||||||
/// Enable metronome?
|
/// Enable metronome?
|
||||||
pub metronome: bool,
|
pub metronome: bool,
|
||||||
/// Current sample rate, tempo, and PPQ.
|
/// Current sample rate, tempo, and PPQ.
|
||||||
|
|
@ -1828,23 +1833,24 @@ pub struct TransportToolbar<E: Engine> {
|
||||||
pub started: Option<(usize, usize)>,
|
pub started: Option<(usize, usize)>,
|
||||||
|
|
||||||
pub focused: bool,
|
pub focused: bool,
|
||||||
pub focus: usize,
|
pub focus: TransportToolbarFocus,
|
||||||
pub playing: TransportPlayPauseButton<E>,
|
pub playing: Option<TransportState>,
|
||||||
pub bpm: TransportBPM<E>,
|
pub bpm: f64,
|
||||||
pub quant: TransportQuantize<E>,
|
pub quant: usize,
|
||||||
pub sync: TransportSync<E>,
|
pub sync: usize,
|
||||||
pub clock: TransportClock<E>,
|
pub frame: usize,
|
||||||
|
pub pulse: usize,
|
||||||
|
pub ppq: usize,
|
||||||
|
pub usecs: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: Engine> TransportToolbar<E> {
|
impl<E: Engine> TransportToolbar<E> {
|
||||||
pub fn standalone () -> Usually<Arc<RwLock<Self>>> where Self: 'static {
|
pub fn standalone () -> Usually<Arc<RwLock<Self>>> where Self: 'static {
|
||||||
let mut transport = Self::new(None);
|
|
||||||
transport.focused = true;
|
|
||||||
let jack = JackClient::Inactive(
|
let jack = JackClient::Inactive(
|
||||||
Client::new("tek_transport", ClientOptions::NO_START_SERVER)?.0
|
Client::new("tek_transport", ClientOptions::NO_START_SERVER)?.0
|
||||||
);
|
);
|
||||||
transport.transport = Some(jack.transport());
|
let mut transport = Self::new(Some(jack.transport()));
|
||||||
transport.playing.transport = Some(jack.transport());
|
transport.focused = true;
|
||||||
let transport = Arc::new(RwLock::new(transport));
|
let transport = Arc::new(RwLock::new(transport));
|
||||||
transport.write().unwrap().jack = Some(
|
transport.write().unwrap().jack = Some(
|
||||||
jack.activate(
|
jack.activate(
|
||||||
|
|
@ -1859,39 +1865,17 @@ impl<E: Engine> TransportToolbar<E> {
|
||||||
pub fn new (transport: Option<Transport>) -> Self {
|
pub fn new (transport: Option<Transport>) -> Self {
|
||||||
let timebase = Arc::new(Timebase::default());
|
let timebase = Arc::new(Timebase::default());
|
||||||
Self {
|
Self {
|
||||||
|
_engine: Default::default(),
|
||||||
focused: false,
|
focused: false,
|
||||||
focus: 0,
|
focus: TransportToolbarFocus::PlayPause,
|
||||||
|
playing: Some(TransportState::Stopped),
|
||||||
playing: TransportPlayPauseButton {
|
bpm: timebase.bpm(),
|
||||||
_engine: Default::default(),
|
quant: 24,
|
||||||
transport: None,
|
sync: timebase.ppq() as usize * 4,
|
||||||
value: Some(TransportState::Stopped),
|
|
||||||
focused: true
|
|
||||||
},
|
|
||||||
bpm: TransportBPM {
|
|
||||||
_engine: Default::default(),
|
|
||||||
value: timebase.bpm(),
|
|
||||||
focused: false
|
|
||||||
},
|
|
||||||
quant: TransportQuantize {
|
|
||||||
_engine: Default::default(),
|
|
||||||
value: 24,
|
|
||||||
focused: false
|
|
||||||
},
|
|
||||||
sync: TransportSync {
|
|
||||||
_engine: Default::default(),
|
|
||||||
value: timebase.ppq() as usize * 4,
|
|
||||||
focused: false
|
|
||||||
},
|
|
||||||
clock: TransportClock {
|
|
||||||
_engine: Default::default(),
|
|
||||||
frame: 0,
|
frame: 0,
|
||||||
pulse: 0,
|
pulse: 0,
|
||||||
ppq: 0,
|
ppq: 0,
|
||||||
usecs: 0,
|
usecs: 0,
|
||||||
focused: false
|
|
||||||
},
|
|
||||||
|
|
||||||
transport,
|
transport,
|
||||||
timebase,
|
timebase,
|
||||||
metronome: false,
|
metronome: false,
|
||||||
|
|
@ -1900,7 +1884,18 @@ impl<E: Engine> TransportToolbar<E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn toggle_play (&mut self) -> Usually<()> {
|
pub fn toggle_play (&mut self) -> Usually<()> {
|
||||||
self.playing.toggle()?;
|
let transport = self.transport.as_ref().unwrap();
|
||||||
|
self.playing = match self.playing.expect("1st frame has not been processed yet") {
|
||||||
|
TransportState::Stopped => {
|
||||||
|
transport.start()?;
|
||||||
|
Some(TransportState::Starting)
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
transport.stop()?;
|
||||||
|
transport.locate(0)?;
|
||||||
|
Some(TransportState::Stopped)
|
||||||
|
},
|
||||||
|
};
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn update (&mut self, scope: &ProcessScope) -> (bool, usize, usize, usize, usize, f64) {
|
pub fn update (&mut self, scope: &ProcessScope) -> (bool, usize, usize, usize, usize, f64) {
|
||||||
|
|
@ -1912,9 +1907,9 @@ impl<E: Engine> TransportToolbar<E> {
|
||||||
} = scope.cycle_times().unwrap();
|
} = scope.cycle_times().unwrap();
|
||||||
let chunk_size = scope.n_frames() as usize;
|
let chunk_size = scope.n_frames() as usize;
|
||||||
let transport = self.transport.as_ref().unwrap().query().unwrap();
|
let transport = self.transport.as_ref().unwrap().query().unwrap();
|
||||||
self.clock.frame = transport.pos.frame() as usize;
|
self.frame = transport.pos.frame() as usize;
|
||||||
let mut reset = false;
|
let mut reset = false;
|
||||||
if self.playing.value != Some(transport.state) {
|
if self.playing != Some(transport.state) {
|
||||||
match transport.state {
|
match transport.state {
|
||||||
TransportState::Rolling => {
|
TransportState::Rolling => {
|
||||||
self.started = Some((
|
self.started = Some((
|
||||||
|
|
@ -1929,7 +1924,7 @@ impl<E: Engine> TransportToolbar<E> {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.playing.value = Some(transport.state);
|
self.playing = Some(transport.state);
|
||||||
(
|
(
|
||||||
reset,
|
reset,
|
||||||
current_frames as usize,
|
current_frames as usize,
|
||||||
|
|
@ -1942,20 +1937,56 @@ impl<E: Engine> TransportToolbar<E> {
|
||||||
pub fn bpm (&self) -> usize {
|
pub fn bpm (&self) -> usize {
|
||||||
self.timebase.bpm() as usize
|
self.timebase.bpm() as usize
|
||||||
}
|
}
|
||||||
|
fn handle_bpm (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||||
|
match from.event() {
|
||||||
|
key!(KeyCode::Char(',')) => { self.bpm -= 1.0; },
|
||||||
|
key!(KeyCode::Char('.')) => { self.bpm += 1.0; },
|
||||||
|
key!(KeyCode::Char('<')) => { self.bpm -= 0.001; },
|
||||||
|
key!(KeyCode::Char('>')) => { self.bpm += 0.001; },
|
||||||
|
_ => return Ok(None)
|
||||||
|
}
|
||||||
|
Ok(Some(true))
|
||||||
|
}
|
||||||
pub fn ppq (&self) -> usize {
|
pub fn ppq (&self) -> usize {
|
||||||
self.timebase.ppq() as usize
|
self.timebase.ppq() as usize
|
||||||
}
|
}
|
||||||
pub fn pulse (&self) -> usize {
|
pub fn pulse (&self) -> usize {
|
||||||
self.timebase.frame_to_pulse(self.clock.frame as f64) as usize
|
self.timebase.frame_to_pulse(self.frame as f64) as usize
|
||||||
}
|
}
|
||||||
pub fn usecs (&self) -> usize {
|
pub fn usecs (&self) -> usize {
|
||||||
self.timebase.frame_to_usec(self.clock.frame as f64) as usize
|
self.timebase.frame_to_usec(self.frame as f64) as usize
|
||||||
}
|
}
|
||||||
pub fn quant (&self) -> usize {
|
pub fn quant (&self) -> usize {
|
||||||
self.quant.value
|
self.quant
|
||||||
|
}
|
||||||
|
fn handle_quant (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||||
|
match from.event() {
|
||||||
|
key!(KeyCode::Char(',')) => {
|
||||||
|
self.quant = prev_note_length(self.quant);
|
||||||
|
Ok(Some(true))
|
||||||
|
},
|
||||||
|
key!(KeyCode::Char('.')) => {
|
||||||
|
self.quant = next_note_length(self.quant);
|
||||||
|
Ok(Some(true))
|
||||||
|
},
|
||||||
|
_ => Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn sync (&self) -> usize {
|
pub fn sync (&self) -> usize {
|
||||||
self.sync.value
|
self.sync
|
||||||
|
}
|
||||||
|
fn handle_sync (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||||
|
match from.event() {
|
||||||
|
key!(KeyCode::Char(',')) => {
|
||||||
|
self.sync = prev_note_length(self.sync);
|
||||||
|
Ok(Some(true))
|
||||||
|
},
|
||||||
|
key!(KeyCode::Char('.')) => {
|
||||||
|
self.sync = next_note_length(self.sync);
|
||||||
|
Ok(Some(true))
|
||||||
|
},
|
||||||
|
_ => Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1969,9 +2000,15 @@ impl<E: Engine> Audio for TransportToolbar<E> {
|
||||||
impl Handle<Tui> for TransportToolbar<Tui> {
|
impl Handle<Tui> for TransportToolbar<Tui> {
|
||||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
||||||
match from.event() {
|
match from.event() {
|
||||||
key!(KeyCode::Left) => { self.focus_prev(); },
|
key!(KeyCode::Left) => { self.focus.prev(); },
|
||||||
key!(KeyCode::Right) => { self.focus_next(); },
|
key!(KeyCode::Right) => { self.focus.next(); },
|
||||||
_ => return self.focused_mut().handle(from)
|
_ => match self.focus {
|
||||||
|
TransportToolbarFocus::PlayPause => self.toggle_play().map(|_|())?,
|
||||||
|
TransportToolbarFocus::Bpm => self.handle_bpm(from).map(|_|())?,
|
||||||
|
TransportToolbarFocus::Quant => self.handle_quant(from).map(|_|())?,
|
||||||
|
TransportToolbarFocus::Sync => self.handle_sync(from).map(|_|())?,
|
||||||
|
TransportToolbarFocus::Clock => {/*todo*/},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(Some(true))
|
Ok(Some(true))
|
||||||
}
|
}
|
||||||
|
|
@ -1980,32 +2017,49 @@ impl Handle<Tui> for TransportToolbar<Tui> {
|
||||||
impl Content for TransportToolbar<Tui> {
|
impl Content for TransportToolbar<Tui> {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
let focus_wrap = |focused, component|Layers::new(move |add|{
|
|
||||||
if focused { add(&CORNERS)?; add(&Background(Color::Rgb(60, 70, 50)))?; }
|
|
||||||
add(component)
|
|
||||||
});
|
|
||||||
row! {
|
row! {
|
||||||
focus_wrap(self.focused && self.playing.focused, &self.playing),
|
|
||||||
focus_wrap(self.focused && self.bpm.focused, &self.bpm),
|
|
||||||
focus_wrap(self.focused && self.quant.focused, &self.quant),
|
|
||||||
focus_wrap(self.focused && self.sync.focused, &self.sync),
|
|
||||||
focus_wrap(self.focused && self.clock.focused, &self.clock),
|
|
||||||
}.fill_x().bg(Color::Rgb(40, 50, 30))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Focus<5, Tui> for TransportToolbar<Tui> {
|
self.focus.wrap(self.focused, TransportToolbarFocus::PlayPause, &Styled(
|
||||||
fn focus (&self) -> usize {
|
match self.playing {
|
||||||
self.focus
|
Some(TransportState::Stopped) => Some(GRAY_DIM.bold()),
|
||||||
|
Some(TransportState::Starting) => Some(GRAY_NOT_DIM_BOLD),
|
||||||
|
Some(TransportState::Rolling) => Some(WHITE_NOT_DIM_BOLD),
|
||||||
|
_ => unreachable!(),
|
||||||
|
},
|
||||||
|
match self.playing {
|
||||||
|
Some(TransportState::Rolling) => "▶ PLAYING",
|
||||||
|
Some(TransportState::Starting) => "READY ...",
|
||||||
|
Some(TransportState::Stopped) => "⏹ STOPPED",
|
||||||
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
fn focus_mut (&mut self) -> &mut usize {
|
).min_xy(11, 2).push_x(1)),
|
||||||
&mut self.focus
|
|
||||||
}
|
self.focus.wrap(self.focused, TransportToolbarFocus::Bpm, &Outset::X(1u16, col! {
|
||||||
fn focusable (&self) -> [&dyn Focusable<Tui>;5] {
|
"BPM",
|
||||||
focusables!(self.playing, self.bpm, self.quant, self.sync, self.clock)
|
format!("{}.{:03}", self.bpm as usize, (self.bpm * 1000.0) % 1000.0).as_str()
|
||||||
}
|
})),
|
||||||
fn focusable_mut (&mut self) -> [&mut dyn Focusable<Tui>;5] {
|
|
||||||
focusables_mut!(self.playing, self.bpm, self.quant, self.sync, self.clock)
|
self.focus.wrap(self.focused, TransportToolbarFocus::Quant, &Outset::X(1u16, col! {
|
||||||
|
"QUANT", ppq_to_name(self.quant as usize)
|
||||||
|
})),
|
||||||
|
|
||||||
|
self.focus.wrap(self.focused, TransportToolbarFocus::Sync, &Outset::X(1u16, col! {
|
||||||
|
"SYNC", ppq_to_name(self.sync as usize)
|
||||||
|
})),
|
||||||
|
|
||||||
|
self.focus.wrap(self.focused, TransportToolbarFocus::Clock, &{
|
||||||
|
let Self { frame: _frame, pulse, ppq, usecs, .. } = self;
|
||||||
|
let (beats, pulses) = if *ppq > 0 { (pulse / ppq, pulse % ppq) } else { (0, 0) };
|
||||||
|
let (bars, beats) = ((beats / 4) + 1, (beats % 4) + 1);
|
||||||
|
let (seconds, msecs) = (usecs / 1000000, usecs / 1000 % 1000);
|
||||||
|
let (minutes, seconds) = (seconds / 60, seconds % 60);
|
||||||
|
Outset::X(1u16, col! {
|
||||||
|
format!("{bars}.{beats}.{pulses:02}").as_str(),
|
||||||
|
format!("{minutes}:{seconds:02}:{msecs:03}").as_str(),
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
|
||||||
|
}.fill_x().bg(Color::Rgb(40, 50, 30))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2018,223 +2072,36 @@ impl Focusable<Tui> for TransportToolbar<Tui> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
#[derive(Clone, Copy, PartialEq)]
|
||||||
|
enum TransportToolbarFocus { PlayPause, Bpm, Quant, Sync, Clock, }
|
||||||
pub struct TransportPlayPauseButton<E: Engine> {
|
impl TransportToolbarFocus {
|
||||||
pub _engine: PhantomData<E>,
|
pub fn wrap <'a, W: Widget<Engine = Tui>> (
|
||||||
pub transport: Option<Transport>,
|
self, parent_focus: bool, focus: Self, widget: &'a W
|
||||||
pub value: Option<TransportState>,
|
) -> impl Widget<Engine = Tui> + 'a {
|
||||||
pub focused: bool
|
Layers::new(move |add|{
|
||||||
}
|
if parent_focus && focus == self {
|
||||||
impl<E: Engine> TransportPlayPauseButton<E> {
|
add(&CORNERS)?;
|
||||||
fn toggle (&mut self) -> Usually<()> {
|
add(&Background(Color::Rgb(60, 70, 50)))?;
|
||||||
let transport = self.transport.as_ref().unwrap();
|
|
||||||
self.value = match self.value.expect("1st frame has not been processed yet") {
|
|
||||||
TransportState::Stopped => {
|
|
||||||
transport.start()?;
|
|
||||||
Some(TransportState::Starting)
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
transport.stop()?;
|
|
||||||
transport.locate(0)?;
|
|
||||||
Some(TransportState::Stopped)
|
|
||||||
},
|
|
||||||
};
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
add(widget)
|
||||||
impl Focusable<Tui> for TransportPlayPauseButton<Tui> {
|
|
||||||
fn is_focused (&self) -> bool {
|
|
||||||
self.focused
|
|
||||||
}
|
|
||||||
fn set_focused (&mut self, focused: bool) {
|
|
||||||
self.focused = focused
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Handle<Tui> for TransportPlayPauseButton<Tui> {
|
|
||||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
||||||
match from.event() {
|
|
||||||
key!(KeyCode::Enter) => self.toggle().map(|_|Some(true)),
|
|
||||||
_ => Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Content for TransportPlayPauseButton<Tui> {
|
|
||||||
type Engine = Tui;
|
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
|
||||||
Layers::new(|add|{
|
|
||||||
add(&Styled(match self.value {
|
|
||||||
Some(TransportState::Stopped) => Some(GRAY_DIM.bold()),
|
|
||||||
Some(TransportState::Starting) => Some(GRAY_NOT_DIM_BOLD),
|
|
||||||
Some(TransportState::Rolling) => Some(WHITE_NOT_DIM_BOLD),
|
|
||||||
_ => unreachable!(),
|
|
||||||
}, match self.value {
|
|
||||||
Some(TransportState::Rolling) => "▶ PLAYING",
|
|
||||||
Some(TransportState::Starting) => "READY ...",
|
|
||||||
Some(TransportState::Stopped) => "⏹ STOPPED",
|
|
||||||
_ => unreachable!(),
|
|
||||||
}).min_xy(11, 2).push_x(1))?;
|
|
||||||
Ok(())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
fn next (&mut self) {
|
||||||
|
*self = match self {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
Self::PlayPause => Self::Bpm,
|
||||||
|
Self::Bpm => Self::Quant,
|
||||||
pub struct TransportBPM<E: Engine> {
|
Self::Quant => Self::Sync,
|
||||||
pub _engine: PhantomData<E>,
|
Self::Sync => Self::Clock,
|
||||||
pub value: f64,
|
Self::Clock => Self::PlayPause,
|
||||||
pub focused: bool
|
|
||||||
}
|
|
||||||
impl Focusable<Tui> for TransportBPM<Tui> {
|
|
||||||
fn is_focused (&self) -> bool {
|
|
||||||
self.focused
|
|
||||||
}
|
}
|
||||||
fn set_focused (&mut self, focused: bool) {
|
|
||||||
self.focused = focused
|
|
||||||
}
|
}
|
||||||
}
|
fn prev (&mut self) {
|
||||||
impl Handle<Tui> for TransportBPM<Tui> {
|
*self = match self {
|
||||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
Self::PlayPause => Self::Clock,
|
||||||
match from.event() {
|
Self::Bpm => Self::PlayPause,
|
||||||
key!(KeyCode::Char(',')) => { self.value -= 1.0; },
|
Self::Quant => Self::Bpm,
|
||||||
key!(KeyCode::Char('.')) => { self.value += 1.0; },
|
Self::Sync => Self::Quant,
|
||||||
key!(KeyCode::Char('<')) => { self.value -= 0.001; },
|
Self::Clock => Self::Sync,
|
||||||
key!(KeyCode::Char('>')) => { self.value += 0.001; },
|
|
||||||
_ => return Ok(None)
|
|
||||||
}
|
|
||||||
Ok(Some(true))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Content for TransportBPM<Tui> {
|
|
||||||
type Engine = Tui;
|
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
|
||||||
let Self { value, .. } = self;
|
|
||||||
Outset::X(1u16, Stack::down(move |add|{
|
|
||||||
add(&"BPM")?;
|
|
||||||
add(&format!("{}.{:03}", *value as usize, (value * 1000.0) % 1000.0).as_str())
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
pub struct TransportQuantize<E: Engine> {
|
|
||||||
pub _engine: PhantomData<E>,
|
|
||||||
pub value: usize,
|
|
||||||
pub focused: bool
|
|
||||||
}
|
|
||||||
impl Focusable<Tui> for TransportQuantize<Tui> {
|
|
||||||
fn is_focused (&self) -> bool {
|
|
||||||
self.focused
|
|
||||||
}
|
|
||||||
fn set_focused (&mut self, focused: bool) {
|
|
||||||
self.focused = focused
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Handle<Tui> for TransportQuantize<Tui> {
|
|
||||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
||||||
match from.event() {
|
|
||||||
key!(KeyCode::Char(',')) => {
|
|
||||||
self.value = prev_note_length(self.value);
|
|
||||||
Ok(Some(true))
|
|
||||||
},
|
|
||||||
key!(KeyCode::Char('.')) => {
|
|
||||||
self.value = next_note_length(self.value);
|
|
||||||
Ok(Some(true))
|
|
||||||
},
|
|
||||||
_ => Ok(None)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Content for TransportQuantize<Tui> {
|
|
||||||
type Engine = Tui;
|
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
|
||||||
let Self { value, .. } = self;
|
|
||||||
Outset::X(1u16, Stack::down(|add|{
|
|
||||||
add(&"QUANT")?;
|
|
||||||
add(&ppq_to_name(*value as usize))
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
pub struct TransportSync<E: Engine> {
|
|
||||||
pub _engine: PhantomData<E>,
|
|
||||||
pub value: usize,
|
|
||||||
pub focused: bool
|
|
||||||
}
|
|
||||||
impl Focusable<Tui> for TransportSync<Tui> {
|
|
||||||
fn is_focused (&self) -> bool {
|
|
||||||
self.focused
|
|
||||||
}
|
|
||||||
fn set_focused (&mut self, focused: bool) {
|
|
||||||
self.focused = focused
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Handle<Tui> for TransportSync<Tui> {
|
|
||||||
fn handle (&mut self, from: &TuiInput) -> Perhaps<bool> {
|
|
||||||
match from.event() {
|
|
||||||
key!(KeyCode::Char(',')) => {
|
|
||||||
self.value = prev_note_length(self.value);
|
|
||||||
Ok(Some(true))
|
|
||||||
},
|
|
||||||
key!(KeyCode::Char('.')) => {
|
|
||||||
self.value = next_note_length(self.value);
|
|
||||||
Ok(Some(true))
|
|
||||||
},
|
|
||||||
_ => Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Content for TransportSync<Tui> {
|
|
||||||
type Engine = Tui;
|
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
|
||||||
let Self { value, .. } = self;
|
|
||||||
Outset::X(1u16, Stack::down(|add|{
|
|
||||||
add(&"SYNC")?;
|
|
||||||
add(&ppq_to_name(*value as usize))
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
pub struct TransportClock<E: Engine> {
|
|
||||||
pub _engine: PhantomData<E>,
|
|
||||||
pub frame: usize,
|
|
||||||
pub pulse: usize,
|
|
||||||
pub ppq: usize,
|
|
||||||
pub usecs: usize,
|
|
||||||
pub focused: bool,
|
|
||||||
}
|
|
||||||
impl Focusable<Tui> for TransportClock<Tui> {
|
|
||||||
fn is_focused (&self) -> bool {
|
|
||||||
self.focused
|
|
||||||
}
|
|
||||||
fn set_focused (&mut self, focused: bool) {
|
|
||||||
self.focused = focused
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Handle<Tui> for TransportClock<Tui> {
|
|
||||||
fn handle (&mut self, _: &TuiInput) -> Perhaps<bool> {
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl Content for TransportClock<Tui> {
|
|
||||||
type Engine = Tui;
|
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
|
||||||
let Self { frame: _frame, pulse, ppq, usecs, .. } = self;
|
|
||||||
Layers::new(move|add|{
|
|
||||||
let (beats, pulses) = if *ppq > 0 { (pulse / ppq, pulse % ppq) } else { (0, 0) };
|
|
||||||
let (bars, beats) = ((beats / 4) + 1, (beats % 4) + 1);
|
|
||||||
let (seconds, msecs) = (usecs / 1000000, usecs / 1000 % 1000);
|
|
||||||
let (minutes, seconds) = (seconds / 60, seconds % 60);
|
|
||||||
add(&Outset::X(1u16, Stack::down(|add|{
|
|
||||||
add(&format!("{bars}.{beats}.{pulses:02}").as_str())?;
|
|
||||||
add(&format!("{minutes}:{seconds:02}:{msecs:03}").as_str())
|
|
||||||
})))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue