Class: HeadMusic::Rudiment::Pitch::NaturalStep

Inherits:
Object
  • Object
show all
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. Register-agnostic — it works purely from the letter name’s position in the scale, so the Pitch supplies the register.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(letter_name, num_steps) ⇒ NaturalStep

Returns a new instance of NaturalStep.



9
10
11
12
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 9

def initialize(letter_name, num_steps)
  @letter_name = letter_name
  @num_steps = num_steps
end

Instance Attribute Details

#letter_nameObject (readonly)

Returns the value of attribute letter_name.



7
8
9
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 7

def letter_name
  @letter_name
end

#num_stepsObject (readonly)

Returns the value of attribute num_steps.



7
8
9
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 7

def num_steps
  @num_steps
end

Instance Method Details

#octaves_deltaObject



18
19
20
21
22
23
24
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 18

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_nameObject



14
15
16
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 14

def target_letter_name
  @target_letter_name ||= letter_name.steps_up(num_steps)
end

#wrapped_down?Boolean (private)

Returns:

  • (Boolean)


28
29
30
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 28

def wrapped_down?
  num_steps.negative? && target_letter_name.position > letter_name.position
end

#wrapped_up?Boolean (private)

Returns:

  • (Boolean)


32
33
34
# File 'lib/head_music/rudiment/pitch/natural_step.rb', line 32

def wrapped_up?
  num_steps.positive? && target_letter_name.position < letter_name.position
end