mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
fix slooo
This commit is contained in:
parent
2f96897d39
commit
e30dd94d23
3 changed files with 29 additions and 13 deletions
|
|
@ -13,35 +13,50 @@ impl Timebase {
|
|||
pub fn new (rate: f64, bpm: f64, ppq: f64) -> Self {
|
||||
Self { rate: rate.into(), bpm: bpm.into(), ppq: ppq.into() }
|
||||
}
|
||||
|
||||
/// Frames per second
|
||||
#[inline] fn rate (&self) -> f64 {
|
||||
self.rate.load(Ordering::Relaxed)
|
||||
}
|
||||
/// Usec per frame
|
||||
#[inline] fn frame_usec (&self) -> f64 {
|
||||
1_000_000 as f64 / self.rate() as f64
|
||||
}
|
||||
/// Frames to usecs
|
||||
#[inline] pub fn frames_usecs (&self, frame: f64) -> f64 {
|
||||
frame * self.frame_usec()
|
||||
}
|
||||
|
||||
/// Beats per minute
|
||||
#[inline] pub fn bpm (&self) -> f64 {
|
||||
self.bpm.load(Ordering::Relaxed)
|
||||
}
|
||||
/// Usec per beat
|
||||
#[inline] fn beat_usec (&self) -> f64 {
|
||||
60_000_000f64 / self.bpm() as f64
|
||||
}
|
||||
|
||||
/// Pulses per beat
|
||||
#[inline] pub fn ppq (&self) -> f64 {
|
||||
self.ppq.load(Ordering::Relaxed)
|
||||
}
|
||||
/// Usec per pulse
|
||||
#[inline] fn pulse_usec (&self) -> f64 {
|
||||
self.beat_usec() / self.ppq() as f64
|
||||
}
|
||||
/// Pulses per frame
|
||||
#[inline] pub fn pulse_frame (&self) -> f64 {
|
||||
self.pulse_usec() / self.frame_usec() as f64
|
||||
}
|
||||
/// Frames per pulse
|
||||
#[inline] pub fn frame_pulse (&self) -> f64 {
|
||||
self.frame_usec() as f64 / self.pulse_usec()
|
||||
}
|
||||
/// Frames to pulses
|
||||
#[inline] pub fn pulses_frames (&self, pulses: f64) -> f64 {
|
||||
self.pulse_frame() * pulses
|
||||
}
|
||||
/// Pulses to frames
|
||||
#[inline] pub fn frames_pulses (&self, frames: f64) -> f64 {
|
||||
frames / self.pulse_frame()
|
||||
}
|
||||
|
|
@ -88,13 +103,14 @@ impl Timebase {
|
|||
}
|
||||
pub fn frames_to_ticks (
|
||||
&self,
|
||||
start: f64,
|
||||
end: f64,
|
||||
quant: f64,
|
||||
start: f64,
|
||||
end: f64,
|
||||
repeat: f64,
|
||||
) -> Vec<(usize, usize)> {
|
||||
let start_frame = start % quant;
|
||||
let end_frame = end % quant;
|
||||
let fpt = self.frames_per_tick();
|
||||
let start_frame = start % repeat;
|
||||
let end_frame = end % repeat;
|
||||
let fpt = self.pulse_frame();
|
||||
//panic!("{start_frame} {end_frame} {fpt}");
|
||||
let mut ticks = vec![];
|
||||
let mut add_frame = |frame: f64|{
|
||||
let jitter = frame.rem_euclid(fpt);
|
||||
|
|
@ -113,7 +129,7 @@ impl Timebase {
|
|||
loop {
|
||||
add_frame(frame as f64);
|
||||
frame = frame + 1;
|
||||
if frame >= quant as usize {
|
||||
if frame >= repeat as usize {
|
||||
frame = 0;
|
||||
loop {
|
||||
add_frame(frame as f64);
|
||||
|
|
|
|||
|
|
@ -25,11 +25,11 @@ impl Phrase {
|
|||
frame0: usize,
|
||||
frames: usize,
|
||||
) {
|
||||
let ticks = timebase.frames_to_ticks(
|
||||
frame0 as f64,
|
||||
(frame0 + frames) as f64,
|
||||
timebase.pulses_frames(self.length as f64)
|
||||
);
|
||||
let start = frame0 as f64;
|
||||
let end = start + frames as f64;
|
||||
let repeat = timebase.pulses_frames(self.length as f64);
|
||||
let ticks = timebase.frames_to_ticks(start, end, repeat);
|
||||
//panic!("{start} {end} {repeat} {ticks:?}");
|
||||
for (time, tick) in ticks.iter() {
|
||||
let events = self.notes.get(&(*tick as usize));
|
||||
if events.is_none() {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ fn main () -> Result<(), Box<dyn Error>> {
|
|||
sample!(44, "Hihat", "/home/user/Lab/Music/pak/chh.wav"),
|
||||
])))?.boxed(),
|
||||
|
||||
Plugin::lv2("Panagement", "file:///home/user/.lv2/Auburn Sounds Panagement 2.lv2")?.boxed(),
|
||||
//Plugin::lv2("Panagement", "file:///home/user/.lv2/Auburn Sounds Panagement 2.lv2")?.boxed(),
|
||||
|
||||
]), Some(vec![
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue