Class: HeadMusic::DiatonicInterval::Size
- Inherits:
-
Object
- Object
- HeadMusic::DiatonicInterval::Size
- Defined in:
- lib/head_music/diatonic_interval.rb
Overview
Encapsulate the distance methods of the interval
Instance Attribute Summary collapse
-
#high_pitch ⇒ Object
readonly
Returns the value of attribute high_pitch.
-
#low_pitch ⇒ Object
readonly
Returns the value of attribute low_pitch.
Instance Method Summary collapse
- #compound? ⇒ Boolean
-
#initialize(pitch1, pitch2) ⇒ Size
constructor
A new instance of Size.
- #number ⇒ Object
- #octaves ⇒ Object
- #semitones ⇒ Object
- #simple? ⇒ Boolean
- #simple_number ⇒ Object
- #simple_semitones ⇒ Object
- #simple_steps ⇒ Object
- #steps ⇒ Object
Constructor Details
#initialize(pitch1, pitch2) ⇒ Size
Returns a new instance of Size.
153 154 155 |
# File 'lib/head_music/diatonic_interval.rb', line 153 def initialize(pitch1, pitch2) @low_pitch, @high_pitch = *[pitch1, pitch2].sort end |
Instance Attribute Details
#high_pitch ⇒ Object (readonly)
Returns the value of attribute high_pitch.
151 152 153 |
# File 'lib/head_music/diatonic_interval.rb', line 151 def high_pitch @high_pitch end |
#low_pitch ⇒ Object (readonly)
Returns the value of attribute low_pitch.
151 152 153 |
# File 'lib/head_music/diatonic_interval.rb', line 151 def low_pitch @low_pitch end |
Instance Method Details
#compound? ⇒ Boolean
173 174 175 |
# File 'lib/head_music/diatonic_interval.rb', line 173 def compound? !simple? end |
#number ⇒ Object
157 158 159 |
# File 'lib/head_music/diatonic_interval.rb', line 157 def number @number ||= @low_pitch.steps_to(@high_pitch) + 1 end |
#octaves ⇒ Object
165 166 167 |
# File 'lib/head_music/diatonic_interval.rb', line 165 def octaves @octaves ||= number / 8 end |
#semitones ⇒ Object
181 182 183 |
# File 'lib/head_music/diatonic_interval.rb', line 181 def semitones (high_pitch - low_pitch).to_i end |
#simple? ⇒ Boolean
169 170 171 |
# File 'lib/head_music/diatonic_interval.rb', line 169 def simple? number <= 8 end |
#simple_number ⇒ Object
161 162 163 |
# File 'lib/head_music/diatonic_interval.rb', line 161 def simple_number @simple_number ||= octave_equivalent? ? 8 : (number - 1) % 7 + 1 end |
#simple_semitones ⇒ Object
177 178 179 |
# File 'lib/head_music/diatonic_interval.rb', line 177 def simple_semitones @simple_semitones ||= semitones % 12 end |
#simple_steps ⇒ Object
189 190 191 |
# File 'lib/head_music/diatonic_interval.rb', line 189 def simple_steps steps % 7 end |
#steps ⇒ Object
185 186 187 |
# File 'lib/head_music/diatonic_interval.rb', line 185 def steps number - 1 end |