Class: HeadMusic::HarmonicInterval
- Inherits:
-
Object
- Object
- HeadMusic::HarmonicInterval
show all
- Defined in:
- lib/head_music/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.
5
6
7
8
9
|
# File 'lib/head_music/harmonic_interval.rb', line 5
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
57
58
59
|
# File 'lib/head_music/harmonic_interval.rb', line 57
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.
3
4
5
|
# File 'lib/head_music/harmonic_interval.rb', line 3
def position
@position
end
|
#voice1 ⇒ Object
Returns the value of attribute voice1.
3
4
5
|
# File 'lib/head_music/harmonic_interval.rb', line 3
def voice1
@voice1
end
|
#voice2 ⇒ Object
Returns the value of attribute voice2.
3
4
5
|
# File 'lib/head_music/harmonic_interval.rb', line 3
def voice2
@voice2
end
|
Instance Method Details
#diatonic_interval ⇒ Object
11
12
13
|
# File 'lib/head_music/harmonic_interval.rb', line 11
def diatonic_interval
@diatonic_interval ||= HeadMusic::DiatonicInterval.new(lower_pitch, upper_pitch)
end
|
#lower_note ⇒ Object
23
24
25
|
# File 'lib/head_music/harmonic_interval.rb', line 23
def lower_note
notes.first
end
|
#lower_pitch ⇒ Object
35
36
37
|
# File 'lib/head_music/harmonic_interval.rb', line 35
def lower_pitch
pitches.first
end
|
#notes ⇒ Object
19
20
21
|
# File 'lib/head_music/harmonic_interval.rb', line 19
def notes
@notes ||= voices.map { |voice| voice.note_at(position) }.compact.sort_by(&:pitch)
end
|
#pitch_orientation ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/head_music/harmonic_interval.rb', line 43
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
31
32
33
|
# File 'lib/head_music/harmonic_interval.rb', line 31
def pitches
@pitches ||= notes.map(&:pitch).sort_by(&:to_i)
end
|
#respond_to_missing?(method_name, *_args) ⇒ Boolean
61
62
63
|
# File 'lib/head_music/harmonic_interval.rb', line 61
def respond_to_missing?(method_name, *_args)
diatonic_interval.respond_to?(method_name)
end
|
#to_s ⇒ Object
53
54
55
|
# File 'lib/head_music/harmonic_interval.rb', line 53
def to_s
"#{diatonic_interval} at #{position}"
end
|
#upper_note ⇒ Object
27
28
29
|
# File 'lib/head_music/harmonic_interval.rb', line 27
def upper_note
notes.last
end
|
#upper_pitch ⇒ Object
39
40
41
|
# File 'lib/head_music/harmonic_interval.rb', line 39
def upper_pitch
pitches.last
end
|
#voices ⇒ Object
15
16
17
|
# File 'lib/head_music/harmonic_interval.rb', line 15
def voices
[voice1, voice2].compact
end
|