lib/head_music/pitch.rb in head_music-0.5.0 vs lib/head_music/pitch.rb in head_music-0.5.1

- old
+ new

@@ -5,10 +5,11 @@ attr_reader :octave delegate :letter, :letter_cycle, to: :spelling delegate :accidental, :sharp?, :flat?, to: :spelling delegate :pitch_class, to: :spelling + delegate :semitones, to: :accidental, prefix: true, allow_nil: true delegate :smallest_interval_to, to: :pitch_class def self.get(value) from_name(value) || from_number(value) @@ -27,11 +28,11 @@ end def self.from_number_and_letter(number, letter) letter = HeadMusic::Letter.get(letter) natural_letter_pitch = get(HeadMusic::Letter.get(letter).pitch_class) - natural_letter_pitch += 12 while (number - natural_letter_pitch.to_i) >= 11 + natural_letter_pitch += 12 while (number - natural_letter_pitch.to_i).to_i >= 11 natural_letter_pitch = get(natural_letter_pitch) accidental_interval = natural_letter_pitch.smallest_interval_to(HeadMusic::PitchClass.get(number)) accidental = HeadMusic::Accidental.for_interval(accidental_interval) spelling = HeadMusic::Spelling.fetch_or_create(letter, accidental) fetch_or_create(spelling, natural_letter_pitch.octave) @@ -53,10 +54,10 @@ def name [spelling, octave].join end def midi_note_number - (octave + 1) * 12 + pitch_class.to_i + (octave + 1) * 12 + letter.pitch_class.to_i + accidental_semitones.to_i end alias_method :midi, :midi_note_number alias_method :number, :midi_note_number