mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-08 12:46:42 +01:00
refactor: reuse horizontal::draw
This commit is contained in:
parent
91832e0072
commit
939ffe3630
6 changed files with 130 additions and 117 deletions
|
|
@ -27,7 +27,7 @@ impl Timebase {
|
|||
self.bpm.load(Ordering::Relaxed)
|
||||
}
|
||||
#[inline] fn beat_usec (&self) -> f64 {
|
||||
60_000_000_000_000f64 / self.bpm() as f64
|
||||
60_000_000f64 / self.bpm() as f64
|
||||
}
|
||||
|
||||
#[inline] pub fn ppq (&self) -> f64 {
|
||||
|
|
@ -36,7 +36,7 @@ impl Timebase {
|
|||
#[inline] fn pulse_usec (&self) -> f64 {
|
||||
self.beat_usec() / self.ppq() as f64
|
||||
}
|
||||
#[inline] fn pulse_frame (&self) -> f64 {
|
||||
#[inline] pub fn pulse_frame (&self) -> f64 {
|
||||
self.pulse_usec() / self.frame_usec() as f64
|
||||
}
|
||||
#[inline] pub fn pulses_frames (&self, pulses: f64) -> f64 {
|
||||
|
|
@ -130,3 +130,33 @@ impl Timebase {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(test)] mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_timebase () -> Usually<()> {
|
||||
let timebase = Timebase::new(48000.0, 240.0, 24.0);
|
||||
println!("F/S = {:.03}", s.rate());
|
||||
println!("B/S = {:.03}", s.beats_per_secon());
|
||||
println!("F/B = {:.03}", s.frames_per_beat());
|
||||
println!("T/B = {:.03}", s.ticks_per_beat());
|
||||
println!("F/T = {:.03}", s.frames_per_tick());
|
||||
println!("F/L = {:.03}", s.frames_per_loop());
|
||||
println!("T/L = {:.03}", s.ticks_per_loop());
|
||||
let fpt = s.fpt();
|
||||
let frames_per_chunk = 240;
|
||||
let chunk = |chunk: usize| s.frames_to_ticks(
|
||||
chunk * frames_per_chunk,
|
||||
(chunk + 1) * frames_per_chunk
|
||||
);
|
||||
//for i in 0..2000 {
|
||||
//println!("{i} {:?}", chunk(i));
|
||||
//}
|
||||
assert_eq!(chunk(0), vec![(0, 0), (125, 1)]);
|
||||
assert_eq!(chunk(1), vec![(10, 2), (135, 3)]);
|
||||
assert_eq!(chunk(12), vec![(120, 24)]);
|
||||
assert_eq!(chunk(412), vec![(120, 24)]);
|
||||
assert_eq!(chunk(413), vec![(5, 25), (130, 26)]);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue