Class: HeadMusic::Rudiment::Pitch::NaturalLetterPitch
- Inherits:
-
Object
- Object
- HeadMusic::Rudiment::Pitch::NaturalLetterPitch
- Defined in:
- lib/head_music/rudiment/pitch/natural_letter_pitch.rb
Overview
The unaltered pitch of a letter name, in the register that puts it nearest a given midi note number: the pitch a spelling of that number is measured from.
A tritone is the tie-break. Any further and the same letter in the next register is closer, so the alteration measured from here would be the larger of the two ways to spell the note.
Constant Summary collapse
- OCTAVE_SEMITONES =
12- TRITONE_SEMITONES =
6
Instance Attribute Summary collapse
-
#letter_name ⇒ Object
readonly
Returns the value of attribute letter_name.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(number, letter_name) ⇒ NaturalLetterPitch
constructor
A new instance of NaturalLetterPitch.
-
#nearest_register_of(candidate) ⇒ Object
private
-
#pitch ⇒ Object
Constructor Details
#initialize(number, letter_name) ⇒ NaturalLetterPitch
Returns a new instance of NaturalLetterPitch.
18 19 20 21 |
# File 'lib/head_music/rudiment/pitch/natural_letter_pitch.rb', line 18 def initialize(number, letter_name) @number = number.to_i @letter_name = HeadMusic::Rudiment::LetterName.get(letter_name) end |
Instance Attribute Details
#letter_name ⇒ Object (readonly)
Returns the value of attribute letter_name.
12 13 14 |
# File 'lib/head_music/rudiment/pitch/natural_letter_pitch.rb', line 12 def letter_name @letter_name end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
12 13 14 |
# File 'lib/head_music/rudiment/pitch/natural_letter_pitch.rb', line 12 def number @number end |
Class Method Details
.get(number, letter_name) ⇒ Object
14 15 16 |
# File 'lib/head_music/rudiment/pitch/natural_letter_pitch.rb', line 14 def self.get(number, letter_name) new(number, letter_name).pitch end |
Instance Method Details
#nearest_register_of(candidate) ⇒ Object (private)
29 30 31 32 33 |
# File 'lib/head_music/rudiment/pitch/natural_letter_pitch.rb', line 29 def nearest_register_of(candidate) candidate += OCTAVE_SEMITONES while (number - candidate.to_i) >= TRITONE_SEMITONES candidate -= OCTAVE_SEMITONES while (number - candidate.to_i) <= -TRITONE_SEMITONES candidate end |