class HeadMusic::HarmonicInterval
A harmonic interval is the diatonic interval between two notes sounding together.
Attributes
position[R]
voice1[R]
voice2[R]
Public Class Methods
new(voice1, voice2, position)
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 7 def initialize(voice1, voice2, position) @voice1 = voice1 @voice2 = voice2 @position = position.is_a?(String) ? HeadMusic::Position.new(voice1.composition, position) : position end
Public Instance Methods
diatonic_interval()
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 13 def diatonic_interval @diatonic_interval ||= HeadMusic::DiatonicInterval.new(lower_pitch, upper_pitch) end
lower_note()
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 25 def lower_note notes.first end
lower_pitch()
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 37 def lower_pitch pitches.first end
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/head_music/harmonic_interval.rb, line 59 def method_missing(method_name, *args, &block) respond_to_missing?(method_name) ? diatonic_interval.send(method_name, *args, &block) : super end
notes()
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 21 def notes @notes ||= voices.map { |voice| voice.note_at(position) }.compact.sort_by(&:pitch) end
pitch_orientation()
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 45 def pitch_orientation return if lower_pitch == upper_pitch if lower_note.voice == voice1 :up elsif lower_note.voice == voice2 :down end end
pitches()
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 33 def pitches @pitches ||= notes.map(&:pitch).sort_by(&:to_i) end
respond_to_missing?(method_name, *_args)
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 63 def respond_to_missing?(method_name, *_args) diatonic_interval.respond_to?(method_name) end
to_s()
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 55 def to_s "#{diatonic_interval} at #{position}" end
upper_note()
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 29 def upper_note notes.last end
upper_pitch()
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 41 def upper_pitch pitches.last end
voices()
click to toggle source
# File lib/head_music/harmonic_interval.rb, line 17 def voices [voice1, voice2].compact end