lib/head_music/pitch.rb in head_music-4.0.1 vs lib/head_music/pitch.rb in head_music-5.0.0
- old
+ new
@@ -1,20 +1,18 @@
-# frozen_string_literal: true
-
# A pitch is a named frequency represented by a spelling and a register.
class HeadMusic::Pitch
include Comparable
attr_reader :spelling, :register
delegate :letter_name, to: :spelling
delegate :series_ascending, :series_descending, to: :letter_name, prefix: true
- delegate :sign, :sharp?, :flat?, to: :spelling
+ delegate :alteration, :sharp?, :flat?, to: :spelling
delegate :pitch_class, to: :spelling
delegate :number, to: :pitch_class, prefix: true
delegate :pitch_class_number, to: :natural, prefix: true
- delegate :semitones, to: :sign, prefix: true, allow_nil: true
+ delegate :semitones, to: :alteration, prefix: true, allow_nil: true
delegate :steps_to, to: :letter_name, prefix: true
delegate :smallest_interval_to, to: :pitch_class
delegate :enharmonic_equivalent?, :enharmonic?, to: :enharmonic_equivalence
@@ -60,13 +58,13 @@
end
def self.from_number_and_letter(number, letter_name)
letter_name = HeadMusic::LetterName.get(letter_name)
natural_letter_pitch = natural_letter_pitch(number, letter_name)
- sign_interval = natural_letter_pitch.smallest_interval_to(HeadMusic::PitchClass.get(number))
- sign = HeadMusic::Sign.by(:semitones, sign_interval) if sign_interval != 0
- spelling = HeadMusic::Spelling.fetch_or_create(letter_name, sign)
+ alteration_interval = natural_letter_pitch.smallest_interval_to(HeadMusic::PitchClass.get(number))
+ alteration = HeadMusic::Alteration.by(:semitones, alteration_interval) if alteration_interval != 0
+ spelling = HeadMusic::Spelling.fetch_or_create(letter_name, alteration)
fetch_or_create(spelling, natural_letter_pitch.register)
end
def self.natural_letter_pitch(number, letter_name)
natural_letter_pitch = get(HeadMusic::LetterName.get(letter_name).pitch_class)
@@ -92,11 +90,11 @@
def name
[spelling, register].join
end
def midi_note_number
- (register + 1) * 12 + letter_name.pitch_class.to_i + sign_semitones.to_i
+ (register + 1) * 12 + letter_name.pitch_class.to_i + alteration_semitones.to_i
end
alias_method :midi, :midi_note_number
alias_method :number, :midi_note_number
@@ -111,10 +109,10 @@
def helmholtz_notation
helmholtz_letter_name + helmholtz_marks
end
def natural
- HeadMusic::Pitch.get(to_s.gsub(HeadMusic::Sign.matcher, ""))
+ HeadMusic::Pitch.get(to_s.gsub(HeadMusic::Alteration.matcher, ""))
end
def +(other)
if other.is_a?(HeadMusic::DiatonicInterval)
# return a pitch