Sha256: b0741c0a4f9698d4366ac3e5ce1ee0cad2f80018ba63c78dde662ad755f175b9
Contents?: true
Size: 924 Bytes
Versions: 1
Compression:
Stored size: 924 Bytes
Contents
class HeadMusic::PitchClass attr_reader :number PREFERRED_SPELLINGS = %w[C C# D Eb E F F# G Ab A Bb B] def self.get(number) @pitch_classes ||= {} number = number.to_i % 12 @pitch_classes[number] ||= new(number) end class << self alias_method :[], :get end def initialize(pitch_class_or_midi_number) @number = pitch_class_or_midi_number % 12 end def to_i number end def +(semitones) HeadMusic::PitchClass.get(to_i + semitones.to_i) end def -(semitones) HeadMusic::PitchClass.get(to_i - semitones.to_i) end def ==(value) to_i == value.to_i end def intervals_to(other) delta = other.to_i - to_i inverse = delta > 0 ? delta - 12 : delta + 12 [delta, inverse].sort_by(&:abs).map { |interval| HeadMusic::Interval.get(interval) } end def smallest_interval_to(other) intervals_to(other).first end private_class_method :new end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
head_music-0.1.1 | lib/head_music/pitch_class.rb |