Skip to content

Commit

Permalink
feat(closest_pitch): ✨ add respellSimple getter
Browse files Browse the repository at this point in the history
Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>
  • Loading branch information
albertms10 committed Apr 1, 2024
1 parent d2e4f76 commit a673720
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/src/note/closest_pitch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ class ClosestPitch {
cents.ratio,
);

/// Respells this [ClosestPitch] to the simplest expression possible.
///
/// Example:
/// ```dart
/// ClosestPitch.parse('A4+36').respelledSimple.toString() == 'A4+36'
/// ClosestPitch.parse('C#2+16').respelledSimple.toString() == 'D♭2+16'
/// ClosestPitch.parse('Bb3+67').respelledSimple.toString() == 'B3-32'
/// ClosestPitch.parse('F#5-152').respelledSimple.toString() == 'E5+48'
/// ```
ClosestPitch get respelledSimple => frequency().closestPitch();

/// The string representation of this [ClosestPitch] record.
///
/// Example:
Expand Down
18 changes: 18 additions & 0 deletions test/src/note/closest_pitch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ void main() {
});
});

group('.respellSimple', () {
test('respells this ClosestPitch to the simplest expression', () {
expect(ClosestPitch.parse('A4+36').respelledSimple.toString(), 'A4+36');
expect(
ClosestPitch.parse('C#2+16').respelledSimple.toString(),
'D♭2+16',
);
expect(
ClosestPitch.parse('Bb3+68').respelledSimple.toString(),
'B3-32',
);
expect(
ClosestPitch.parse('F#5-152').respelledSimple.toString(),
'E5+48',
);
});
});

group('.toString()', () {
test('returns the string representation of this ClosestPitch', () {
expect(
Expand Down

0 comments on commit a673720

Please sign in to comment.