lib/head_music/pitch.rb in head_music-0.23.4 vs lib/head_music/pitch.rb in head_music-0.24.0

- old
+ new

@@ -19,12 +19,21 @@ delegate :smallest_interval_to, to: :pitch_class delegate :enharmonic_equivalent?, :enharmonic?, to: :enharmonic_equivalence delegate :octave_equivalent?, to: :octave_equivalence + # Fetches a pitch identified by the information passed in. + # + # Accepts: + # - a Pitch instance + # - a PitchClass instance + # - a name string, such as 'Ab4' + # - a number corresponding to the midi note number def self.get(value) - from_pitch_class(value) || from_name(value) || from_number(value) + from_pitch_class(value) || + from_name(value) || + from_number(value) end def self.middle_c get('C4') end @@ -46,12 +55,10 @@ end def self.from_number(number) return nil unless number == number.to_i - spelling = HeadMusic::Spelling.from_number(number) - octave = (number.to_i / 12) - 1 - fetch_or_create(spelling, octave) + fetch_or_create(HeadMusic::Spelling.from_number(number), (number.to_i / 12) - 1) 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)