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.
155 156 157 |
# File 'lib/head_music/diatonic_interval.rb', line 155 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.
153 154 155 |
# File 'lib/head_music/diatonic_interval.rb', line 153 def high_pitch @high_pitch end |
#low_pitch ⇒ Object (readonly)
Returns the value of attribute low_pitch.
153 154 155 |
# File 'lib/head_music/diatonic_interval.rb', line 153 def low_pitch @low_pitch end |
Instance Method Details
#compound? ⇒ Boolean
175 176 177 |
# File 'lib/head_music/diatonic_interval.rb', line 175 def compound? !simple? end |
#number ⇒ Object
159 160 161 |
# File 'lib/head_music/diatonic_interval.rb', line 159 def number @number ||= @low_pitch.steps_to(@high_pitch) + 1 end |
#octaves ⇒ Object
167 168 169 |
# File 'lib/head_music/diatonic_interval.rb', line 167 def octaves @octaves ||= number / 8 end |
#semitones ⇒ Object
183 184 185 |
# File 'lib/head_music/diatonic_interval.rb', line 183 def semitones (high_pitch - low_pitch).to_i end |
#simple? ⇒ Boolean
171 172 173 |
# File 'lib/head_music/diatonic_interval.rb', line 171 def simple? number <= 8 end |
#simple_number ⇒ Object
163 164 165 |
# File 'lib/head_music/diatonic_interval.rb', line 163 def simple_number @simple_number ||= octave_equivalent? ? 8 : (number - 1) % 7 + 1 end |
#simple_semitones ⇒ Object
179 180 181 |
# File 'lib/head_music/diatonic_interval.rb', line 179 def simple_semitones @simple_semitones ||= semitones % 12 end |
#simple_steps ⇒ Object
191 192 193 |
# File 'lib/head_music/diatonic_interval.rb', line 191 def simple_steps steps % 7 end |
#steps ⇒ Object
187 188 189 |
# File 'lib/head_music/diatonic_interval.rb', line 187 def steps number - 1 end |