Class: HeadMusic::Analysis::MelodicInterval
- Inherits:
-
Object
- Object
- HeadMusic::Analysis::MelodicInterval
show all
- Defined in:
- lib/head_music/analysis/melodic_interval.rb
Overview
A melodic interval is the distance between one note and the next.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of MelodicInterval.
8
9
10
11
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 8
def initialize(note1, note2)
@first_note = note1
@second_note = note2
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
93
94
95
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 93
def method_missing(method_name, *args, &block)
respond_to_missing?(method_name) ? diatonic_interval.send(method_name, *args, &block) : super
end
|
Instance Attribute Details
#first_note ⇒ Object
Returns the value of attribute first_note.
6
7
8
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 6
def first_note
@first_note
end
|
#second_note ⇒ Object
Returns the value of attribute second_note.
6
7
8
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 6
def second_note
@second_note
end
|
Instance Method Details
#ascending? ⇒ Boolean
45
46
47
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 45
def ascending?
direction == :ascending
end
|
#descending? ⇒ Boolean
49
50
51
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 49
def descending?
direction == :descending
end
|
#diatonic_interval ⇒ Object
13
14
15
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 13
def diatonic_interval
@diatonic_interval ||= HeadMusic::Analysis::DiatonicInterval.new(first_pitch, second_pitch)
end
|
#direction ⇒ Object
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 73
def direction
@direction ||=
if first_pitch < second_pitch
:ascending
elsif first_pitch > second_pitch
:descending
else
:none
end
end
|
#first_pitch ⇒ Object
33
34
35
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 33
def first_pitch
@first_pitch ||= first_note.pitch
end
|
#high_pitch ⇒ Object
65
66
67
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 65
def high_pitch
pitches.max
end
|
#low_pitch ⇒ Object
69
70
71
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 69
def low_pitch
pitches.min
end
|
#moving? ⇒ Boolean
53
54
55
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 53
def moving?
ascending? || descending?
end
|
#notes ⇒ Object
25
26
27
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 25
def notes
[first_note, second_note]
end
|
#pitches ⇒ Object
29
30
31
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 29
def pitches
[first_pitch, second_pitch]
end
|
#position_end ⇒ Object
21
22
23
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 21
def position_end
second_note.next_position
end
|
#position_start ⇒ Object
17
18
19
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 17
def position_start
first_note.position
end
|
#repetition? ⇒ Boolean
57
58
59
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 57
def repetition?
!moving?
end
|
#respond_to_missing?(method_name, *_args) ⇒ Boolean
97
98
99
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 97
def respond_to_missing?(method_name, *_args)
diatonic_interval.respond_to?(method_name)
end
|
#second_pitch ⇒ Object
37
38
39
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 37
def second_pitch
@second_pitch ||= second_note.pitch
end
|
#spans?(pitch) ⇒ Boolean
61
62
63
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 61
def spans?(pitch)
pitch >= low_pitch && pitch <= high_pitch
end
|
#spells_consonant_triad_with?(other_interval) ⇒ Boolean
84
85
86
87
88
89
90
91
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 84
def spells_consonant_triad_with?(other_interval)
return false if step? || other_interval.step?
combined_pitches = (pitches + other_interval.pitches).uniq
return false if combined_pitches.length < 3
HeadMusic::Rudiment::PitchSet.new(combined_pitches).consonant_triad?
end
|
#to_s ⇒ Object
41
42
43
|
# File 'lib/head_music/analysis/melodic_interval.rb', line 41
def to_s
[direction, diatonic_interval].join(" ")
end
|