mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
run pulse counter in transport
This commit is contained in:
parent
d77fe325b0
commit
f26609ed62
4 changed files with 34 additions and 43 deletions
|
|
@ -2,10 +2,10 @@ use crate::*;
|
|||
use std::iter::Iterator;
|
||||
|
||||
/// Any numeric type that represents time
|
||||
pub trait TimeUnit: PartialEq + Copy
|
||||
pub trait TimeUnit: PartialEq + Copy + Display
|
||||
+ Add<Self, Output=Self> + Mul<Self, Output=Self>
|
||||
+ Div<Self, Output=Self> + Rem<Self, Output=Self> {}
|
||||
impl<T> TimeUnit for T where T: PartialEq + Copy
|
||||
impl<T> TimeUnit for T where T: PartialEq + Copy + Display
|
||||
+ Add<Self, Output=Self> + Mul<Self, Output=Self>
|
||||
+ Div<Self, Output=Self> + Rem<Self, Output=Self> {}
|
||||
|
||||
|
|
@ -79,6 +79,12 @@ pub trait PulsesPerQuaver<U: TimeUnit> {
|
|||
fn ppq (&self) -> U;
|
||||
/// Set the PPQ
|
||||
fn set_ppq (&self, ppq: U);
|
||||
/// Return number of pulses to which a number of microseconds corresponds (BPM-dependent)
|
||||
#[inline] fn usecs_to_pulse (&self, usec: U) -> U
|
||||
where U: TimeFloat, Self: BeatsPerMinute<U>
|
||||
{
|
||||
usec / self.usec_per_pulse()
|
||||
}
|
||||
/// Return duration of a pulse in microseconds (BPM-dependent)
|
||||
#[inline] fn usec_per_pulse (&self) -> U
|
||||
where U: TimeFloat, Self: BeatsPerMinute<U>
|
||||
|
|
@ -135,13 +141,13 @@ pub trait UsecPosition<U: TimeUnit> {
|
|||
pub trait LaunchSync<U: TimeUnit> {
|
||||
fn sync (&self) -> U;
|
||||
fn set_sync (&self, sync: U);
|
||||
#[inline] fn next_launch_sample (&self) -> U where U: TimeInteger, Self: FramePosition<U> {
|
||||
#[inline] fn next_launch_sample (&self) -> U where U: TimeInteger, Self: PulsePosition<U> {
|
||||
let sync = self.sync();
|
||||
let sample = self.sample();
|
||||
if sample % sync == U::from(0) {
|
||||
sample
|
||||
let pulse = self.pulse();
|
||||
if pulse % sync == U::from(0) {
|
||||
pulse
|
||||
} else {
|
||||
(sample / sync) * sync + U::from(1)
|
||||
(pulse / sync) * sync + U::from(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -251,10 +257,10 @@ impl Iterator for TicksIterator {
|
|||
if self.1 > self.3 {
|
||||
return None
|
||||
}
|
||||
let fpt = self.0;
|
||||
let fpt = self.0;
|
||||
let sample = self.1 as f64;
|
||||
let start = self.2;
|
||||
let end = self.3;
|
||||
let start = self.2;
|
||||
let end = self.3;
|
||||
self.1 = self.1 + 1;
|
||||
//println!("{fpt} {sample} {start} {end}");
|
||||
let jitter = sample.rem_euclid(fpt); // ramps
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue