Class: Musicality::AddingSequence

Inherits:
Object
  • Object
show all
Includes:
BiInfiniteSequence
Defined in:
lib/musicality/composition/util/adding_sequence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BiInfiniteSequence

#at, #over, #take, #take_back

Constructor Details

#initialize(pattern, start_val = 0) ⇒ AddingSequence

Returns a new instance of AddingSequence.

Raises:



7
8
9
10
11
12
# File 'lib/musicality/composition/util/adding_sequence.rb', line 7

def initialize pattern, start_val = 0
  raise EmptyError if pattern.empty?
  @pattern = pattern
  @n = pattern.size
  @start_value = start_val
end

Instance Attribute Details

#start_valueObject (readonly)

Returns the value of attribute start_value.



6
7
8
# File 'lib/musicality/composition/util/adding_sequence.rb', line 6

def start_value
  @start_value
end

Instance Method Details

#next_value(cur_val, cur_idx) ⇒ Object



16
17
18
# File 'lib/musicality/composition/util/adding_sequence.rb', line 16

def next_value cur_val, cur_idx
  cur_val + @pattern[cur_idx % @n]
end

#pattern_sizeObject



14
# File 'lib/musicality/composition/util/adding_sequence.rb', line 14

def pattern_size; @pattern.size; end

#prev_value(cur_val, cur_idx) ⇒ Object



19
20
21
# File 'lib/musicality/composition/util/adding_sequence.rb', line 19

def prev_value cur_val, cur_idx
  cur_val - @pattern[(cur_idx-1) % @n]
end