Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(note): simplify fromRawAccidentals accidental increment #49

Merged
merged 2 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lib/src/note/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ class Note implements MusicItem {

return EnharmonicNote(
(fifthInterval.semitones * accidentals + 1).chromaticModExcludeZero,
).toClosestNote(
(accidental == Accidental.flat && accidentals > 8) ||
(accidental == Accidental.sharp && accidentals > 10)
? Accidental(accidental.semitones + 1)
: accidental,
);
).toClosestNote(accidental.increment(accidentals ~/ 9));
}

/// Returns the number of semitones that correspond to this [Note]
Expand Down
8 changes: 2 additions & 6 deletions test/src/tonality/key_signature_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ void main() {
group('.tonalities', () {
test('should return the Set of tonalities for this KeySignature', () {
expect(const KeySignature(10, Accidental.flat).tonalities, {
// TODO(albertms10): Failing test:
// Should be Note(Notes.e, Accidental.doubleFlat).
const Tonality(Note.d, Modes.major),
const Tonality(Note(Notes.e, Accidental.doubleFlat), Modes.major),
const Tonality(Note(Notes.c, Accidental.flat), Modes.minor),
});
expect(const KeySignature(9, Accidental.flat).tonalities, {
// TODO(albertms10): Failing test:
// Should be Note(Notes.b, Accidental.doubleFlat).
const Tonality(Note.a, Modes.major),
const Tonality(Note(Notes.b, Accidental.doubleFlat), Modes.major),
const Tonality(Note.gFlat, Modes.minor),
});
expect(const KeySignature(8, Accidental.flat).tonalities, {
Expand Down