Class: Zgomot::Comp::PitchClass
- Defined in:
- lib/zgomot/comp/pitch_class.rb
Constant Summary collapse
- PITCH_CLASS =
{ :C => 0, :Cs => 1, :D => 2, :Ds => 3, :E => 4, :F => 5, :Fs => 6, :G => 7, :Gs => 8, :A => 9, :As => 10, :B => 11 }
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #<(p) ⇒ Object
- #>(p) ⇒ Object
-
#initialize(p) ⇒ PitchClass
constructor
A new instance of PitchClass.
Constructor Details
#initialize(p) ⇒ PitchClass
Returns a new instance of PitchClass.
27 28 29 30 |
# File 'lib/zgomot/comp/pitch_class.rb', line 27 def initialize(p) raise(Zgomot::Error, "#{p} is invalid pitch class") unless PITCH_CLASS.include?(p) @value = p end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
26 27 28 |
# File 'lib/zgomot/comp/pitch_class.rb', line 26 def value @value end |
Class Method Details
.next(pc, interval) ⇒ Object
18 19 20 21 |
# File 'lib/zgomot/comp/pitch_class.rb', line 18 def next(pc, interval) start_pos = PITCH_CLASS[to_value(pc)] new(PITCH_CLASS.inject([]){|r,(c,p)| p.eql?((start_pos+interval) % 12) ? r << c : r}.first) if start_pos end |
.to_value(p) ⇒ Object
22 23 24 |
# File 'lib/zgomot/comp/pitch_class.rb', line 22 def to_value(p) p.kind_of?(PitchClass) ? p.value : p end |
Instance Method Details
#<(p) ⇒ Object
31 32 33 |
# File 'lib/zgomot/comp/pitch_class.rb', line 31 def <(p) PITCH_CLASS[value] < PITCH_CLASS[self.class.to_value(p)] end |
#>(p) ⇒ Object
34 35 36 |
# File 'lib/zgomot/comp/pitch_class.rb', line 34 def >(p) PITCH_CLASS[value] > PITCH_CLASS[self.class.to_value(p)] end |