lib/head_music/pitch.rb in head_music-0.27.0 vs lib/head_music/pitch.rb in head_music-0.28.0
- old
+ new
@@ -32,15 +32,15 @@
from_name(value) ||
from_number(value)
end
def self.middle_c
- get('C4')
+ get("C4")
end
def self.concert_a
- get('A4')
+ get("A4")
end
def self.from_pitch_class(pitch_class)
return nil unless pitch_class.is_a?(HeadMusic::PitchClass)
@@ -95,12 +95,12 @@
def midi_note_number
(register + 1) * 12 + letter_name.pitch_class.to_i + sign_semitones.to_i
end
- alias midi midi_note_number
- alias number midi_note_number
+ alias_method :midi, :midi_note_number
+ alias_method :number, :midi_note_number
def to_s
name
end
@@ -111,11 +111,11 @@
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::Sign.matcher, ""))
end
def +(other)
if other.is_a?(HeadMusic::DiatonicInterval)
# return a pitch
@@ -125,14 +125,15 @@
HeadMusic::Pitch.get(to_i + other.to_i)
end
end
def -(other)
- if other.is_a?(HeadMusic::DiatonicInterval)
+ case other
+ when HeadMusic::DiatonicInterval
# return a pitch
other.below(self)
- elsif other.is_a?(HeadMusic::Pitch)
+ when HeadMusic::Pitch
# return an interval
HeadMusic::ChromaticInterval.get(to_i - other.to_i)
else
# assume value represents an interval in semitones and return another pitch
HeadMusic::Pitch.get(to_i - other.to_i)
@@ -192,10 +193,10 @@
def tuning
@tuning ||= HeadMusic::Tuning.new
end
def octaves_delta(num_steps)
- octaves_delta = (num_steps.abs / 7) * (num_steps >= 0 ? 1 : -1)
+ octaves_delta = (num_steps.abs / 7) * ((num_steps >= 0) ? 1 : -1)
if wrapped_down?(num_steps)
octaves_delta -= 1
elsif wrapped_up?(num_steps)
octaves_delta += 1
end