euphony-units 0.1.1

Core types and traits for music composition
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use crate::{ratio::Ratio, time::beat::Beat};

#[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Ord, Eq)]
pub struct UnquantizedBeat(pub u64, pub Beat);

impl UnquantizedBeat {
    pub fn quantize(self, min: Beat) -> Beat {
        let count = self.1.as_ratio() / min.as_ratio();
        let count = count.whole() + u64::from(count.fraction() > Ratio(1, 2));
        Beat(self.0, 1) + min * count
    }
}