Skip to content

Commit

Permalink
refactor(equal_temperament): ♻️ revert chaning fork to an optional …
Browse files Browse the repository at this point in the history
…positional constructor argument

Signed-off-by: Albert Mañosa <26429103+albertms10@users.noreply.github.com>
  • Loading branch information
albertms10 committed Mar 31, 2024
1 parent a1d1d90 commit a535496
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ And use it in a `TuningSystem`:

```dart
Note.b.flat.inOctave(4).frequency(
tuningSystem: const EqualTemperament.edo12(TuningFork.c256),
tuningSystem: const EqualTemperament.edo12(fork: TuningFork.c256),
); // 456.1401436878537
```

Expand Down
2 changes: 1 addition & 1 deletion example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void main() {
TuningFork.c256; // C256

Note.b.flat.inOctave(4).frequency(
tuningSystem: const EqualTemperament.edo12(TuningFork.c256),
tuningSystem: const EqualTemperament.edo12(fork: TuningFork.c256),
); // 456.1401436878537

const Frequency(432).closestPitch(); // A4-32
Expand Down
4 changes: 2 additions & 2 deletions lib/src/note/pitch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,12 @@ final class Pitch extends Scalable<Pitch> implements Comparable<Pitch> {
///
/// Note.b.flat.inOctave(4).frequency(
/// tuningSystem: EqualTemperament.edo12(
/// Pitch.reference.at(const Frequency(438)),
/// fork: Pitch.reference.at(const Frequency(438)),
/// ),
/// ) == const Frequency(464.04)
///
/// Note.a.inOctave(4).frequency(
/// tuningSystem: const EqualTemperament.edo12(TuningFork.c256),
/// tuningSystem: const EqualTemperament.edo12(fork: TuningFork.c256),
/// ) == const Frequency(430.54)
///
/// Note.a.inOctave(4).frequency(temperature: const Celsius(18))
Expand Down
10 changes: 4 additions & 6 deletions lib/src/tuning/equal_temperament.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ class EqualTemperament extends TuningSystem {
const EqualTemperament(this._steps, {super.fork = TuningFork.a440});

/// See [12 equal temperament](https://en.wikipedia.org/wiki/12_equal_temperament).
const EqualTemperament.edo12([TuningFork fork = TuningFork.a440])
: _steps = const [2, 2, 1, 2, 2, 2, 1],
super(fork: fork);
const EqualTemperament.edo12({super.fork = TuningFork.a440})
: _steps = const [2, 2, 1, 2, 2, 2, 1];

/// See [19 equal temperament](https://en.wikipedia.org/wiki/19_equal_temperament).
const EqualTemperament.edo19([TuningFork fork = TuningFork.a440])
: _steps = const [3, 3, 2, 3, 3, 3, 2],
super(fork: fork);
const EqualTemperament.edo19({super.fork = TuningFork.a440})
: _steps = const [3, 3, 2, 3, 3, 3, 2];

/// The equal divisions of the octave of this [EqualTemperament].
///
Expand Down
6 changes: 3 additions & 3 deletions test/src/note/frequency_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ void main() {

expect(
const Frequency(440).closestPitch(
tuningSystem: const EqualTemperament.edo12(TuningFork.a415),
tuningSystem: const EqualTemperament.edo12(fork: TuningFork.a415),
),
Note.b.flat.inOctave(4) + const Cent(1.270624748447127),
);
expect(
const Frequency(512).closestPitch(
tuningSystem: EqualTemperament.edo12(
Note.c.inOctave(5).at(const Frequency(512)),
fork: Note.c.inOctave(5).at(const Frequency(512)),
),
),
Note.c.inOctave(5) + const Cent(0),
);
expect(
const Frequency(440).closestPitch(
tuningSystem: EqualTemperament.edo12(
Note.c.inOctave(5).at(const Frequency(512)),
fork: Note.c.inOctave(5).at(const Frequency(512)),
),
),
Note.a.inOctave(4) + const Cent(37.63165622959145),
Expand Down
9 changes: 5 additions & 4 deletions test/src/note/pitch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ void main() {

test('returns the Frequency of this Pitch at 438 Hz', () {
const tuningSystem = EqualTemperament.edo12(
TuningFork(Pitch.reference, Frequency(438)),
fork: TuningFork(Pitch.reference, Frequency(438)),
);
expect(
Note.c.inOctave(4).frequency(tuningSystem: tuningSystem),
Expand Down Expand Up @@ -1122,7 +1122,7 @@ void main() {
});

test('returns the Frequency of this Pitch from 256 Hz (C4)', () {
const tuningSystem = EqualTemperament.edo12(TuningFork.c256);
const tuningSystem = EqualTemperament.edo12(fork: TuningFork.c256);
expect(
Note.c.inOctave(4).frequency(tuningSystem: tuningSystem),
const Frequency(256),
Expand All @@ -1148,7 +1148,7 @@ void main() {
.harmonics(
upToIndex: 15,
tuningSystem: const EqualTemperament.edo12(
TuningFork(Pitch.reference, Frequency(438)),
fork: TuningFork(Pitch.reference, Frequency(438)),
),
)
.toString(),
Expand All @@ -1161,7 +1161,8 @@ void main() {
.inOctave(1)
.harmonics(
upToIndex: 15,
tuningSystem: const EqualTemperament.edo12(TuningFork.c256),
tuningSystem:
const EqualTemperament.edo12(fork: TuningFork.c256),
)
.toString(),
'{C1, C2, G2+2, C3, E3-14, G3+2, A♯3-31, C4, D4+4, '
Expand Down
2 changes: 1 addition & 1 deletion test/src/tuning/equal_temperament_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void main() {
'EDO 19 (3 3 2 3 3 3 2) at A440',
);
expect(
const EqualTemperament.edo19(TuningFork.c256).toString(),
const EqualTemperament.edo19(fork: TuningFork.c256).toString(),
'EDO 19 (3 3 2 3 3 3 2) at C256',
);
});
Expand Down

0 comments on commit a535496

Please sign in to comment.