Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(interval): ✨ make perfect constructor default to PerfectQuality.perfect #435

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Create an `Interval`:

```dart
Interval.P4; // P4
const Interval.perfect(Size.twelfth, PerfectQuality.perfect); // P12
const Interval.imperfect(Size.tenth, ImperfectQuality.major); // M10
```

Or turn it descending:
Expand Down
2 changes: 1 addition & 1 deletion example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void main() {

// Intervals
Interval.P4; // P4
const Interval.perfect(Size.twelfth, PerfectQuality.perfect); // P12
const Interval.imperfect(Size.tenth, ImperfectQuality.major); // M10

-Interval.m6; // m-6
Interval.M3.descending(); // M-3
Expand Down
19 changes: 11 additions & 8 deletions lib/src/interval/interval.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class Interval
static const d1 = Interval.perfect(Size.unison, PerfectQuality.diminished);

/// A perfect unison [Interval].
static const P1 = Interval.perfect(Size.unison, PerfectQuality.perfect);
static const P1 = Interval.perfect(Size.unison);

/// An augmented unison [Interval].
static const A1 = Interval.perfect(Size.unison, PerfectQuality.augmented);
Expand Down Expand Up @@ -70,7 +70,7 @@ final class Interval
static const d4 = Interval.perfect(Size.fourth, PerfectQuality.diminished);

/// A perfect fourth [Interval].
static const P4 = Interval.perfect(Size.fourth, PerfectQuality.perfect);
static const P4 = Interval.perfect(Size.fourth);

/// An augmented fourth [Interval].
static const A4 = Interval.perfect(Size.fourth, PerfectQuality.augmented);
Expand All @@ -79,7 +79,7 @@ final class Interval
static const d5 = Interval.perfect(Size.fifth, PerfectQuality.diminished);

/// A perfect fifth [Interval].
static const P5 = Interval.perfect(Size.fifth, PerfectQuality.perfect);
static const P5 = Interval.perfect(Size.fifth);

/// An augmented fifth [Interval].
static const A5 = Interval.perfect(Size.fifth, PerfectQuality.augmented);
Expand Down Expand Up @@ -114,7 +114,7 @@ final class Interval
static const d8 = Interval.perfect(Size.octave, PerfectQuality.diminished);

/// A perfect octave [Interval].
static const P8 = Interval.perfect(Size.octave, PerfectQuality.perfect);
static const P8 = Interval.perfect(Size.octave);

/// An augmented octave [Interval].
static const A8 = Interval.perfect(Size.octave, PerfectQuality.augmented);
Expand All @@ -135,7 +135,7 @@ final class Interval
static const d11 = Interval.perfect(Size.eleventh, PerfectQuality.diminished);

/// A perfect eleventh [Interval].
static const P11 = Interval.perfect(Size.eleventh, PerfectQuality.perfect);
static const P11 = Interval.perfect(Size.eleventh);

/// An augmented eleventh [Interval].
static const A11 = Interval.perfect(Size.eleventh, PerfectQuality.augmented);
Expand All @@ -159,9 +159,12 @@ final class Interval
static final _regExp = RegExp(r'(\w+?)(-?\d+)');

/// Creates a new [Interval] allowing only perfect quality [size]s.
const Interval.perfect(this.size, PerfectQuality this.quality)
// Copied from [Size.isPerfect] to allow const.
: assert(
const Interval.perfect(
this.size, [
PerfectQuality this.quality = PerfectQuality.perfect,
])
// Copied from [Size.isPerfect] to allow const.
: assert(
((size < 0 ? 0 - size : size) + (size < 0 ? 0 - size : size) ~/ 8) %
4 <
2,
Expand Down
52 changes: 10 additions & 42 deletions test/src/interval/interval_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ void main() {
expect(Interval.parse('A5'), Interval.A5);
expect(Interval.parse('A-1'), -Interval.A1);
expect(Interval.parse('P1'), Interval.P1);
expect(
Interval.parse('P22'),
const Interval.perfect(Size(22), PerfectQuality.perfect),
);
expect(Interval.parse('P22'), const Interval.perfect(Size(22)));
expect(Interval.parse('d5'), Interval.d5);
expect(Interval.parse('d-5'), -Interval.d5);
expect(
Expand Down Expand Up @@ -195,20 +192,9 @@ void main() {
expect(Interval.m13.semitones, 20);
expect((-Interval.M13).semitones, -21);

expect(
const Interval.perfect(Size(15), PerfectQuality.perfect).semitones,
24,
);

expect(
const Interval.perfect(Size(22), PerfectQuality.perfect).semitones,
36,
);

expect(
const Interval.perfect(Size(29), PerfectQuality.perfect).semitones,
48,
);
expect(const Interval.perfect(Size(15)).semitones, 24);
expect(const Interval.perfect(Size(22)).semitones, 36);
expect(const Interval.perfect(Size(29)).semitones, 48);
});
});

Expand Down Expand Up @@ -302,14 +288,8 @@ void main() {

group('.simple', () {
test('returns the simplified version of this Interval', () {
expect(
const Interval.perfect(Size(-22), PerfectQuality.perfect).simple,
-Interval.P8,
);
expect(
const Interval.perfect(Size(-15), PerfectQuality.perfect).simple,
-Interval.P8,
);
expect(const Interval.perfect(Size(-22)).simple, -Interval.P8);
expect(const Interval.perfect(Size(-15)).simple, -Interval.P8);
expect((-Interval.M13).simple, -Interval.M6);
expect((-Interval.P11).simple, -Interval.P4);
expect((-Interval.m9).simple, -Interval.m2);
Expand All @@ -324,14 +304,8 @@ void main() {
expect(Interval.m9.simple, Interval.m2);
expect(Interval.P11.simple, Interval.P4);
expect(Interval.M13.simple, Interval.M6);
expect(
const Interval.perfect(Size(15), PerfectQuality.perfect).simple,
Interval.P8,
);
expect(
const Interval.perfect(Size(22), PerfectQuality.perfect).simple,
Interval.P8,
);
expect(const Interval.perfect(Size(15)).simple, Interval.P8);
expect(const Interval.perfect(Size(22)).simple, Interval.P8);
});
});

Expand Down Expand Up @@ -684,19 +658,13 @@ void main() {
.toString(),
'M-14 (M-7)',
);
expect(
const Interval.perfect(Size(15), PerfectQuality.perfect).toString(),
'P15 (P8)',
);
expect(const Interval.perfect(Size(15)).toString(), 'P15 (P8)');
expect(
const Interval.imperfect(Size(-16), ImperfectQuality.diminished)
.toString(),
'd-16 (d-2)',
);
expect(
const Interval.perfect(Size(22), PerfectQuality.perfect).toString(),
'P22 (P8)',
);
expect(const Interval.perfect(Size(22)).toString(), 'P22 (P8)');

expect(
const Interval.perfect(Size.fifth, PerfectQuality(-4)).toString(),
Expand Down
23 changes: 3 additions & 20 deletions test/src/note/note_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -610,26 +610,9 @@ void main() {
expect(Note.c.transposeBy(Interval.m13), Note.a.flat);
expect(Note.c.transposeBy(Interval.M13), Note.a);

expect(
Note.c.transposeBy(
const Interval.perfect(Size(15), PerfectQuality.perfect),
),
Note.c,
);

expect(
Note.c.transposeBy(
const Interval.perfect(Size(22), PerfectQuality.perfect),
),
Note.c,
);

expect(
Note.c.transposeBy(
const Interval.perfect(Size(29), PerfectQuality.perfect),
),
Note.c,
);
expect(Note.c.transposeBy(const Interval.perfect(Size(15))), Note.c);
expect(Note.c.transposeBy(const Interval.perfect(Size(22))), Note.c);
expect(Note.c.transposeBy(const Interval.perfect(Size(29))), Note.c);
});
});

Expand Down
20 changes: 7 additions & 13 deletions test/src/note/pitch_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -610,23 +610,23 @@ void main() {
expect(Note.c.inOctave(3).interval(Note.c.inOctave(4)), Interval.P8);
expect(
Note.c.inOctave(3).interval(Note.c.inOctave(5)),
const Interval.perfect(Size(15), PerfectQuality.perfect),
const Interval.perfect(Size(15)),
);

expect(
Note.c.inOctave(3).interval(Note.c.inOctave(6)),
const Interval.perfect(Size(22), PerfectQuality.perfect),
const Interval.perfect(Size(22)),
);

expect(
Note.c.inOctave(2).interval(Note.c.inOctave(6)),
const Interval.perfect(Size(29), PerfectQuality.perfect),
const Interval.perfect(Size(29)),
);

expect(
skip: true,
() => Note.c.inOctave(4).interval(Note.b.sharp.inOctave(3)),
const Interval.perfect(Size(29), PerfectQuality.perfect),
const Interval.perfect(Size(29)),
);
});
});
Expand Down Expand Up @@ -884,23 +884,17 @@ void main() {
);

expect(
Note.c.inOctave(4).transposeBy(
const Interval.perfect(Size(15), PerfectQuality.perfect),
),
Note.c.inOctave(4).transposeBy(const Interval.perfect(Size(15))),
Note.c.inOctave(6),
);

expect(
Note.c.inOctave(4).transposeBy(
const Interval.perfect(Size(22), PerfectQuality.perfect),
),
Note.c.inOctave(4).transposeBy(const Interval.perfect(Size(22))),
Note.c.inOctave(7),
);

expect(
Note.c.inOctave(4).transposeBy(
const Interval.perfect(Size(29), PerfectQuality.perfect),
),
Note.c.inOctave(4).transposeBy(const Interval.perfect(Size(29))),
Note.c.inOctave(8),
);
});
Expand Down