wip: PhraseLength widget

This commit is contained in:
🪞👃🪞 2024-10-16 10:42:44 +03:00
parent b9b4f5ff3a
commit 83dafe3e81
2 changed files with 74 additions and 0 deletions

View file

@ -309,3 +309,43 @@ impl<E: Engine> PhrasePlayer<E> {
self.overdub = !self.overdub;
}
}
pub struct PhraseLength<E: Engine> {
_engine: PhantomData<E>,
pub ppq: usize,
pub bpb: usize,
pub pulses: usize,
pub focused: bool,
pub focus: PhraseLengthFocus
}
impl<E: Engine> PhraseLength<E> {
fn new (pulses: usize) -> Self {
Self {
_engine: Default::default(),
ppq: PPQ,
bpb: 4,
pulses,
focused: false,
focus: PhraseLengthFocus::Bar
}
}
pub fn bars (&self) -> usize {
self.pulses / (self.bpb * self.ppq)
}
pub fn beats (&self) -> usize {
self.pulses % (self.bpb * self.ppq)
}
pub fn ticks (&self) -> usize {
self.pulses % self.ppq
}
pub fn bars_string (&self) -> String {
format!("{}", self.bars())
}
pub fn beats_string (&self) -> String {
format!("{}", self.beats())
}
pub fn ticks_string (&self) -> String {
format!("{}", self.ticks())
}
}
#[derive(Copy,Clone)]
pub enum PhraseLengthFocus { Bar, Beat, Tick }

View file

@ -322,3 +322,37 @@ pub(crate) fn keys_vert () -> Buffer {
const NTH_OCTAVE: [&'static str;11] = [
"-1", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
];
impl Content for PhraseLength<Tui> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
Layers::new(move|add|{
match (self.focused, &self.focus) {
(false, _) => add(&row!(
" ", self.bars_string(),
".", self.beats_string(),
".", self.ticks_string(),
" "
)),
(true, PhraseLengthFocus::Bar) => add(&row!(
"[", self.bars_string(),
"]", self.beats_string(),
".", self.ticks_string(),
" "
)),
(true, PhraseLengthFocus::Beat) => add(&row!(
" ", self.bars_string(),
"[", self.beats_string(),
"]", self.ticks_string(),
" "
)),
(true, PhraseLengthFocus::Tick) => add(&row!(
" ", self.bars_string(),
".", self.beats_string(),
"[", self.ticks_string(),
"]"
)),
}
})
}
}