diff --git a/lib/src/interval/enharmonic_interval.dart b/lib/src/interval/enharmonic_interval.dart index da683514..3340f2a5 100644 --- a/lib/src/interval/enharmonic_interval.dart +++ b/lib/src/interval/enharmonic_interval.dart @@ -3,40 +3,38 @@ part of '../../music_notes.dart'; class EnharmonicInterval extends Enharmonic { const EnharmonicInterval(super.semitones); - static const perfectUnison = EnharmonicInterval(1); - static const minorSecond = EnharmonicInterval(2); - static const majorSecond = EnharmonicInterval(3); - static const minorThird = EnharmonicInterval(4); - static const majorThird = EnharmonicInterval(5); - static const perfectFourth = EnharmonicInterval(6); - static const tritone = EnharmonicInterval(7); - static const perfectFifth = EnharmonicInterval(8); - static const minorSixth = EnharmonicInterval(9); - static const majorSixth = EnharmonicInterval(10); - static const minorSeventh = EnharmonicInterval(11); - static const majorSeventh = EnharmonicInterval(12); + static const perfectUnison = EnharmonicInterval(0); + static const minorSecond = EnharmonicInterval(1); + static const majorSecond = EnharmonicInterval(2); + static const minorThird = EnharmonicInterval(3); + static const majorThird = EnharmonicInterval(4); + static const perfectFourth = EnharmonicInterval(5); + static const tritone = EnharmonicInterval(6); + static const perfectFifth = EnharmonicInterval(7); + static const minorSixth = EnharmonicInterval(8); + static const majorSixth = EnharmonicInterval(9); + static const minorSeventh = EnharmonicInterval(10); + static const majorSeventh = EnharmonicInterval(11); + static const perfectOctave = EnharmonicInterval(12); @override Set get items { - final interval = IntIntervalExtension.fromSemitones(semitones - 1); + final interval = IntIntervalExtension.fromSemitones(semitones); if (interval != null) { - final intervalBelow = interval == 1 ? 1 : interval - 1; - final intervalAbove = interval + 1; - return SplayTreeSet.of({ - Interval.fromSemitones(intervalBelow, semitones - 1), - Interval.fromSemitones(interval, semitones - 1), - Interval.fromSemitones(intervalAbove, semitones - 1), + if (interval > 1) Interval.fromSemitones(interval - 1, semitones), + Interval.fromSemitones(interval, semitones), + Interval.fromSemitones(interval + 1, semitones), }); } - final intervalBelow = IntIntervalExtension.fromSemitones(semitones - 2); - final intervalAbove = IntIntervalExtension.fromSemitones(semitones); + final intervalBelow = IntIntervalExtension.fromSemitones(semitones - 1); + final intervalAbove = IntIntervalExtension.fromSemitones(semitones + 1); return SplayTreeSet.of({ - Interval.fromSemitones(intervalBelow!, semitones - 1), - Interval.fromSemitones(intervalAbove!, semitones - 1), + Interval.fromSemitones(intervalBelow!, semitones), + Interval.fromSemitones(intervalAbove!, semitones), }); } diff --git a/test/src/enharmonic_test.dart b/test/src/enharmonic_test.dart index 56dd931f..9cf618f4 100644 --- a/test/src/enharmonic_test.dart +++ b/test/src/enharmonic_test.dart @@ -9,9 +9,9 @@ void main() { expect(EnharmonicNote.g.toString(), '8 {F𝄪, G, A𝄫}'); expect(EnharmonicNote.dSharp.toString(), '4 {D♯, E♭}'); - expect(EnharmonicInterval.perfectUnison.toString(), '1 {P1, d2}'); - expect(EnharmonicInterval.majorThird.toString(), '5 {M3, d4}'); - expect(EnharmonicInterval.minorSixth.toString(), '9 {A5, m6, dd7}'); + expect(EnharmonicInterval.perfectUnison.toString(), '0 {P1, d2}'); + expect(EnharmonicInterval.majorThird.toString(), '4 {M3, d4}'); + expect(EnharmonicInterval.minorSixth.toString(), '8 {A5, m6, dd7}'); }); }); }); diff --git a/test/src/interval/enharmonic_interval_test.dart b/test/src/interval/enharmonic_interval_test.dart index 6fa2d9b8..c8805c06 100644 --- a/test/src/interval/enharmonic_interval_test.dart +++ b/test/src/interval/enharmonic_interval_test.dart @@ -66,11 +66,16 @@ void main() { const Interval.imperfect(7, ImperfectQuality.major), const Interval.perfect(8, PerfectQuality.diminished), }); - expect(const EnharmonicInterval(13).items, { + expect(EnharmonicInterval.perfectOctave.items, { const Interval.imperfect(7, ImperfectQuality.augmented), const Interval.perfect(8, PerfectQuality.perfect), const Interval.imperfect(9, ImperfectQuality.diminished), }); + expect(const EnharmonicInterval(13).items, { + const Interval.perfect(8, PerfectQuality.augmented), + const Interval.imperfect(9, ImperfectQuality.minor), + const Interval.imperfect(10, ImperfectQuality.doubleDiminished), + }); }, ); }); diff --git a/test/src/interval/interval_test.dart b/test/src/interval/interval_test.dart index 7bf83bcc..c93e7a7c 100644 --- a/test/src/interval/interval_test.dart +++ b/test/src/interval/interval_test.dart @@ -129,26 +129,20 @@ void main() { group('.fromSemitonesQuality()', () { test('should return the correct Interval from semitones and Quality', () { expect( - Interval.fromSemitonesQuality(4), - equals(const Interval.imperfect(3, ImperfectQuality.minor)), + Interval.fromSemitonesQuality(3), + const Interval.imperfect(3, ImperfectQuality.minor), ); expect( - Interval.fromSemitonesQuality(7), - equals(const Interval.perfect(4, PerfectQuality.augmented)), + Interval.fromSemitonesQuality(6), + const Interval.perfect(4, PerfectQuality.augmented), ); expect( - Interval.fromSemitonesQuality( - 7, - PerfectQuality.augmented, - ), - equals(const Interval.perfect(4, PerfectQuality.augmented)), + Interval.fromSemitonesQuality(6, PerfectQuality.augmented), + const Interval.perfect(4, PerfectQuality.augmented), ); expect( - Interval.fromSemitonesQuality( - 7, - PerfectQuality.diminished, - ), - equals(const Interval.perfect(5, PerfectQuality.diminished)), + Interval.fromSemitonesQuality(6, PerfectQuality.diminished), + const Interval.perfect(5, PerfectQuality.diminished), ); }); }); diff --git a/test/src/music_test.dart b/test/src/music_test.dart index 411a5cab..aabe85b7 100644 --- a/test/src/music_test.dart +++ b/test/src/music_test.dart @@ -7,7 +7,7 @@ void main() { test('should return the correct chromatic scale notes', () { expect( chromaticScale, - equals(const [ + const [ EnharmonicNote.c, EnharmonicNote.cSharp, EnharmonicNote.d, @@ -20,7 +20,7 @@ void main() { EnharmonicNote.a, EnharmonicNote.aSharp, EnharmonicNote.b, - ]), + ], ); }); }); diff --git a/test/src/note/note_test.dart b/test/src/note/note_test.dart index bce38e64..a557fc7f 100644 --- a/test/src/note/note_test.dart +++ b/test/src/note/note_test.dart @@ -68,127 +68,113 @@ void main() { test('should return the Interval for a unison', () { expect( Note.c.exactInterval(Note.c), - equals(const Interval.perfect(1, PerfectQuality.perfect)), + const Interval.perfect(1, PerfectQuality.perfect), ); expect( Note.c.exactInterval(Note.cSharp), - equals(const Interval.perfect(1, PerfectQuality.augmented)), + const Interval.perfect(1, PerfectQuality.augmented), ); }); test('should return the Interval for a second', () { expect( Note.c.exactInterval(const Note(Notes.d, Accidental.doubleFlat)), - equals( - const Interval.imperfect(2, ImperfectQuality.diminished), - ), + const Interval.imperfect(2, ImperfectQuality.diminished), ); expect( Note.c.exactInterval(Note.dFlat), - equals(const Interval.imperfect(2, ImperfectQuality.minor)), + const Interval.imperfect(2, ImperfectQuality.minor), ); expect( Note.c.exactInterval(Note.d), - equals(const Interval.imperfect(2, ImperfectQuality.major)), + const Interval.imperfect(2, ImperfectQuality.major), ); expect( Note.c.exactInterval(Note.dSharp), - equals( - const Interval.imperfect(2, ImperfectQuality.augmented), - ), + const Interval.imperfect(2, ImperfectQuality.augmented), ); }); test('should return the Interval for a third', () { expect( Note.c.exactInterval(const Note(Notes.e, Accidental.doubleFlat)), - equals( - const Interval.imperfect(3, ImperfectQuality.diminished), - ), + const Interval.imperfect(3, ImperfectQuality.diminished), ); expect( Note.c.exactInterval(Note.eFlat), - equals(const Interval.imperfect(3, ImperfectQuality.minor)), + const Interval.imperfect(3, ImperfectQuality.minor), ); expect( Note.c.exactInterval(Note.e), - equals(const Interval.imperfect(3, ImperfectQuality.major)), + const Interval.imperfect(3, ImperfectQuality.major), ); expect( Note.c.exactInterval(const Note(Notes.e, Accidental.sharp)), - equals( - const Interval.imperfect(3, ImperfectQuality.augmented), - ), + const Interval.imperfect(3, ImperfectQuality.augmented), ); }); test('should return the Interval for a fourth', () { expect( Note.c.exactInterval(const Note(Notes.f, Accidental.flat)), - equals(const Interval.perfect(4, PerfectQuality.diminished)), + const Interval.perfect(4, PerfectQuality.diminished), ); expect( Note.c.exactInterval(Note.f), - equals(const Interval.perfect(4, PerfectQuality.perfect)), + const Interval.perfect(4, PerfectQuality.perfect), ); expect( Note.c.exactInterval(Note.fSharp), - equals(const Interval.perfect(4, PerfectQuality.augmented)), + const Interval.perfect(4, PerfectQuality.augmented), ); }); test('should return the Interval for a fifth', () { expect( Note.c.exactInterval(Note.gFlat), - equals(const Interval.perfect(5, PerfectQuality.diminished)), + const Interval.perfect(5, PerfectQuality.diminished), ); expect( Note.c.exactInterval(Note.g), - equals(const Interval.perfect(5, PerfectQuality.perfect)), + const Interval.perfect(5, PerfectQuality.perfect), ); expect( Note.c.exactInterval(Note.gSharp), - equals(const Interval.perfect(5, PerfectQuality.augmented)), + const Interval.perfect(5, PerfectQuality.augmented), ); }); test('should return the Interval for a sixth', () { expect( Note.c.exactInterval(const Note(Notes.a, Accidental.doubleFlat)), - equals( - const Interval.imperfect(6, ImperfectQuality.diminished), - ), + const Interval.imperfect(6, ImperfectQuality.diminished), ); expect( Note.c.exactInterval(Note.aFlat), - equals(const Interval.imperfect(6, ImperfectQuality.minor)), + const Interval.imperfect(6, ImperfectQuality.minor), ); expect( Note.c.exactInterval(Note.a), - equals(const Interval.imperfect(6, ImperfectQuality.major)), + const Interval.imperfect(6, ImperfectQuality.major), ); expect( Note.c.exactInterval(Note.aSharp), - equals( - const Interval.imperfect(6, ImperfectQuality.augmented), - ), + const Interval.imperfect(6, ImperfectQuality.augmented), ); }); test('should return the Interval for a seventh', () { expect( Note.c.exactInterval(const Note(Notes.b, Accidental.doubleFlat)), - equals( - const Interval.imperfect(7, ImperfectQuality.diminished), - ), + const Interval.imperfect(7, ImperfectQuality.diminished), ); expect( Note.c.exactInterval(Note.bFlat), - equals(const Interval.imperfect(7, ImperfectQuality.minor)), + const Interval.imperfect(7, ImperfectQuality.minor), ); expect( Note.c.exactInterval(Note.b), - equals(const Interval.imperfect(7, ImperfectQuality.major)), + const Interval.imperfect(7, ImperfectQuality.major), ); // TODO(albertms10): add test case for: // `Note.c.exactInterval(const Note(Notes.b, Accidental.sharp))`.