Class: Zgomot::Comp::PitchClass

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(p) ⇒ PitchClass

Returns a new instance of PitchClass.

Raises:



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

#valueObject (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