lib/head_music/scale.rb in head_music-0.27.0 vs lib/head_music/scale.rb in head_music-0.28.0
- old
+ new
@@ -1,18 +1,18 @@
# frozen_string_literal: true
# A scale contains ordered pitches starting at a tonal center.
class HeadMusic::Scale
- SCALE_REGEX = /^[A-G][#b]?\s+\w+$/.freeze
+ SCALE_REGEX = /^[A-G][#b]?\s+\w+$/
def self.get(root_pitch, scale_type = nil)
root_pitch, scale_type = root_pitch.split(/\s+/) if root_pitch.is_a?(String) && scale_type =~ SCALE_REGEX
root_pitch = HeadMusic::Pitch.get(root_pitch)
scale_type = HeadMusic::ScaleType.get(scale_type || :major)
@scales ||= {}
hash_key = HeadMusic::Utilities::HashKey.for(
- [root_pitch, scale_type].join(' ').gsub(/#|♯/, 'sharp').gsub(/(\w)[b♭]/, '\\1flat')
+ [root_pitch, scale_type].join(" ").gsub(/#|♯/, "sharp").gsub(/(\w)[b♭]/, '\\1flat')
)
@scales[hash_key] ||= new(root_pitch, scale_type)
end
delegate :letter_name_series_ascending, :letter_name_series_descending, to: :root_pitch
@@ -68,11 +68,11 @@
pitch_for_step(i, semitones_from_root, direction)
end
end
def direction_sign(direction)
- direction == :descending ? -1 : 1
+ (direction == :descending) ? -1 : 1
end
def direction_intervals(direction)
scale_type.send("#{direction}_intervals")
end
@@ -101,10 +101,10 @@
end
def diatonic_letter_for_step(direction, step)
return unless scale_type.diatonic?
- direction == :ascending ? letter_name_series_ascending[step % 7] : letter_name_series_descending[step % 7]
+ (direction == :ascending) ? letter_name_series_ascending[step % 7] : letter_name_series_descending[step % 7]
end
def child_scale_letter_for_step(semitones_from_root)
return unless scale_type.parent