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

feat(note): ✨ add isEnharmonicWith method #291

Merged
merged 1 commit into from
Oct 13, 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
10 changes: 10 additions & 0 deletions lib/src/note/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ final class Note implements Comparable<Note>, Scalable<Note> {
respellByAccidental(Accidental.natural) ??
respellByAccidental(Accidental(accidental.semitones.sign))!;

/// Whether this [Note] is enharmonically equivalent to [other].
///
/// Example:
/// ```dart
/// Note.g.sharp.isEnharmonicWith(Note.a.flat) == true
/// Note.c.isEnharmonicWith(Note.b.sharp) == true
/// Note.e.isEnharmonicWith(Note.f) == false
/// ```
bool isEnharmonicWith(Note other) => toPitchClass() == other.toPitchClass();

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

group('.isEnharmonicWith()', () {
test(
'should return whether this Note is enharmonically equivalent to other',
() {
expect(Note.c.sharp.isEnharmonicWith(Note.d.flat), isTrue);
expect(Note.b.isEnharmonicWith(Note.c.flat), isTrue);
expect(Note.b.sharp.isEnharmonicWith(Note.c), isTrue);
expect(Note.e.isEnharmonicWith(Note.f.flat), isTrue);
expect(Note.e.sharp.isEnharmonicWith(Note.f), isTrue);
expect(Note.e.sharp.sharp.isEnharmonicWith(Note.g.flat), isTrue);
expect(Note.a.flat.flat.isEnharmonicWith(Note.f.sharp.sharp), isTrue);

expect(Note.c.isEnharmonicWith(Note.b), isFalse);
expect(Note.f.isEnharmonicWith(Note.g), isFalse);
expect(Note.a.isEnharmonicWith(Note.d.sharp), isFalse);
},
);
});

group('.circleOfFifths()', () {
test(
'should return the circle of fifths starting from this Note',
Expand Down