Skip to content

Commit

Permalink
feat(size): ✨ add isDissonant getter moved from Interval
Browse files Browse the repository at this point in the history
  • Loading branch information
albertms10 committed Mar 10, 2024
1 parent ac5051a commit 68cd9a3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/src/interval/interval.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ final class Interval
ImperfectQuality(:final semitones) =>
semitones.isNegative && semitones > 1,
} ||
const {Size.second, Size.seventh}.contains(simple.size.abs());
size.isDissonant;

/// This [Interval] respelled by [size] while keeping the same number of
/// [semitones].
Expand Down
57 changes: 34 additions & 23 deletions lib/src/interval/size.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,6 @@ extension type const Size._(int size) implements int {
? Interval.perfect(this, PerfectQuality.augmented)
: Interval.imperfect(this, ImperfectQuality.augmented);

/// Whether this [Size] conforms a perfect interval.
///
/// Example:
/// ```dart
/// Size.fifth.isPerfect == true
/// Size.sixth.isPerfect == false
/// (-Size.eleventh).isPerfect == true
/// ```
bool get isPerfect => absShift % (octave / 2) < 2;

/// Whether this [Size] is greater than [Size.octave].
///
/// Example:
/// ```dart
/// Size.fifth.isCompound == false
/// (-Size.sixth).isCompound == false
/// Size.octave.isCompound == false
/// Size.ninth.isCompound == true
/// (-Size.eleventh).isCompound == true
/// Size.thirteenth.isCompound == true
/// ```
bool get isCompound => abs() > octave;

static int _inverted(Size size) {
final diff = 9 - size.simple.size.abs();

Expand Down Expand Up @@ -211,6 +188,40 @@ extension type const Size._(int size) implements int {
/// ```
Size get simple => Size(_simple(this));

/// Whether this [Size] conforms a perfect interval.
///
/// Example:
/// ```dart
/// Size.fifth.isPerfect == true
/// Size.sixth.isPerfect == false
/// (-Size.eleventh).isPerfect == true
/// ```
bool get isPerfect => absShift % (octave / 2) < 2;

/// Whether this [Size] is greater than [Size.octave].
///
/// Example:
/// ```dart
/// Size.fifth.isCompound == false
/// (-Size.sixth).isCompound == false
/// Size.octave.isCompound == false
/// Size.ninth.isCompound == true
/// (-Size.eleventh).isCompound == true
/// Size.thirteenth.isCompound == true
/// ```
bool get isCompound => abs() > octave;

/// Whether this [Size] is dissonant.
///
/// Example:
/// ```dart
/// Size.unison.isDissonant == false
/// Size.fifth.isDissonant == false
/// Size.seventh.isDissonant == true
/// (-Size.ninth).isDissonant == true
/// ```
bool get isDissonant => const {second, seventh}.contains(simple.size.abs());

/// This [Size] formatted as a string.
String format({IntervalNotation system = IntervalNotation.standard}) =>
system.size(this);
Expand Down

0 comments on commit 68cd9a3

Please sign in to comment.