Skip to content

Commit

Permalink
Fix for unison intervals on edge cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
twitchax committed Jan 16, 2023
1 parent bbbb47b commit 7838efa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ impl Add<Interval> for Note {
};

// There is a "special wrap" for `Cb`, and `Dbbb`, since they don't technically loop; and, for B#, etc., on the other side.
let special_octave = if new_pitch == NamedPitch::CFlat || new_pitch == NamedPitch::DTripleFlat {
// Basically, if we were already "on" the weird one (this is a perfect unision, or perfect octave, etc.), then we don't
// do anything special. Otherwise, if we landed on on of these edge cases, then we need to adjust the octave.
let special_octave = if (self.named_pitch != NamedPitch::CFlat && new_pitch == NamedPitch::CFlat) || (self.named_pitch != NamedPitch::DTripleFlat && new_pitch == NamedPitch::DTripleFlat) {
1
} else if new_pitch == NamedPitch::BSharp || new_pitch == NamedPitch::BDoubleSharp || new_pitch == NamedPitch::BTripleSharp || new_pitch == NamedPitch::ATripleSharp {
} else if (self.named_pitch != NamedPitch::BSharp && new_pitch == NamedPitch::BSharp) || (self.named_pitch != NamedPitch::BDoubleSharp && new_pitch == NamedPitch::BDoubleSharp) || (self.named_pitch != NamedPitch::BTripleSharp && new_pitch == NamedPitch::BTripleSharp) || (self.named_pitch != NamedPitch::ATripleSharp && new_pitch == NamedPitch::ATripleSharp) {
-1
} else {
0
Expand Down Expand Up @@ -468,6 +470,14 @@ mod tests {
assert_eq!(BFlatThree + Interval::MinorNinth, CFlatFive);
assert_eq!(A + Interval::AugmentedNinth, BSharpFive);
assert_eq!(CSharp + Interval::AugmentedSeventh, BDoubleSharp);

assert_eq!(DTripleFlat + Interval::PerfectOctave, DTripleFlatFive);
assert_eq!(DTripleFlat + Interval::PerfectUnison, DTripleFlat);

assert_eq!(BSharp + Interval::PerfectOctave, BSharpFive);
assert_eq!(BSharp + Interval::PerfectUnison, BSharp);

assert_eq!(ATripleSharp + Interval::TwoPerfectOctaves, ATripleSharpSix);
}

#[test]
Expand Down

0 comments on commit 7838efa

Please sign in to comment.