summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs13
1 files changed, 13 insertions, 0 deletions
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<Semitones> for Hertz {
fn from(st: Semitones) -> Self {
(*Self::default() * STD_BASE.powf(*st)).into()