Class: Musicality::RepeatingSequence

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BiInfiniteSequence

#at, #over, #take, #take_back

Constructor Details

#initialize(pattern) ⇒ RepeatingSequence

Returns a new instance of RepeatingSequence.

Raises:



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

def initialize pattern
  raise EmptyError if pattern.empty?
  @pattern = pattern
  @n = pattern.size
  @start_value = pattern.first
end

Instance Attribute Details

#start_valueObject (readonly)

Returns the value of attribute start_value.



6
7
8
# File 'lib/musicality/composition/util/repeating_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/repeating_sequence.rb', line 16

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

#pattern_sizeObject



14
# File 'lib/musicality/composition/util/repeating_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/repeating_sequence.rb', line 19

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