Class: HeadMusic::Rudiment::Pitch::StepDistance
- Inherits:
-
Object
- Object
- HeadMusic::Rudiment::Pitch::StepDistance
- Defined in:
- lib/head_music/rudiment/pitch/step_distance.rb
Overview
The number of diatonic steps from one pitch to another, signed: the letter steps between them, plus seven for each octave crossed.
The letter steps already carry one wrap of the scale, so a register difference counts one octave short whenever the starting letter sits above the ending letter – C4 to A4 is five steps, not twelve.
Constant Summary collapse
- STEPS_PER_OCTAVE =
7
Instance Attribute Summary collapse
-
#from_pitch ⇒ Object
readonly
Returns the value of attribute from_pitch.
-
#to_pitch ⇒ Object
readonly
Returns the value of attribute to_pitch.
Instance Method Summary collapse
-
#initialize(from_pitch, to_pitch) ⇒ StepDistance
constructor
A new instance of StepDistance.
-
#octave_adjustment ⇒ Object
private
-
#octave_changes ⇒ Object
private
-
#pitch_class_above? ⇒ Boolean
private
-
#steps ⇒ Object
Constructor Details
#initialize(from_pitch, to_pitch) ⇒ StepDistance
Returns a new instance of StepDistance.
13 14 15 16 |
# File 'lib/head_music/rudiment/pitch/step_distance.rb', line 13 def initialize(from_pitch, to_pitch) @from_pitch = from_pitch @to_pitch = HeadMusic::Rudiment::Pitch.get(to_pitch) end |
Instance Attribute Details
#from_pitch ⇒ Object (readonly)
Returns the value of attribute from_pitch.
11 12 13 |
# File 'lib/head_music/rudiment/pitch/step_distance.rb', line 11 def from_pitch @from_pitch end |
#to_pitch ⇒ Object (readonly)
Returns the value of attribute to_pitch.
11 12 13 |
# File 'lib/head_music/rudiment/pitch/step_distance.rb', line 11 def to_pitch @to_pitch end |
Instance Method Details
#octave_adjustment ⇒ Object (private)
28 29 30 |
# File 'lib/head_music/rudiment/pitch/step_distance.rb', line 28 def octave_adjustment pitch_class_above? ? 1 : 0 end |
#octave_changes ⇒ Object (private)
24 25 26 |
# File 'lib/head_music/rudiment/pitch/step_distance.rb', line 24 def octave_changes to_pitch.register - from_pitch.register - octave_adjustment end |
#pitch_class_above? ⇒ Boolean (private)
32 33 34 |
# File 'lib/head_music/rudiment/pitch/step_distance.rb', line 32 def pitch_class_above? from_pitch.natural_pitch_class_number > to_pitch.natural_pitch_class_number end |
#steps ⇒ Object
18 19 20 |
# File 'lib/head_music/rudiment/pitch/step_distance.rb', line 18 def steps from_pitch.letter_name_steps_to(to_pitch) + STEPS_PER_OCTAVE * octave_changes end |