Class: HeadMusic::Rudiment::Pitch::NaturalStep
- Inherits:
-
Object
- Object
- HeadMusic::Rudiment::Pitch::NaturalStep
- Defined in:
- lib/head_music/rudiment/pitch/natural_step.rb
Overview
Computes where a signed number of diatonic (letter-name) steps lands relative to a starting letter name: the destination letter and how many octaves the move crosses. The computation is register-agnostic, working purely from the letter name’s position in the scale, so #applied_to takes the pitch that supplies the register.
Instance Attribute Summary collapse
-
#letter_name ⇒ Object
readonly
Returns the value of attribute letter_name.
-
#num_steps ⇒ Object
readonly
Returns the value of attribute num_steps.
Instance Method Summary collapse
-
#applied_to(pitch) ⇒ Object
-
#initialize(letter_name, num_steps) ⇒ NaturalStep
constructor
A new instance of NaturalStep.
-
#octaves_delta ⇒ Object
-
#target_letter_name ⇒ Object
-
#wrapped_down? ⇒ Boolean
private
-
#wrapped_up? ⇒ Boolean
private
Constructor Details
#initialize(letter_name, num_steps) ⇒ NaturalStep
Returns a new instance of NaturalStep.
10 11 12 13 |
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 10 def initialize(letter_name, num_steps) @letter_name = letter_name @num_steps = num_steps end |
Instance Attribute Details
#letter_name ⇒ Object (readonly)
Returns the value of attribute letter_name.
8 9 10 |
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 8 def letter_name @letter_name end |
#num_steps ⇒ Object (readonly)
Returns the value of attribute num_steps.
8 9 10 |
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 8 def num_steps @num_steps end |
Instance Method Details
#applied_to(pitch) ⇒ Object
27 28 29 |
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 27 def applied_to(pitch) HeadMusic::Rudiment::Pitch.get([target_letter_name, pitch.register + octaves_delta].join) end |
#octaves_delta ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 19 def octaves_delta whole_octaves = (num_steps.abs / 7) * (num_steps.negative? ? -1 : 1) return whole_octaves - 1 if wrapped_down? return whole_octaves + 1 if wrapped_up? whole_octaves end |
#target_letter_name ⇒ Object
15 16 17 |
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 15 def target_letter_name @target_letter_name ||= letter_name.steps_up(num_steps) end |
#wrapped_down? ⇒ Boolean (private)
33 34 35 |
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 33 def wrapped_down? num_steps.negative? && target_letter_name.position > letter_name.position end |
#wrapped_up? ⇒ Boolean (private)
37 38 39 |
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 37 def wrapped_up? num_steps.positive? && target_letter_name.position < letter_name.position end |