-
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.
refactor(accidental): rewrite new
Accidental
class (#8)
* refactor(accidental): rewrite new `Accidental` class * test(accidental): add test cases for `Accidental` * docs(tonality): fix typo * docs(accidental): reformat Markdown list
- Loading branch information
1 parent
86067fb
commit 202f0b2
Showing
11 changed files
with
155 additions
and
166 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
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
part of '../../music_notes.dart'; | ||
|
||
/// An accidental. | ||
class Accidental { | ||
/// The value representing this [Accidental]: | ||
/// | ||
/// - `> 0` for sharps. | ||
/// - `== 0` for natural. | ||
/// - `< 0` for flats. | ||
final int value; | ||
|
||
/// Creates a new [Accidental] from a [value]. | ||
const Accidental(this.value); | ||
|
||
static const Accidental tripleSharp = Accidental(3); | ||
static const Accidental doubleSharp = Accidental(2); | ||
static const Accidental sharp = Accidental(1); | ||
static const Accidental natural = Accidental(0); | ||
static const Accidental flat = Accidental(-1); | ||
static const Accidental doubleFlat = Accidental(-2); | ||
static const Accidental tripleFlat = Accidental(-3); | ||
|
||
static const String doubleSharpSymbol = '𝄪'; | ||
static const String sharpSymbol = '♯'; | ||
static const String naturalSymbol = '♮'; | ||
static const String flatSymbol = '♭'; | ||
static const String doubleFlatSymbol = '𝄫'; | ||
|
||
/// Returns the symbol of this [Accidental]. | ||
/// | ||
/// Examples: | ||
/// ```dart | ||
/// assert(Accidental.flat.symbol == '♭') | ||
/// assert(Accidental.doubleSharp.symbol == '𝄪') | ||
/// ``` | ||
String get symbol { | ||
if (value == 0) return naturalSymbol; | ||
|
||
return (value.isOdd ? (value.isNegative ? flatSymbol : sharpSymbol) : '') + | ||
(value.isNegative ? doubleFlatSymbol : doubleSharpSymbol) * | ||
(value.abs() ~/ 2); | ||
} | ||
|
||
@override | ||
bool operator ==(Object other) => other is Accidental && value == other.value; | ||
|
||
@override | ||
int get hashCode => value.hashCode; | ||
} |
Oops, something went wrong.