Skip to content

Commit

Permalink
fix(note): add fromRawAccidentals method
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Nov 23, 2020
1 parent fc72689 commit 5c2f663
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
37 changes: 27 additions & 10 deletions lib/src/classes/note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,7 @@ class Note implements MusicItem {
/// ```
static Note fromTonalityAccidentals(int accidentals, Modes mode,
[Accidentals accidental]) {
final Note note = Note.fromSemitones(
Interval(
Intervals.Quinta,
Qualities.Justa,
descending: accidental == Accidentals.Bemoll,
).semitones *
accidentals +
1,
accidental,
);
final note = fromRawAccidentals(accidentals, accidental);

return mode == Modes.Major
? note
Expand All @@ -44,6 +35,32 @@ class Note implements MusicItem {
);
}

/// Returns the [Note] from the [Tonality] given its [accidentals] number
/// and optional [accidental].
///
/// Examples:
/// ```dart
/// Note.fromRawAccidentals(2, Accidentals.Sostingut)
/// == const Note(Notes.Re)
///
/// Note.fromRawAccidentals(0)
/// == const Note(Notes.La)
/// ```
static Note fromRawAccidentals(int accidentals, [Accidentals accidental]) =>
Note.fromSemitones(
Interval(
Intervals.Quinta,
Qualities.Justa,
descending: accidental == Accidentals.Bemoll,
).semitones *
accidentals +
1,
(accidental == Accidentals.Bemoll && accidentals > 8) ||
(accidental == Accidentals.Sostingut && accidentals > 10)
? accidental.incremented
: accidental,
);

/// Returns the number of semitones that correspond to this [Note] from [Notes.Do].
///
/// Examples:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/classes/tonality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Tonality {
/// == Accidentals.Bemoll
/// ```
Accidentals get accidental => CircleOfFifths.exactFifthsDistance(
Tonality.fromAccidentals(0, Modes.Major).note,
Tonality.fromAccidentals(0, mode).note,
note,
) >
0
Expand Down

0 comments on commit 5c2f663

Please sign in to comment.