mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
wip: PhraseLength widget
This commit is contained in:
parent
b9b4f5ff3a
commit
83dafe3e81
2 changed files with 74 additions and 0 deletions
|
|
@ -309,3 +309,43 @@ impl<E: Engine> PhrasePlayer<E> {
|
||||||
self.overdub = !self.overdub;
|
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 }
|
||||||
|
|
|
||||||
|
|
@ -322,3 +322,37 @@ pub(crate) fn keys_vert () -> Buffer {
|
||||||
const NTH_OCTAVE: [&'static str;11] = [
|
const NTH_OCTAVE: [&'static str;11] = [
|
||||||
"-1", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
|
"-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(),
|
||||||
|
"]"
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue