mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
remove TransportViewState
This commit is contained in:
parent
84d650adf2
commit
1060afa4f3
3 changed files with 69 additions and 64 deletions
|
|
@ -1,14 +1,13 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
impl<'a, T: TransportViewState> Content for TransportView<'a, T> {
|
impl Content for TransportView {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
let state = self.0;
|
let Self { state, selected, focused, bpm, sync, quant, beat, msu, } = self;
|
||||||
let selected = state.transport_selected();
|
|
||||||
row!(
|
row!(
|
||||||
selected.wrap(TransportFocus::PlayPause, &Styled(
|
selected.wrap(TransportFocus::PlayPause, &Styled(
|
||||||
None,
|
None,
|
||||||
match *state.transport_state().read().unwrap() {
|
match *state {
|
||||||
Some(TransportState::Rolling) => "▶ PLAYING",
|
Some(TransportState::Rolling) => "▶ PLAYING",
|
||||||
Some(TransportState::Starting) => "READY ...",
|
Some(TransportState::Starting) => "READY ...",
|
||||||
Some(TransportState::Stopped) => "⏹ STOPPED",
|
Some(TransportState::Stopped) => "⏹ STOPPED",
|
||||||
|
|
@ -16,19 +15,19 @@ impl<'a, T: TransportViewState> Content for TransportView<'a, T> {
|
||||||
}
|
}
|
||||||
).min_xy(11, 2).push_x(1)),
|
).min_xy(11, 2).push_x(1)),
|
||||||
selected.wrap(TransportFocus::Bpm, &Outset::X(1u16, {
|
selected.wrap(TransportFocus::Bpm, &Outset::X(1u16, {
|
||||||
let bpm = state.transport_bpm_value();
|
row! {
|
||||||
row! { "BPM ", format!("{}.{:03}", bpm as usize, (bpm * 1000.0) % 1000.0) }
|
"BPM ",
|
||||||
|
format!("{}.{:03}", *bpm as usize, (bpm * 1000.0) % 1000.0)
|
||||||
|
}
|
||||||
|
})),
|
||||||
|
selected.wrap(TransportFocus::Quant, &Outset::X(1u16, row! {
|
||||||
|
"QUANT ", pulses_to_name(*quant as usize)
|
||||||
})),
|
})),
|
||||||
//let quant = state.focus().wrap(state.focused(), TransportFocus::Quant, &Outset::X(1u16, row! {
|
|
||||||
//"QUANT ", ppq_to_name(state.0.quant as usize)
|
|
||||||
//})),
|
|
||||||
selected.wrap(TransportFocus::Sync, &Outset::X(1u16, row! {
|
selected.wrap(TransportFocus::Sync, &Outset::X(1u16, row! {
|
||||||
"SYNC ", pulses_to_name(state.transport_sync_value() as usize)
|
"SYNC ", pulses_to_name(*sync as usize)
|
||||||
})),
|
})),
|
||||||
selected.wrap(TransportFocus::Clock, &{
|
selected.wrap(TransportFocus::Clock, &{
|
||||||
let time1 = state.transport_format_beat();
|
row!("B" , beat.as_str(), " T", msu.as_str()).outset_x(1)
|
||||||
let time2 = state.transport_format_msu();
|
|
||||||
row!("B" ,time1.as_str(), " T", time2.as_str()).outset_x(1)
|
|
||||||
}).align_e().fill_x(),
|
}).align_e().fill_x(),
|
||||||
).fill_x().bg(Color::Rgb(40, 50, 30))
|
).fill_x().bg(Color::Rgb(40, 50, 30))
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +38,7 @@ impl Content for SequencerTui {
|
||||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||||
lay!(
|
lay!(
|
||||||
col!(
|
col!(
|
||||||
widget(&TransportView(self)),
|
TransportView::from(self),
|
||||||
Split::right(20,
|
Split::right(20,
|
||||||
widget(&PhrasesView(self)),
|
widget(&PhrasesView(self)),
|
||||||
widget(&PhraseView(self)),
|
widget(&PhraseView(self)),
|
||||||
|
|
@ -83,7 +82,7 @@ impl Content for ArrangerTui {
|
||||||
let arranger_focused = self.arranger_focused();
|
let arranger_focused = self.arranger_focused();
|
||||||
Split::down(
|
Split::down(
|
||||||
1,
|
1,
|
||||||
TransportView(self),
|
TransportView::from(self),
|
||||||
Split::down(
|
Split::down(
|
||||||
self.splits[0],
|
self.splits[0],
|
||||||
lay!(
|
lay!(
|
||||||
|
|
|
||||||
|
|
@ -1,57 +1,63 @@
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub struct TransportView<'a, T: TransportViewState>(pub &'a T);
|
pub struct TransportView {
|
||||||
|
pub(crate) state: Option<TransportState>,
|
||||||
|
pub(crate) selected: Option<TransportFocus>,
|
||||||
|
pub(crate) focused: bool,
|
||||||
|
pub(crate) bpm: f64,
|
||||||
|
pub(crate) sync: f64,
|
||||||
|
pub(crate) quant: f64,
|
||||||
|
pub(crate) beat: String,
|
||||||
|
pub(crate) msu: String,
|
||||||
|
}
|
||||||
|
impl<'a, T> From<&'a T> for TransportView
|
||||||
|
where
|
||||||
|
T: ClockApi,
|
||||||
|
Option<TransportFocus>: From<&'a T>
|
||||||
|
{
|
||||||
|
fn from (state: &'a T) -> Self {
|
||||||
|
let selected = state.into();
|
||||||
|
Self {
|
||||||
|
selected,
|
||||||
|
focused: selected.is_some(),
|
||||||
|
state: state.transport_state().read().unwrap().clone(),
|
||||||
|
bpm: state.bpm().get(),
|
||||||
|
sync: state.sync().get(),
|
||||||
|
quant: state.quant().get(),
|
||||||
|
beat: state.current().format_beat(),
|
||||||
|
msu: state.current().usec.format_msu(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<&TransportTui> for Option<TransportFocus> {
|
||||||
|
fn from (state: &TransportTui) -> Self {
|
||||||
|
match state.focus.inner() {
|
||||||
|
AppFocus::Content(focus) => Some(focus),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<&SequencerTui> for Option<TransportFocus> {
|
||||||
|
fn from (state: &SequencerTui) -> Self {
|
||||||
|
match state.focus.inner() {
|
||||||
|
AppFocus::Content(SequencerFocus::Transport(focus)) => Some(focus),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<&ArrangerTui> for Option<TransportFocus> {
|
||||||
|
fn from (state: &ArrangerTui) -> Self {
|
||||||
|
match state.focus.inner() {
|
||||||
|
AppFocus::Content(ArrangerFocus::Transport(focus)) => Some(focus),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct PhrasesView<'a, T: PhrasesViewState>(pub &'a T);
|
pub struct PhrasesView<'a, T: PhrasesViewState>(pub &'a T);
|
||||||
|
|
||||||
pub struct PhraseView<'a, T: PhraseViewState>(pub &'a T);
|
pub struct PhraseView<'a, T: PhraseViewState>(pub &'a T);
|
||||||
|
|
||||||
pub trait TransportViewState: ClockApi + Send + Sync {
|
|
||||||
fn transport_selected (&self) -> Option<TransportFocus>;
|
|
||||||
fn transport_focused (&self) -> bool {
|
|
||||||
self.transport_selected().is_some()
|
|
||||||
}
|
|
||||||
fn transport_bpm_value (&self) -> f64 {
|
|
||||||
self.bpm().get()
|
|
||||||
}
|
|
||||||
fn transport_sync_value (&self) -> f64 {
|
|
||||||
self.sync().get()
|
|
||||||
}
|
|
||||||
fn transport_format_beat (&self) -> String {
|
|
||||||
self.current().format_beat()
|
|
||||||
}
|
|
||||||
fn transport_format_msu (&self) -> String {
|
|
||||||
self.current().usec.format_msu()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TransportViewState for TransportTui {
|
|
||||||
fn transport_selected (&self) -> Option<TransportFocus> {
|
|
||||||
if let AppFocus::Content(focus) = self.focus.inner() {
|
|
||||||
Some(focus)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TransportViewState for SequencerTui {
|
|
||||||
fn transport_selected (&self) -> Option<TransportFocus> {
|
|
||||||
if let AppFocus::Content(SequencerFocus::Transport(focus)) = self.focus.inner() {
|
|
||||||
Some(focus)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl TransportViewState for ArrangerTui {
|
|
||||||
fn transport_selected (&self) -> Option<TransportFocus> {
|
|
||||||
if let AppFocus::Content(ArrangerFocus::Transport(focus)) = self.focus.inner() {
|
|
||||||
Some(focus)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait ArrangerViewState {
|
pub trait ArrangerViewState {
|
||||||
fn arranger_focused (&self) -> bool;
|
fn arranger_focused (&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ use crate::*;
|
||||||
impl Widget for TransportTui {
|
impl Widget for TransportTui {
|
||||||
type Engine = Tui;
|
type Engine = Tui;
|
||||||
fn layout (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
|
fn layout (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
|
||||||
TransportView(self).layout(to)
|
TransportView::from(self).layout(to)
|
||||||
}
|
}
|
||||||
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
|
fn render (&self, to: &mut TuiOutput) -> Usually<()> {
|
||||||
TransportView(self).render(to)
|
TransportView::from(self).render(to)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue