Class: HeadMusic::Analysis::HarmonicInterval
- Inherits:
-
Object
- Object
- HeadMusic::Analysis::HarmonicInterval
show all
- Defined in:
- lib/head_music/analysis/harmonic_interval.rb
Overview
A harmonic interval is the diatonic interval between two notes sounding together.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(voice1, voice2, position) ⇒ HarmonicInterval
Returns a new instance of HarmonicInterval.
8
9
10
11
12
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 8
def initialize(voice1, voice2, position)
@voice1 = voice1
@voice2 = voice2
@position = position.is_a?(String) ? HeadMusic::Content::Position.new(voice1.composition, position) : position
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
60
61
62
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 60
def method_missing(method_name, *args, &block)
respond_to_missing?(method_name) ? diatonic_interval.send(method_name, *args, &block) : super
end
|
Instance Attribute Details
#position ⇒ Object
Returns the value of attribute position.
6
7
8
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 6
def position
@position
end
|
#voice1 ⇒ Object
Returns the value of attribute voice1.
6
7
8
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 6
def voice1
@voice1
end
|
#voice2 ⇒ Object
Returns the value of attribute voice2.
6
7
8
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 6
def voice2
@voice2
end
|
Instance Method Details
#diatonic_interval ⇒ Object
14
15
16
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 14
def diatonic_interval
@diatonic_interval ||= HeadMusic::Analysis::DiatonicInterval.new(lower_pitch, upper_pitch)
end
|
#lower_note ⇒ Object
26
27
28
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 26
def lower_note
notes.first
end
|
#lower_pitch ⇒ Object
38
39
40
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 38
def lower_pitch
pitches.first
end
|
#notes ⇒ Object
22
23
24
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 22
def notes
@notes ||= voices.map { |voice| voice.note_at(position) }.compact.sort_by(&:pitch)
end
|
#pitch_orientation ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 46
def pitch_orientation
return if lower_pitch == upper_pitch
if lower_note.voice == voice1
:up
elsif lower_note.voice == voice2
:down
end
end
|
#pitches ⇒ Object
34
35
36
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 34
def pitches
@pitches ||= notes.map(&:pitch).sort_by(&:to_i)
end
|
#respond_to_missing?(method_name, *_args) ⇒ Boolean
64
65
66
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 64
def respond_to_missing?(method_name, *_args)
diatonic_interval.respond_to?(method_name)
end
|
#to_s ⇒ Object
56
57
58
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 56
def to_s
"#{diatonic_interval} at #{position}"
end
|
#upper_note ⇒ Object
30
31
32
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 30
def upper_note
notes.last
end
|
#upper_pitch ⇒ Object
42
43
44
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 42
def upper_pitch
pitches.last
end
|
#voices ⇒ Object
18
19
20
|
# File 'lib/head_music/analysis/harmonic_interval.rb', line 18
def voices
[voice1, voice2].compact
end
|