mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 04:36:45 +01:00
launch pt.9: fix beats_per_second
This commit is contained in:
parent
e149d777ed
commit
e7dce0f84b
4 changed files with 87 additions and 85 deletions
|
|
@ -74,7 +74,7 @@ impl Timebase {
|
|||
}
|
||||
/// Iterate over ticks between start and end.
|
||||
pub fn pulses_between_samples (&self, start: usize, end: usize) -> TicksIterator {
|
||||
TicksIterator { fpt: self.samples_per_pulse(), sample: start, start, end }
|
||||
TicksIterator { spp: self.samples_per_pulse(), sample: start, start, end }
|
||||
}
|
||||
}
|
||||
impl Default for Timebase { fn default () -> Self { Self::new(48000f64, 150f64, DEFAULT_PPQ) } }
|
||||
|
|
@ -126,23 +126,23 @@ impl Instant {
|
|||
}
|
||||
}
|
||||
/// Iterator that emits subsequent ticks within a range.
|
||||
pub struct TicksIterator { fpt: f64, sample: usize, start: usize, end: usize, }
|
||||
pub struct TicksIterator { spp: f64, sample: usize, start: usize, end: usize, }
|
||||
impl Iterator for TicksIterator {
|
||||
type Item = (usize, usize);
|
||||
fn next (&mut self) -> Option<Self::Item> {
|
||||
loop {
|
||||
if self.sample > self.end { return None }
|
||||
let fpt = self.fpt;
|
||||
let spp = self.spp;
|
||||
let sample = self.sample as f64;
|
||||
let start = self.start;
|
||||
let end = self.end;
|
||||
self.sample += 1;
|
||||
//println!("{fpt} {sample} {start} {end}");
|
||||
let jitter = sample.rem_euclid(fpt); // ramps
|
||||
let next_jitter = (sample + 1.0).rem_euclid(fpt);
|
||||
//println!("{spp} {sample} {start} {end}");
|
||||
let jitter = sample.rem_euclid(spp); // ramps
|
||||
let next_jitter = (sample + 1.0).rem_euclid(spp);
|
||||
if jitter > next_jitter { // at crossing:
|
||||
let time = (sample as usize) % (end as usize-start as usize);
|
||||
let tick = (sample / fpt) as usize;
|
||||
let tick = (sample / spp) as usize;
|
||||
return Some((time, tick))
|
||||
}
|
||||
}
|
||||
|
|
@ -173,7 +173,7 @@ pub trait MIDITime {
|
|||
/// Return the duration fo a beat in microseconds
|
||||
#[inline] fn usec_per_beat (&self) -> f64 { 60_000_000f64 / self.bpm().get() }
|
||||
/// Return the number of beats in a second
|
||||
#[inline] fn beat_per_second (&self) -> f64 { self.bpm().get() / 60_000_000f64 }
|
||||
#[inline] fn beat_per_second (&self) -> f64 { self.bpm().get() / 60f64 }
|
||||
/// Return the number of microseconds corresponding to a note of the given duration
|
||||
#[inline] fn note_to_usec (&self, (num, den): (f64, f64)) -> f64 {
|
||||
4.0 * self.usec_per_beat() * num / den
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue