Class: Musicality::ScaleClass

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/musicality/composition/model/scale_class.rb

Instance Method Summary collapse

Methods included from Enumerable

#map_with_index, #to_pcs

Constructor Details

#initialize(intervals) ⇒ ScaleClass

Returns a new instance of ScaleClass.



6
7
8
9
10
11
# File 'lib/musicality/composition/model/scale_class.rb', line 6

def initialize intervals
  if intervals.detect {|x| x <= 0 }
    raise NonPositiveError, "One or more scale intervals (#{intervals}) is non-positive"
  end
  @intervals = intervals
end

Instance Method Details

#==(other) ⇒ Object



15
16
17
# File 'lib/musicality/composition/model/scale_class.rb', line 15

def ==(other)
  self.entries == other.entries
end

#eachObject



19
20
21
22
# File 'lib/musicality/composition/model/scale_class.rb', line 19

def each
  return @intervals.each unless block_given?
  @intervals.each {|x| yield x }
end

#intervalsObject



13
# File 'lib/musicality/composition/model/scale_class.rb', line 13

def intervals; self.entries; end

#rotate(n = 1) ⇒ Object



32
33
34
# File 'lib/musicality/composition/model/scale_class.rb', line 32

def rotate n = 1
  ScaleClass.new(@intervals.rotate(n))
end

#to_pitch_seq(start_pitch) ⇒ Object



24
25
26
# File 'lib/musicality/composition/model/scale_class.rb', line 24

def to_pitch_seq start_pitch
  AddingSequence.new(@intervals, start_pitch)
end

#to_scale(pitch_class) ⇒ Object



28
29
30
# File 'lib/musicality/composition/model/scale_class.rb', line 28

def to_scale pitch_class
  Scale.new(pitch_class, @intervals)
end