Class: HeadMusic::Content::Voice::MelodicNotePair
- Inherits:
-
Object
- Object
- HeadMusic::Content::Voice::MelodicNotePair
- Defined in:
- lib/head_music/content/voice.rb
Overview
A pair of consecutive notes in a melodic line, used to analyze intervals and leaps.
Instance Attribute Summary collapse
-
#first_note ⇒ Object
readonly
Returns the value of attribute first_note.
-
#second_note ⇒ Object
readonly
Returns the value of attribute second_note.
Instance Method Summary collapse
-
#initialize(first_note, second_note) ⇒ MelodicNotePair
constructor
A new instance of MelodicNotePair.
-
#melodic_interval ⇒ Object
-
#notes ⇒ Object
-
#pitches ⇒ Object
-
#spells_consonant_triad_with?(other_note_pair) ⇒ Boolean
Constructor Details
#initialize(first_note, second_note) ⇒ MelodicNotePair
Returns a new instance of MelodicNotePair.
151 152 153 154 |
# File 'lib/head_music/content/voice.rb', line 151 def initialize(first_note, second_note) @first_note = first_note @second_note = second_note end |
Instance Attribute Details
#first_note ⇒ Object (readonly)
Returns the value of attribute first_note.
140 141 142 |
# File 'lib/head_music/content/voice.rb', line 140 def first_note @first_note end |
#second_note ⇒ Object (readonly)
Returns the value of attribute second_note.
140 141 142 |
# File 'lib/head_music/content/voice.rb', line 140 def second_note @second_note end |
Instance Method Details
#melodic_interval ⇒ Object
164 165 166 |
# File 'lib/head_music/content/voice.rb', line 164 def melodic_interval @melodic_interval ||= HeadMusic::Analysis::MelodicInterval.new(*notes) end |
#notes ⇒ Object
156 157 158 |
# File 'lib/head_music/content/voice.rb', line 156 def notes @notes ||= [first_note, second_note] end |
#pitches ⇒ Object
160 161 162 |
# File 'lib/head_music/content/voice.rb', line 160 def pitches @pitches ||= notes.map(&:pitch) end |
#spells_consonant_triad_with?(other_note_pair) ⇒ Boolean
168 169 170 171 172 173 174 175 |
# File 'lib/head_music/content/voice.rb', line 168 def spells_consonant_triad_with?(other_note_pair) return false if step? || other_note_pair.step? combined_pitches = (pitches + other_note_pair.pitches).uniq return false if combined_pitches.length < 3 HeadMusic::Analysis::PitchCollection.new(combined_pitches).consonant_triad? end |