Class: Musicality::Scale

Inherits:
Object
  • Object
show all
Defined in:
lib/musicality/composition/model/scale.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pitch_class, intervals) ⇒ Scale

Returns a new instance of Scale.



5
6
7
8
# File 'lib/musicality/composition/model/scale.rb', line 5

def initialize pitch_class, intervals
  @pitch_class = pitch_class
  @intervals = intervals
end

Instance Attribute Details

#pitch_classObject (readonly)

Returns the value of attribute pitch_class.



4
5
6
# File 'lib/musicality/composition/model/scale.rb', line 4

def pitch_class
  @pitch_class
end

Instance Method Details

#at_octave(octave) ⇒ Object



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

def at_octave octave
  start_pitch = Pitch.new(octave: octave, semitone: @pitch_class)
  AddingSequence.new(@intervals, start_pitch)
end

#intervalsObject



10
# File 'lib/musicality/composition/model/scale.rb', line 10

def intervals; @intervals.entries; end

#rotate(n) ⇒ Object



21
22
23
24
25
26
# File 'lib/musicality/composition/model/scale.rb', line 21

def rotate n
  diff = AddingSequence.new(@intervals).at(n)
  new_pc = (@pitch_class + diff).to_pc
  new_intervals = @intervals.rotate(n)
  Scale.new(new_pc,new_intervals)
end

#sizeObject



12
13
14
# File 'lib/musicality/composition/model/scale.rb', line 12

def size
  @intervals.size
end

#transpose(diff) ⇒ Object



16
17
18
19
# File 'lib/musicality/composition/model/scale.rb', line 16

def transpose diff
  new_pc = (@pitch_class + diff).to_pc
  Scale.new(new_pc,@intervals)
end