fix(domain): remove dead use_sharps param, handle Cb enharmonic
This commit is contained in:
@@ -14,7 +14,7 @@ impl Note {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_semitone(s: u8, use_sharps: bool) -> Note {
|
||||
pub fn from_semitone(s: u8) -> Note {
|
||||
match s % 12 {
|
||||
0 => Note::C, 1 => Note::CSharpDFlat, 2 => Note::D,
|
||||
3 => Note::DSharpEFlat, 4 => Note::E, 5 => Note::F,
|
||||
@@ -66,12 +66,11 @@ impl Note {
|
||||
}
|
||||
|
||||
fn sharp_of(root: Note) -> Note {
|
||||
Note::from_semitone((root.semitone() + 1) % 12, true)
|
||||
Note::from_semitone((root.semitone() + 1) % 12)
|
||||
}
|
||||
|
||||
fn flat_of(root: Note) -> Option<Note> {
|
||||
if root.semitone() == 0 { return None; } // Cb is unusual, skip
|
||||
Some(Note::from_semitone((root.semitone() + 11) % 12, false))
|
||||
Some(Note::from_semitone((root.semitone() + 11) % 12))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,8 +80,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn semitone_roundtrip() {
|
||||
assert_eq!(Note::from_semitone(Note::A.semitone(), true), Note::A);
|
||||
assert_eq!(Note::from_semitone(Note::FSharpGFlat.semitone(), true), Note::FSharpGFlat);
|
||||
assert_eq!(Note::from_semitone(Note::A.semitone()), Note::A);
|
||||
assert_eq!(Note::from_semitone(Note::FSharpGFlat.semitone()), Note::FSharpGFlat);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_cb_enharmonic() {
|
||||
assert_eq!(Note::from_str("Cb"), Some(Note::B));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user