class HeadMusic::ScaleDegree
A scale degree is a number indicating the ordinality of the spelling in the key signature. TODO: Rewrite to accept a tonal_center and a scale type.
Constants
- NAME_FOR_DIATONIC_DEGREE
Attributes
key_signature[R]
spelling[R]
Public Class Methods
new(key_signature, spelling)
click to toggle source
# File lib/head_music/scale_degree.rb, line 15 def initialize(key_signature, spelling) @key_signature = key_signature @spelling = HeadMusic::Spelling.get(spelling) end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/head_music/scale_degree.rb, line 35 def <=>(other) if other.is_a?(HeadMusic::ScaleDegree) [degree, sign.semitones] <=> [other.degree, other.sign.semitones] else to_s <=> other.to_s end end
degree()
click to toggle source
# File lib/head_music/scale_degree.rb, line 20 def degree scale.letter_name_series_ascending.index(spelling.letter_name.to_s) + 1 end
name_for_degree()
click to toggle source
# File lib/head_music/scale_degree.rb, line 43 def name_for_degree return unless scale_type.diatonic? NAME_FOR_DIATONIC_DEGREE[degree] || (scale_type.intervals.last == 1 || sign == '#' ? 'leading tone' : 'subtonic') end
sign()
click to toggle source
# File lib/head_music/scale_degree.rb, line 24 def sign sign_semitones = spelling.sign&.semitones || 0 usual_sign_semitones = scale_degree_usual_spelling.sign&.semitones || 0 delta = sign_semitones - usual_sign_semitones HeadMusic::Sign.by(:semitones, delta) if delta != 0 end
to_s()
click to toggle source
# File lib/head_music/scale_degree.rb, line 31 def to_s "#{sign}#{degree}" end
Private Instance Methods
scale_degree_usual_spelling()
click to toggle source
# File lib/head_music/scale_degree.rb, line 52 def scale_degree_usual_spelling HeadMusic::Spelling.get(scale.spellings[degree - 1]) end