Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Albert Mañosa <albertmasa2@gmail.com>
  • Loading branch information
plammens and albertms10 committed May 13, 2023
1 parent 4409f23 commit 2a42a7d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
9 changes: 5 additions & 4 deletions lib/src/note/frequency.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
part of '../../music_notes.dart';

/// Represents an absolute pitch, a physical frequency.
@immutable
class Frequency {
Frequency(this.hertz);
const Frequency(this.hertz);

final double hertz;

/// Whether this [Frequency] is inside the human hearing range.
///
/// Example:
/// ```dart
/// Note.a.inOctave(4).isHumanAudibleAt() == true
/// Note.d.inOctave(0).isHumanAudibleAt() == false
/// Note.g.inOctave(12).isHumanAudibleAt(442) == false
/// const Frequency(880).isHumanAudible == true
/// Note.a.inOctave(4).equalTemperamentFrequency().isHumanAudible == true
/// Note.g.inOctave(12).equalTemperamentFrequency(442).isHumanAudible == false
/// ```
bool get isHumanAudible {
const minFrequency = 20;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/note/positioned_note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ final class PositionedNote extends Note {
/// Note.a.inOctave(4).equalTemperamentFrequency(338) == 338
/// Note.bFlat.inOctave(4).equalTemperamentFrequency(338) == 464.04
/// ```
Frequency equalTemperamentFrequency([double a4Hertzs = 440]) => Frequency(
a4Hertzs * math.pow(sqrt12_2, Note.a.inOctave(4).difference(this)),
Frequency equalTemperamentFrequency([double a4Hertz = 440]) => Frequency(
a4Hertz * math.pow(sqrt12_2, Note.a.inOctave(4).difference(this)),
);

/// Returns the string representation of this [Note] following the
Expand Down
2 changes: 2 additions & 0 deletions test/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'interval/quality_test.dart' as quality_test;
import 'music_test.dart' as music_test;
import 'note/accidental_test.dart' as accidental_test;
import 'note/enharmonic_note_test.dart' as enharmonic_note_test;
import 'note/frequency_test.dart' as frequency_test;
import 'note/note_test.dart' as note_test;
import 'note/notes_test.dart' as notes_test;
import 'note/positioned_note_test.dart' as positioned_note_test;
Expand All @@ -24,6 +25,7 @@ void main() {
music_test.main();
accidental_test.main();
enharmonic_note_test.main();
frequency_test.main();
note_test.main();
notes_test.main();
positioned_note_test.main();
Expand Down
16 changes: 9 additions & 7 deletions test/src/note/frequency_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import 'package:music_notes/music_notes.dart';
import 'package:test/test.dart';

void main() {
group('.isHumanAudible', () {
test('should return whether the frequency is audible by humans', () {
expect(Frequency(0).isHumanAudible, isFalse);
expect(Frequency(100).isHumanAudible, isTrue);
expect(Frequency(400).isHumanAudible, isTrue);
expect(Frequency(15000).isHumanAudible, isTrue);
expect(Frequency(100000).isHumanAudible, isFalse);
group('Frequency', () {
group('.isHumanAudible', () {
test('should return whether the frequency is audible by humans', () {
expect(const Frequency(0).isHumanAudible, isFalse);
expect(const Frequency(100).isHumanAudible, isTrue);
expect(const Frequency(400).isHumanAudible, isTrue);
expect(const Frequency(15000).isHumanAudible, isTrue);
expect(const Frequency(100000).isHumanAudible, isFalse);
});
});
});
}

0 comments on commit 2a42a7d

Please sign in to comment.