From b7e0fa06ca5454314f1341a63148001f497ff018 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sat, 27 Aug 2022 15:38:23 +0800 Subject: some new songs and small modifications --- src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 5fa7e79..23fffe2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -245,6 +245,19 @@ impl Default for Hertz { } } +impl Semitones { + /// Return the octave of the semitone. + fn octave(self) -> (usize, usize) { + let translated = *self + 9f64; + + let quotient = translated.div_euclid(12f64) as i64; + + let rem = translated.rem_euclid(12f64) as usize; + + ((quotient + 4) as usize, rem) + } +} + impl From for Hertz { fn from(st: Semitones) -> Self { (*Self::default() * STD_BASE.powf(*st)).into() -- cgit v1.2.3-18-g5258