Module: Cyclotone::Transforms::Accumulation
- Included in:
- Pattern
- Defined in:
- lib/cyclotone/transforms/accumulation.rb
Instance Method Summary collapse
- #jux(&block) ⇒ Object
- #jux_by(amount, &block) ⇒ Object
- #layer(functions) ⇒ Object
- #overlay(other) ⇒ Object
- #superimpose(&block) ⇒ Object
- #weave(count, pattern, controls) ⇒ Object
- #weave_with(count, pattern, functions) ⇒ Object
Instance Method Details
#jux(&block) ⇒ Object
23 24 25 |
# File 'lib/cyclotone/transforms/accumulation.rb', line 23 def jux(&block) jux_by(1, &block) end |
#jux_by(amount, &block) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/cyclotone/transforms/accumulation.rb', line 27 def jux_by(amount, &block) raise ArgumentError, "jux_by requires a block" unless block offset = amount.to_f / 2.0 left = merge(Controls.pan((0.5 - offset).clamp(0.0, 1.0))) right = block.call(self).merge(Controls.pan((0.5 + offset).clamp(0.0, 1.0))) Pattern.stack([left, right]) end |
#layer(functions) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/cyclotone/transforms/accumulation.rb', line 16 def layer(functions) normalized_functions = Array(functions) raise ArgumentError, "layer requires functions" if normalized_functions.empty? Pattern.stack(normalized_functions.map { |function| function.call(self) }) end |
#overlay(other) ⇒ Object
6 7 8 |
# File 'lib/cyclotone/transforms/accumulation.rb', line 6 def (other) Pattern.stack([self, Pattern.ensure_pattern(other)]) end |
#superimpose(&block) ⇒ Object
10 11 12 13 14 |
# File 'lib/cyclotone/transforms/accumulation.rb', line 10 def superimpose(&block) raise ArgumentError, "superimpose requires a block" unless block (block.call(self)) end |
#weave(count, pattern, controls) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/cyclotone/transforms/accumulation.rb', line 36 def weave(count, pattern, controls) functions = Array(controls).map do |control_pattern| proc { |base| base.merge(control_pattern) } end weave_with(count, pattern, functions) end |
#weave_with(count, pattern, functions) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cyclotone/transforms/accumulation.rb', line 44 def weave_with(count, pattern, functions) normalized_count = normalize_weave_count(count) normalized_functions = Array(functions) raise ArgumentError, "weave functions must not be empty" if normalized_functions.empty? Pattern.fastcat( Array.new(normalized_count) do |index| normalized_functions[index % normalized_functions.length].call(pattern) end ) end |