-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mode)!: rewrite
Mode
enums (#78)
- Loading branch information
1 parent
f149838
commit aa4574e
Showing
11 changed files
with
152 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
part of '../../music_notes.dart'; | ||
|
||
abstract class Mode implements Enum, Comparable<Mode> { | ||
Scale get scale; | ||
int get brightness; | ||
|
||
static int compareModes(Mode a, Mode b) => compareMultiple([ | ||
() => a.brightness.compareTo(b.brightness), | ||
() => a.name.compareTo(b.name), | ||
]); | ||
} | ||
|
||
enum TonalMode implements Mode { | ||
major(Scale.major, brightness: 0), | ||
minor(Scale.naturalMinor, brightness: -3); | ||
|
||
@override | ||
final Scale scale; | ||
|
||
@override | ||
final int brightness; | ||
|
||
const TonalMode(this.scale, {required this.brightness}); | ||
|
||
/// Returns the inverted of this [TonalMode]. | ||
/// | ||
/// Example: | ||
/// ```dart | ||
/// TonalMode.major.inverted == TonalMode.minor | ||
/// TonalMode.minor.inverted == TonalMode.major | ||
/// ``` | ||
TonalMode get opposite => | ||
this == TonalMode.major ? TonalMode.minor : TonalMode.major; | ||
|
||
@override | ||
int compareTo(Mode other) => Mode.compareModes(this, other); | ||
} | ||
|
||
enum ModalMode implements Mode { | ||
lydian(Scale.lydian, brightness: 1), | ||
ionian(Scale.ionian, brightness: 0), | ||
mixolydian(Scale.mixolydian, brightness: -1), | ||
dorian(Scale.dorian, brightness: -2), | ||
aeolian(Scale.aeolian, brightness: -3), | ||
phrygian(Scale.phrygian, brightness: -4), | ||
locrian(Scale.locrian, brightness: -5); | ||
|
||
@override | ||
final Scale scale; | ||
|
||
@override | ||
final int brightness; | ||
|
||
const ModalMode(this.scale, {required this.brightness}); | ||
|
||
@override | ||
int compareTo(Mode other) => Mode.compareModes(this, other); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'dart:collection' show SplayTreeSet; | ||
|
||
import 'package:music_notes/music_notes.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('TonalMode', () { | ||
group('.opposite', () { | ||
test('should return the correct opposite mode', () { | ||
expect(TonalMode.major.opposite, TonalMode.minor); | ||
expect(TonalMode.minor.opposite, TonalMode.major); | ||
}); | ||
}); | ||
|
||
group('.compareTo', () { | ||
test('should correctly sort Mode items in a collection', () { | ||
final orderedSet = SplayTreeSet<Mode>.of(const [ | ||
TonalMode.minor, | ||
ModalMode.phrygian, | ||
ModalMode.ionian, | ||
TonalMode.major, | ||
ModalMode.aeolian, | ||
ModalMode.lydian, | ||
]); | ||
expect(orderedSet.toList(), const [ | ||
ModalMode.phrygian, | ||
ModalMode.aeolian, | ||
TonalMode.minor, | ||
ModalMode.ionian, | ||
TonalMode.major, | ||
ModalMode.lydian, | ||
]); | ||
}); | ||
}); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters