mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-09 13:16:44 +01:00
wip: long awaited fixes to main sequencer
This commit is contained in:
parent
2837ffff4a
commit
78e5469b32
17 changed files with 391 additions and 563 deletions
|
|
@ -2,11 +2,11 @@ use crate::core::*;
|
|||
|
||||
pub struct Timebase {
|
||||
/// Frames per second
|
||||
pub rate: AtomicUsize,
|
||||
pub rate: AtomicUsize,
|
||||
/// Beats per minute
|
||||
pub tempo: AtomicUsize,
|
||||
pub bpm: AtomicUsize,
|
||||
/// Ticks per beat
|
||||
pub ppq: AtomicUsize,
|
||||
pub ppq: AtomicUsize,
|
||||
}
|
||||
|
||||
enum QuantizeMode {
|
||||
|
|
@ -35,14 +35,26 @@ impl Timebase {
|
|||
#[inline] pub fn rate (&self) -> usize {
|
||||
self.rate.load(Ordering::Relaxed)
|
||||
}
|
||||
#[inline] pub fn tempo (&self) -> usize {
|
||||
self.tempo.load(Ordering::Relaxed)
|
||||
#[inline] pub fn bpm (&self) -> usize {
|
||||
self.bpm.load(Ordering::Relaxed)
|
||||
}
|
||||
#[inline] pub fn ppq (&self) -> usize {
|
||||
self.ppq.load(Ordering::Relaxed)
|
||||
}
|
||||
#[inline] pub fn pulse_to_frame (&self, pulses: usize) -> usize {
|
||||
let beat = self.bpm() / 60;
|
||||
let quaver = beat / 4;
|
||||
let pulse = quaver / self.ppq();
|
||||
pulse * pulses
|
||||
}
|
||||
#[inline] pub fn frame_to_pulse (&self, frames: usize) -> usize {
|
||||
let beat = self.bpm() / 60;
|
||||
let quaver = beat / 4;
|
||||
let pulse = quaver / self.ppq();
|
||||
frames / pulse
|
||||
}
|
||||
#[inline] fn beats_per_second (&self) -> f64 {
|
||||
self.tempo() as f64 / 60000.0
|
||||
self.bpm() as f64 / 60000.0
|
||||
}
|
||||
#[inline] fn frames_per_second (&self) -> usize {
|
||||
self.rate()
|
||||
|
|
@ -72,7 +84,7 @@ impl Timebase {
|
|||
self.usec_per_beat() * beats_per_bar
|
||||
}
|
||||
#[inline] pub fn usec_per_beat (&self) -> usize {
|
||||
60_000_000_000 / self.tempo()
|
||||
60_000_000_000 / self.bpm()
|
||||
}
|
||||
#[inline] pub fn usec_per_step (&self, divisor: usize) -> usize {
|
||||
self.usec_per_beat() / divisor
|
||||
|
|
@ -93,9 +105,9 @@ impl Timebase {
|
|||
#[inline] pub fn note_to_frame (&self, note: &NoteDuration) -> usize {
|
||||
self.usec_to_frame(self.note_to_usec(note))
|
||||
}
|
||||
pub fn frames_to_ticks (&self, start: usize, end: usize, fpl: usize) -> Vec<(usize, usize)> {
|
||||
let start_frame = start % fpl;
|
||||
let end_frame = end % fpl;
|
||||
pub fn frames_to_ticks (&self, start: usize, end: usize, quant: usize) -> Vec<(usize, usize)> {
|
||||
let start_frame = start % quant;
|
||||
let end_frame = end % quant;
|
||||
let fpt = self.frames_per_tick();
|
||||
let mut ticks = vec![];
|
||||
let mut add_frame = |frame: f64|{
|
||||
|
|
@ -115,7 +127,7 @@ impl Timebase {
|
|||
loop {
|
||||
add_frame(frame as f64);
|
||||
frame = frame + 1;
|
||||
if frame >= fpl {
|
||||
if frame >= quant {
|
||||
frame = 0;
|
||||
loop {
|
||||
add_frame(frame as f64);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue