class Coltrane::Theory::FrequencyInterval
Interval
describe the logarithmic distance between 2 frequencies. It's measured in cents.
Attributes
cents[R]
hash[R]
Public Class Methods
new(cents)
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 16 def initialize(cents) @cents = cents.round end
Public Instance Methods
+(other)
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 60 def +(other) case other when Numeric then FrequencyInterval[cents + other] when Interval then FrequencyInterval[cents + other.cents] end end
-(other)
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 67 def -(other) case other when Numeric then FrequencyInterval[cents - other] when Interval then FrequencyInterval[cents - other.cents] end end
-@()
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 74 def -@ FrequencyInterval[-cents] end
<=>(other)
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 78 def <=>(other) cents <=> other.cents end
==(other)
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 52 def ==(other) return false unless other.is_a? FrequencyInterval cents == other.cents end
Also aliased as: eql?
ascending()
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 24 def ascending self.class[cents.abs] end
ascending?()
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 32 def ascending? cents > 0 end
descending()
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 28 def descending self.class[-cents.abs] end
descending?()
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 36 def descending? cents < 0 end
interval_class()
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 48 def interval_class IntervalClass.new(semitones) end
inversion()
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 40 def inversion self.class[(-cents.abs % 1200) * (ascending? ? +1 : -1)] end
opposite()
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 44 def opposite self.class.new(-cents) end
semitones()
click to toggle source
# File lib/coltrane/theory/frequency_interval.rb, line 20 def semitones (cents.to_f / 100).round end