Class: Musicality::AddingSequence
- Inherits:
-
Object
- Object
- Musicality::AddingSequence
- Includes:
- BiInfiniteSequence
- Defined in:
- lib/musicality/composition/util/adding_sequence.rb
Instance Attribute Summary collapse
-
#start_value ⇒ Object
readonly
Returns the value of attribute start_value.
Instance Method Summary collapse
-
#initialize(pattern, start_val = 0) ⇒ AddingSequence
constructor
A new instance of AddingSequence.
- #next_value(cur_val, cur_idx) ⇒ Object
- #pattern_size ⇒ Object
- #prev_value(cur_val, cur_idx) ⇒ Object
Methods included from BiInfiniteSequence
#at, #over, #take, #take_back
Constructor Details
#initialize(pattern, start_val = 0) ⇒ AddingSequence
Returns a new instance of AddingSequence.
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_value ⇒ Object (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_size ⇒ Object
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 |