Skip to content

Commit

Permalink
feat!(closest_pitch): 💥 remove hertz member (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Jan 3, 2024
1 parent bb0d75e commit da79645
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 36 deletions.
14 changes: 4 additions & 10 deletions lib/src/note/closest_pitch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ class ClosestPitch {
/// The difference in cents.
final Cent cents;

/// The difference in hertz.
final double hertz;

/// Creates a new [ClosestPitch] from [pitch], [cents] and [hertz].
const ClosestPitch(this.pitch, {this.cents = const Cent(0), this.hertz = 0});
/// Creates a new [ClosestPitch] from [pitch] and [cents].
const ClosestPitch(this.pitch, {this.cents = const Cent(0)});

/// Returns the string representation of this [ClosestPitch] record.
///
Expand All @@ -34,11 +31,8 @@ class ClosestPitch {

@override
bool operator ==(Object other) =>
other is ClosestPitch &&
pitch == other.pitch &&
cents == other.cents &&
hertz == other.hertz;
other is ClosestPitch && pitch == other.pitch && cents == other.cents;

@override
int get hashCode => Object.hash(pitch, cents, hertz);
int get hashCode => Object.hash(pitch, cents);
}
5 changes: 2 additions & 3 deletions lib/src/note/frequency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class Frequency implements Comparable<Frequency> {
/// Example:
/// ```dart
/// const Frequency(467).closestPitch()
/// == ClosestPitch(Note.a.sharp.inOctave(4), cents: Cent(3.1), hertz: 0.84)
/// == ClosestPitch(Note.a.sharp.inOctave(4), cents: Cent(3.1))
///
/// const Frequency(260).closestPitch()
/// == ClosestPitch(Note.c.inOctave(4), cents: Cent(-10.79), hertz: -1.63)
/// == ClosestPitch(Note.c.inOctave(4), cents: Cent(-10.79))
/// ```
///
/// This method and [Pitch.frequency] are inverses of each other for a
Expand Down Expand Up @@ -83,7 +83,6 @@ class Frequency implements Comparable<Frequency> {
return ClosestPitch(
isCloserToUpwardsSpelling ? closestPitch.respelledUpwards : closestPitch,
cents: Ratio(hertz / closestPitchFrequency.hertz).cents,
hertz: hertzDelta,
);
}

Expand Down
23 changes: 5 additions & 18 deletions test/src/note/closest_pitch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,8 @@ void main() {
ClosestPitch(Note.a.inOctave(4)),
);
expect(
ClosestPitch(
Note.c.sharp.inOctave(3),
cents: const Cent(-2.123),
hertz: -2.021,
),
ClosestPitch(
Note.c.sharp.inOctave(3),
cents: const Cent(-2.123),
hertz: -2.021,
),
ClosestPitch(Note.c.sharp.inOctave(3), cents: const Cent(-2.123)),
ClosestPitch(Note.c.sharp.inOctave(3), cents: const Cent(-2.123)),
);
});

Expand All @@ -55,17 +47,12 @@ void main() {
isNot(equals(ClosestPitch(Note.g.inOctave(4)))),
);
expect(
ClosestPitch(
Note.c.sharp.inOctave(3),
cents: const Cent(-2.123),
hertz: -2.021,
),
ClosestPitch(Note.c.sharp.inOctave(3), cents: const Cent(-2.123)),
isNot(
equals(
ClosestPitch(
Note.c.sharp.inOctave(3),
cents: const Cent(-0.345),
hertz: -4.989,
),
),
),
Expand All @@ -77,13 +64,13 @@ void main() {
final collection = {
ClosestPitch(Note.a.inOctave(4)),
ClosestPitch(Note.b.flat.inOctave(3)),
ClosestPitch(Note.c.inOctave(3), cents: const Cent(2), hertz: 2),
ClosestPitch(Note.c.inOctave(3), cents: const Cent(2)),
};
collection.addAll(collection);
expect(collection.toList(), [
ClosestPitch(Note.a.inOctave(4)),
ClosestPitch(Note.b.flat.inOctave(3)),
ClosestPitch(Note.c.inOctave(3), cents: const Cent(2), hertz: 2),
ClosestPitch(Note.c.inOctave(3), cents: const Cent(2)),
]);
});
});
Expand Down
5 changes: 0 additions & 5 deletions test/src/note/frequency_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,20 @@ void main() {
ClosestPitch(
Note.a.sharp.inOctave(4),
cents: const Cent(-41.96437412632116),
hertz: -11.163761518089927,
),
);
expect(
const Frequency(467).closestPitch(),
ClosestPitch(
Note.b.flat.inOctave(4),
cents: const Cent(3.1028314220028586),
hertz: 0.8362384819100726,
),
);
expect(
const Frequency(256).closestPitch(),
ClosestPitch(
Note.c.inOctave(4),
cents: const Cent(-37.63165622959142),
hertz: -5.625565300598623,
),
);

Expand All @@ -58,7 +55,6 @@ void main() {
ClosestPitch(
Note.b.flat.inOctave(4),
cents: const Cent(1.270624748447127),
hertz: 0.32281584089247417,
),
);
expect(
Expand All @@ -78,7 +74,6 @@ void main() {
ClosestPitch(
Note.a.inOctave(4),
cents: const Cent(37.63165622959145),
hertz: 9.461035390098175,
),
);
});
Expand Down

0 comments on commit da79645

Please sign in to comment.