class Coltrane::Theory::PitchClass
Pitch
classes, and by classes here we don't mean in the sense of a ruby class are all the classes of pitches (frequencies) that are in a whole number of octaves apart.
For example, C1, C2, C3 are all pitches from the C pitch class. Take a look into Notes description if you somehow feel this is confuse and that it could just be called as notes instead.
Constants
- NOTATION
Attributes
hash[R]
integer[R]
Public Class Methods
[](arg, frequency: nil)
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 39 def self.[](arg, frequency: nil) new(arg, frequency: nil) end
all()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 24 def self.all NOTATION.map { |n| new(n) } end
all_letters()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 20 def self.all_letters %w[C D E F G A B] end
new(arg = nil, frequency: nil)
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 28 def initialize(arg = nil, frequency: nil) @integer = case arg when String then NOTATION.index(arg) when Frequency then frequency_to_integer(Frequency.new(arg)) when Numeric then (arg % 12) when nil then frequency_to_integer(Frequency.new(frequency)) when PitchClass then arg.integer else raise(WrongArgumentsError) end end
size()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 129 def self.size NOTATION.size end
Public Instance Methods
+(other)
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 93 def +(other) case other when Interval then self.class[integer + other.semitones] when Integer then self.class[integer + other] when PitchClass then self.class[integer + other.integer] when Frequency then self.class.new(frequency: frequency + other) end end
-(other)
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 102 def -(other) case other when Interval then self.class[integer - other.semitones] when Integer then self.class[integer - other] when PitchClass then Interval.new(self, other) when Frequency then self.class.new(frequency: frequency - other) end end
<=>(other)
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 115 def <=>(other) integer <=> other.integer end
==(other)
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 43 def ==(other) integer == other.integer end
Also aliased as: eql?
accidental?()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 78 def accidental? notation.match? /#|b/ end
ascending_interval_to(other)
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 58 def ascending_interval_to(other) Interval.new(self, (other.is_a?(PitchClass) ? other : Note.new(other))) end
Also aliased as: interval_to
descending_interval_to(other)
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 64 def descending_interval_to(other) Interval.new( self, (other.is_a?(PitchClass) ? other : Note.new(other)), ascending: false ) end
enharmonic?(other)
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 137 def enharmonic?(other) case other when String then integer == Note[other].integer when Note then integer == other.integer end end
flat?()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 86 def flat? notation.match? /b/ end
fundamental_frequency()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 119 def fundamental_frequency @fundamental_frequency ||= Frequency[ Theory.base_tuning * (2**((integer - Theory::BASE_PITCH_INTEGER.to_f) / 12)) ] end
Also aliased as: frequency
letter()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 54 def letter name[0] end
pitch_class()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 111 def pitch_class self end
pretty_name()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 74 def pretty_name name.tr('b', "\u266D").tr('#', "\u266F") end
sharp?()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 82 def sharp? notation.match? /#/ end
size()
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 133 def size self.class.size end
Private Instance Methods
frequency_to_integer(f)
click to toggle source
# File lib/coltrane/theory/pitch_class.rb, line 146 def frequency_to_integer(f) begin (::BASE_PITCH_INTEGER + size * Math.log(f.to_f / Theory.base_tuning.to_f, 2)) % size end.round end