Class: HeadMusic::Sonority
- Inherits:
-
Object
- Object
- HeadMusic::Sonority
- Defined in:
- lib/head_music/sonority.rb
Overview
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.
Constant Summary collapse
- SONORITIES =
{ major_triad: %w[M3 P5], minor_triad: %w[m3 P5], diminished_triad: %w[m3 d5], augmented_triad: %w[M3 A5], major_minor_seventh_chord: %w[M3 P5 m7], major_major_seventh_chord: %w[M3 P5 M7], minor_minor_seventh_chord: %w[m3 P5 m7], minor_major_seventh_chord: %w[m3 P5 M7], half_diminished_seventh_chord: %w[m3 d5 m7], diminished_seventh_chord: %w[m3 d5 d7], dominant_ninth_chord: %w[M2 M3 P5 m7], dominant_minor_ninth_chord: %w[m2 M3 P5 m7], minor_ninth_chord: %w[M2 m3 P5 m7], major_ninth_chord: %w[M2 M3 P5 M7], six_nine_chord: %w[M2 M3 P5 M6], minor_six_nine_chord: %w[M2 m3 P5 M6], suspended_four_chord: %w[P4 P5], suspended_two_chord: %w[M2 P5], quartal_chord: %w[P4 m7] }.freeze
Instance Attribute Summary collapse
-
#pitch_set ⇒ Object
readonly
Returns the value of attribute pitch_set.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #consonant? ⇒ Boolean
- #diatonic_intervals_above_bass_pitch ⇒ Object
- #identifier ⇒ Object
-
#initialize(pitch_set) ⇒ Sonority
constructor
A new instance of Sonority.
- #inversion ⇒ Object
- #inversions ⇒ Object
- #quartal? ⇒ Boolean (also: #quintal?)
- #root_position ⇒ Object
- #secundal? ⇒ Boolean
- #seventh_chord? ⇒ Boolean
- #tertian? ⇒ Boolean
- #triad? ⇒ Boolean
Constructor Details
#initialize(pitch_set) ⇒ Sonority
Returns a new instance of Sonority.
36 37 38 39 |
# File 'lib/head_music/sonority.rb', line 36 def initialize(pitch_set) @pitch_set = pitch_set identifier end |
Instance Attribute Details
#pitch_set ⇒ Object (readonly)
Returns the value of attribute pitch_set.
27 28 29 |
# File 'lib/head_music/sonority.rb', line 27 def pitch_set @pitch_set end |
Instance Method Details
#==(other) ⇒ Object
116 117 118 119 120 |
# File 'lib/head_music/sonority.rb', line 116 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? ⇒ Boolean
73 74 75 76 77 |
# File 'lib/head_music/sonority.rb', line 73 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 ⇒ Object
109 110 111 112 113 114 |
# File 'lib/head_music/sonority.rb', line 109 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 ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/head_music/sonority.rb', line 41 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 ⇒ Object
51 52 53 54 55 |
# File 'lib/head_music/sonority.rb', line 51 def inversion @inversion ||= inversions.index do |inversion| SONORITIES[identifier] == inversion.diatonic_intervals_above_bass_pitch.map(&:shorthand) end end |
#inversions ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/head_music/sonority.rb', line 57 def inversions @inversions ||= begin inversion = reduction inversions = [] inversion.pitches.length.times do |_i| inversions << inversion inversion = inversion.uninvert end inversions end end |
#quartal? ⇒ Boolean Also known as: quintal?
100 101 102 103 104 105 106 |
# File 'lib/head_music/sonority.rb', line 100 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 |
#root_position ⇒ Object
69 70 71 |
# File 'lib/head_music/sonority.rb', line 69 def root_position @root_position ||= inversions[inversion] end |
#secundal? ⇒ Boolean
94 95 96 97 98 |
# File 'lib/head_music/sonority.rb', line 94 def secundal? @secundal ||= inversions.detect do |inversion| inversion.diatonic_intervals.count(&:second?).to_f / inversion.diatonic_intervals.length > 0.5 end end |
#seventh_chord? ⇒ Boolean
83 84 85 |
# File 'lib/head_music/sonority.rb', line 83 def seventh_chord? @seventh_chord ||= tetrachord? && tertian? end |
#tertian? ⇒ Boolean
87 88 89 90 91 92 |
# File 'lib/head_music/sonority.rb', line 87 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? ⇒ Boolean
79 80 81 |
# File 'lib/head_music/sonority.rb', line 79 def triad? @triad ||= trichord? && tertian? end |