Module: Cyclotone::Transforms::Sample
- Included in:
- Pattern
- Defined in:
- lib/cyclotone/transforms/sample.rb
Instance Method Summary collapse
- #bite(count, pattern) ⇒ Object
- #chew(count, pattern) ⇒ Object
- #chop(count) ⇒ Object
- #loop_at(cycles) ⇒ Object
- #randslice(count) ⇒ Object
- #segment(count) ⇒ Object
- #slice(count, pattern) ⇒ Object
- #splice(count, pattern) ⇒ Object
- #striate(count) ⇒ Object
Instance Method Details
#bite(count, pattern) ⇒ Object
39 40 41 |
# File 'lib/cyclotone/transforms/sample.rb', line 39 def bite(count, pattern) slice(count, pattern).fast(count) end |
#chew(count, pattern) ⇒ Object
43 44 45 |
# File 'lib/cyclotone/transforms/sample.rb', line 43 def chew(count, pattern) bite(count, pattern) end |
#chop(count) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/cyclotone/transforms/sample.rb', line 6 def chop(count) normalized_count = validate_positive_integer(count, "chop count") Pattern.fastcat( Array.new(normalized_count) do |index| merge(Controls.begin(Rational(index, normalized_count))).merge( Controls.end(Rational(index + 1, normalized_count)) ) end ) end |
#loop_at(cycles) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/cyclotone/transforms/sample.rb', line 56 def loop_at(cycles) normalized_cycles = Pattern.to_rational(cycles) raise ArgumentError, "loop_at cycles must be positive" unless normalized_cycles.positive? merge(Controls.speed(1.0 / normalized_cycles.to_f)) end |
#randslice(count) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/cyclotone/transforms/sample.rb', line 47 def randslice(count) normalized_count = validate_positive_integer(count, "randslice count") map_events do |event| index = Support::Deterministic.int(normalized_count, :randslice, event.value, event.part.start) merge_controls(event, begin: Rational(index, normalized_count), end: Rational(index + 1, normalized_count)) end end |
#segment(count) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cyclotone/transforms/sample.rb', line 63 def segment(count) normalized_count = validate_positive_integer(count, "segment count") Pattern.new do |span| cycle_start = Rational(span.cycle_number) segment_length = Rational(1, normalized_count) Array.new(normalized_count) { |index| index }.filter_map do |index| segment_span = TimeSpan.new( cycle_start + (segment_length * index), cycle_start + (segment_length * (index + 1)) ) overlap = span.intersection(segment_span) next unless overlap value = query_point(segment_span.midpoint) Event.new(whole: segment_span, part: overlap, value: value) end end end |
#slice(count, pattern) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cyclotone/transforms/sample.rb', line 22 def slice(count, pattern) normalized_count = validate_positive_integer(count, "slice count") selection = Pattern.ensure_pattern(pattern) map_events do |event| selected_value = selection.query_point(event.onset || event.part.start) next nil if selected_value.nil? index = selected_value.to_i % normalized_count merge_controls(event, begin: Rational(index, normalized_count), end: Rational(index + 1, normalized_count)) end end |
#splice(count, pattern) ⇒ Object
35 36 37 |
# File 'lib/cyclotone/transforms/sample.rb', line 35 def splice(count, pattern) slice(count, pattern).merge(Controls.speed(count)) end |
#striate(count) ⇒ Object
18 19 20 |
# File 'lib/cyclotone/transforms/sample.rb', line 18 def striate(count) chop(count) end |