Class: HeadMusic::Content::Voice::MelodicNotePair

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(first_note, second_note) ⇒ MelodicNotePair

Returns a new instance of MelodicNotePair.



180
181
182
183
# File 'lib/head_music/content/voice.rb', line 180

def initialize(first_note, second_note)
  @first_note = first_note
  @second_note = second_note
end

Instance Attribute Details

#first_noteObject (readonly)

Returns the value of attribute first_note.



169
170
171
# File 'lib/head_music/content/voice.rb', line 169

def first_note
  @first_note
end

#second_noteObject (readonly)

Returns the value of attribute second_note.



169
170
171
# File 'lib/head_music/content/voice.rb', line 169

def second_note
  @second_note
end

Instance Method Details

#melodic_intervalObject



193
194
195
# File 'lib/head_music/content/voice.rb', line 193

def melodic_interval
  @melodic_interval ||= HeadMusic::Analysis::MelodicInterval.new(*notes)
end

#notesObject



185
186
187
# File 'lib/head_music/content/voice.rb', line 185

def notes
  @notes ||= [first_note, second_note]
end

#pitchesObject



189
190
191
# File 'lib/head_music/content/voice.rb', line 189

def pitches
  @pitches ||= notes.map(&:pitch)
end

#spells_consonant_triad_with?(other_note_pair) ⇒ Boolean

Returns:

  • (Boolean)


197
198
199
200
201
202
203
204
# File 'lib/head_music/content/voice.rb', line 197

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