Skip to content

Commit

Permalink
Merge 74f80f5 into fdb6b2e
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Apr 22, 2023
2 parents fdb6b2e + 74f80f5 commit 661f657
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"cSpell.ignoreWords": ["music"]
"cSpell.ignoreWords": ["music"],
"cSpell.words": ["helmholtz"]
}
36 changes: 36 additions & 0 deletions lib/src/note/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,42 @@ class Note implements MusicItem {
);
}

/// Returns the string representation of this [Note] following the
/// [scientific pitch notation](https://en.wikipedia.org/wiki/Scientific_pitch_notation).
///
/// Example:
/// ```dart
/// Note.c.scientificName == 'C4'
/// Note.a.inOctave(3).scientificName == 'A3'
/// Note.bFlat.inOctave(1).scientificName == 'B♭1'
/// ```
String get scientificName {
return '${note.name.toUpperCase()}'
'${accidental != Accidental.natural ? accidental.symbol : ''}'
'$octave';
}

/// Returns the string representation of this [Note] following
/// [Helmholtz’s pitch notation](https://en.wikipedia.org/wiki/Helmholtz_pitch_notation).
///
/// Example:
/// ```dart
/// Note.c.helmholtzName == 'c′'
/// Note.a.inOctave(3).helmholtzName == 'a'
/// Note.bFlat.inOctave(1).helmholtzName == 'B♭͵'
/// ```
String get helmholtzName {
if (octave >= 3) {
return '${note.name}'
'${accidental != Accidental.natural ? accidental.symbol : ''}'
'${'′' * (octave - 3)}';
}

return '${note.name.toUpperCase()}'
'${accidental != Accidental.natural ? accidental.symbol : ''}'
'${'͵' * (octave - 2).abs()}';
}

@override
String toString() =>
note.name.toUpperCase() +
Expand Down
36 changes: 36 additions & 0 deletions test/src/note/note_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,42 @@ void main() {
});
});

group('.scientificName', () {
test(
'should return the scientific pitch notation name for this Note',
() {
expect(Note.gSharp.inOctave(-1).scientificName, 'G♯-1');
expect(Note.d.inOctave(0).scientificName, 'D0');
expect(Note.bFlat.inOctave(1).scientificName, 'B♭1');
expect(Note.g.inOctave(2).scientificName, 'G2');
expect(Note.a.inOctave(3).scientificName, 'A3');
expect(Note.c.scientificName, 'C4');
expect(Note.cSharp.scientificName, 'C♯4');
expect(Note.a.scientificName, 'A4');
expect(Note.fSharp.inOctave(5).scientificName, 'F♯5');
expect(Note.e.inOctave(7).scientificName, 'E7');
},
);
});

group('.helmholtzName', () {
test(
'should return the Helmholtz pitch notation name for this Note',
() {
expect(Note.gSharp.inOctave(-1).helmholtzName, 'G♯͵͵͵');
expect(Note.d.inOctave(0).helmholtzName, 'D͵͵');
expect(Note.bFlat.inOctave(1).helmholtzName, 'B♭͵');
expect(Note.g.inOctave(2).helmholtzName, 'G');
expect(Note.a.inOctave(3).helmholtzName, 'a');
expect(Note.c.helmholtzName, 'c′');
expect(Note.cSharp.helmholtzName, 'c♯′');
expect(Note.a.helmholtzName, 'a′');
expect(Note.fSharp.inOctave(5).helmholtzName, 'f♯′′');
expect(Note.e.inOctave(7).helmholtzName, 'e′′′′');
},
);
});

group('.toString()', () {
test('should return the string representation of this Note', () {
expect(Note.c.toString(), 'C');
Expand Down

0 comments on commit 661f657

Please sign in to comment.