Skip to content

Commit

Permalink
✨ feat(note): add respelledSimple getter (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Jun 19, 2023
1 parent 142b232 commit 7a38f86
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/src/note/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ final class Note implements Comparable<Note>, Scalable<Note> {
return Note(baseNote, accidental);
}

/// Returns this [Note] with the simplest [Accidental] spelling while keeping
/// the same number of [semitones].
///
/// Example:
/// ```dart
/// Note.e.sharp.respelledSimple == Note.f
/// Note.d.flat.flat.respelledSimple == Note.c
/// Note.f.sharp.sharp.sharp.respelledSimple == Note.g.sharp
/// ```
Note get respelledSimple =>
respellByAccidental(Accidental.natural) ??
respellByAccidental(Accidental(accidental.semitones.sign))!;

/// Returns this [Note] positioned in the given [octave] as [PositionedNote].
///
/// Example:
Expand Down
17 changes: 17 additions & 0 deletions test/src/note/note_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,23 @@ void main() {
});
});

group('.respelledSimple', () {
test(
'should return this Note with the simplest Accidental spelling',
() {
expect(Note.c.respelledSimple, Note.c);
expect(Note.b.respelledSimple, Note.b);
expect(Note.d.flat.respelledSimple, Note.d.flat);
expect(Note.c.sharp.respelledSimple, Note.c.sharp);
expect(Note.e.sharp.respelledSimple, Note.f);
expect(Note.c.flat.respelledSimple, Note.b);
expect(Note.g.sharp.sharp.respelledSimple, Note.a);
expect(Note.a.flat.flat.flat.respelledSimple, Note.g.flat);
expect(Note.f.sharp.sharp.sharp.respelledSimple, Note.g.sharp);
},
);
});

group('.circleOfFifthsDistance', () {
test('should return the circle of fifths distance of this Note', () {
expect(Note.f.flat.circleOfFifthsDistance, -8);
Expand Down

0 comments on commit 7a38f86

Please sign in to comment.