control transport values

This commit is contained in:
🪞👃🪞 2024-07-12 16:56:19 +03:00
parent 33e5f47526
commit 45021bc77a
10 changed files with 168 additions and 86 deletions

View file

@ -1,16 +1,43 @@
use crate::core::*;
#[derive(PartialEq)]
pub enum TransportFocus {
BPM,
Quant,
Sync,
}
impl TransportFocus {
pub fn prev (&mut self) {
*self = match self {
Self::BPM => Self::Sync,
Self::Quant => Self::BPM,
Self::Sync => Self::Quant,
}
}
pub fn next (&mut self) {
*self = match self {
Self::BPM => Self::Quant,
Self::Quant => Self::Sync,
Self::Sync => Self::BPM,
}
}
}
pub struct TransportToolbar {
pub metronome: bool,
pub mode: bool,
pub focused: bool,
pub entered: bool,
pub selected: TransportFocus,
/// Current sample rate, tempo, and PPQ.
pub timebase: Arc<Timebase>,
/// JACK transport handle.
transport: Option<Transport>,
/// Quantization factor
pub quant: usize,
/// Global sync quant
pub sync: usize,
/// Current transport state
pub playing: Option<TransportState>,
/// Current position according to transport
@ -21,17 +48,20 @@ pub struct TransportToolbar {
impl TransportToolbar {
pub fn new (transport: Option<Transport>) -> Self {
let timebase = Arc::new(Timebase::default());
Self {
transport,
selected: TransportFocus::BPM,
metronome: false,
mode: false,
focused: false,
entered: false,
timebase: Arc::new(Timebase::default()),
playhead: 0,
playing: Some(TransportState::Stopped),
started: None,
quant: 24,
sync: timebase.ppq() as usize * 4,
transport,
timebase,
}
}
pub fn toggle_play (&mut self) -> Usually<()> {