use crate::{SCOPE, TONIC, FillsNotary};
use std::collections::HashMap;
#[derive(Default)]
pub struct NaturalMusicBox {
tonic: f64,
pub notary: HashMap<String, f64>,
}
impl NaturalMusicBox {
pub fn new() -> Self {
let mut music = Self {
tonic: TONIC,
notary: HashMap::new(),
};
music.fill_notes();
music
}
}
impl FillsNotary for NaturalMusicBox {
fn fill_notes(&mut self) {
for i in 1..SCOPE {
let harmonic_series: f64 = ((i as f64) + 1.0) / (i as f64);
let overtone = self.tonic * harmonic_series;
self.notary
.insert(format!("{}/{}", i, i + 1), overtone.to_owned());
}
}
fn fill_inverse_notes(&mut self) {
for i in 1..SCOPE {
let harmonic_series: f64 = ((i as f64) + 1.0) / (i as f64);
let overtone = self.tonic / harmonic_series;
self.notary
.insert(format!("{}/{}", i, i + 1), overtone.to_owned());
}
}
}