class HeadMusic::Sonority

A Sonority describes a set of pitch class intervalic relationships. For example, a minor triad, or a major-minor seventh chord. The Sonority class is a factory for returning one of its subclasses.

Constants

SONORITIES

Attributes

pitch_set[R]

Public Class Methods

new(pitch_set) click to toggle source
# File lib/head_music/sonority.rb, line 38
def initialize(pitch_set)
  @pitch_set = pitch_set
  identifier
end

Public Instance Methods

==(other) click to toggle source
# File lib/head_music/sonority.rb, line 118
def ==(other)
  other = HeadMusic::PitchSet.new(other) if other.is_a?(Array)
  other = self.class.new(other) if other.is_a?(HeadMusic::PitchSet)
  identifier == other.identifier
end
consonant?() click to toggle source
# File lib/head_music/sonority.rb, line 75
def consonant?
  @consonant ||=
    pitch_set.reduction_diatonic_intervals.all?(&:consonant?) &&
    root_position.diatonic_intervals_above_bass_pitch.all?(&:consonant?)
end
diatonic_intervals_above_bass_pitch() click to toggle source
# File lib/head_music/sonority.rb, line 111
def diatonic_intervals_above_bass_pitch
  return nil unless identifier

  @diatonic_intervals_above_bass_pitch ||=
    SONORITIES[identifier].map { |shorthand| HeadMusic::DiatonicInterval.get(shorthand) }
end
identifier() click to toggle source
# File lib/head_music/sonority.rb, line 43
def identifier
  return @identifier if defined?(@identifier)

  @identifier = SONORITIES.keys.detect do |key|
    inversions.map do |inversion|
      inversion.diatonic_intervals_above_bass_pitch.map(&:shorthand)
    end.include?(SONORITIES[key])
  end
end
inversion() click to toggle source
# File lib/head_music/sonority.rb, line 53
def inversion
  @inversion ||= inversions.index do |inversion|
    SONORITIES[identifier] == inversion.diatonic_intervals_above_bass_pitch.map(&:shorthand)
  end
end
inversions() click to toggle source
# File lib/head_music/sonority.rb, line 59
def inversions
  @inversions ||= begin
    inversion = reduction
    inversions = []
    inversion.pitches.length.times do |_i|
      inversions << inversion
      inversion = inversion.uninvert
    end
    inversions
  end
end
quartal?() click to toggle source
# File lib/head_music/sonority.rb, line 102
def quartal?
  @quartal ||= inversions.detect do |inversion|
    inversion.diatonic_intervals.count do |interval|
      interval.fourth? || interval.fifth?
    end.to_f / inversion.diatonic_intervals.length > 0.5
  end
end
Also aliased as: quintal?
quintal?()
Alias for: quartal?
root_position() click to toggle source
# File lib/head_music/sonority.rb, line 71
def root_position
  @root_position ||= inversions[inversion]
end
secundal?() click to toggle source
# File lib/head_music/sonority.rb, line 96
def secundal?
  @secundal ||= inversions.detect do |inversion|
    inversion.diatonic_intervals.count(&:second?).to_f / inversion.diatonic_intervals.length > 0.5
  end
end
seventh_chord?() click to toggle source
# File lib/head_music/sonority.rb, line 85
def seventh_chord?
  @seventh_chord ||= tetrachord? && tertian?
end
tertian?() click to toggle source
# File lib/head_music/sonority.rb, line 89
def tertian?
  @tertian ||= inversions.detect do |inversion|
    inversion.diatonic_intervals.count(&:third?).to_f / inversion.diatonic_intervals.length > 0.5 ||
      (scale_degrees_above_bass_pitch && [3, 5, 7]).length == 3
  end
end
triad?() click to toggle source
# File lib/head_music/sonority.rb, line 81
def triad?
  @triad ||= trichord? && tertian?
end