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): ✨ rename toPitchClass and create Pitch.toClass methods #385

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: 5 additions & 5 deletions lib/src/note/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ final class Note extends Scalable<Note> implements Comparable<Note> {
/// Note.c.isEnharmonicWith(Note.b.sharp) == true
/// Note.e.isEnharmonicWith(Note.f) == false
/// ```
bool isEnharmonicWith(Note other) => toClass() == other.toClass();
bool isEnharmonicWith(Note other) => toPitchClass() == other.toPitchClass();

/// Returns this [Note] positioned in the given [octave] as a [Pitch].
///
Expand Down Expand Up @@ -402,11 +402,11 @@ final class Note extends Scalable<Note> implements Comparable<Note> {
///
/// Example:
/// ```dart
/// Note.c.toClass() == PitchClass.c
/// Note.e.sharp.toClass() == PitchClass.f
/// Note.c.flat.flat.toClass() == PitchClass.aSharp
/// Note.c.toPitchClass() == PitchClass.c
/// Note.e.sharp.toPitchClass() == PitchClass.f
/// Note.c.flat.flat.toPitchClass() == PitchClass.aSharp
/// ```
PitchClass toClass() => PitchClass(semitones);
PitchClass toPitchClass() => PitchClass(semitones);

@override
String toString({NoteNotation system = NoteNotation.english}) =>
Expand Down
10 changes: 10 additions & 0 deletions lib/src/note/pitch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ final class Pitch extends Scalable<Pitch> implements Comparable<Pitch> {
int _semitonesWithoutAccidental(int semitones, Note referenceNote) =>
semitones - referenceNote.accidental.semitones;

/// Creates a new [PitchClass] from [semitones].
///
/// Example:
/// ```dart
/// Note.c.inOctave(4).toClass() == PitchClass.c
/// Note.e.sharp.inOctave(2).toClass() == PitchClass.f
/// Note.c.flat.flat.inOctave(5).toClass() == PitchClass.aSharp
/// ```
PitchClass toClass() => PitchClass(semitones);

/// Transposes this [Pitch] by [interval].
///
/// Example:
Expand Down
12 changes: 6 additions & 6 deletions test/src/note/note_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -630,13 +630,13 @@ void main() {
});
});

group('.toClass()', () {
group('.toPitchClass()', () {
test('creates a new PitchClass from semitones', () {
expect(Note.c.toClass(), PitchClass.c);
expect(Note.d.sharp.toClass(), PitchClass.dSharp);
expect(Note.e.flat.toClass(), PitchClass.dSharp);
expect(Note.e.sharp.toClass(), PitchClass.f);
expect(Note.c.flat.flat.toClass(), PitchClass.aSharp);
expect(Note.c.toPitchClass(), PitchClass.c);
expect(Note.d.sharp.toPitchClass(), PitchClass.dSharp);
expect(Note.e.flat.toPitchClass(), PitchClass.dSharp);
expect(Note.e.sharp.toPitchClass(), PitchClass.f);
expect(Note.c.flat.flat.toPitchClass(), PitchClass.aSharp);
});
});

Expand Down
10 changes: 10 additions & 0 deletions test/src/note/pitch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,16 @@ void main() {
});
});

group('.toClass()', () {
test('creates a new PitchClass from semitones', () {
expect(Note.c.inOctave(4).toClass(), PitchClass.c);
expect(Note.d.sharp.inOctave(3).toClass(), PitchClass.dSharp);
expect(Note.e.flat.inOctave(-1).toClass(), PitchClass.dSharp);
expect(Note.e.sharp.inOctave(6).toClass(), PitchClass.f);
expect(Note.c.flat.flat.inOctave(5).toClass(), PitchClass.aSharp);
});
});

group('.interval()', () {
test('returns the Interval between this Pitch and other', () {
expect(Note.c.inOctave(4).interval(Note.c.inOctave(4)), Interval.P1);
Expand Down