class Sequencer::Core

The core sequencer

Attributes

event[R]
loop[R]
pointer[RW]
trigger[R]

Public Class Methods

new() click to toggle source
# File lib/sequencer/core.rb, line 9
def initialize
  @event = Event.new
  @loop = Loop.new
  @pointer = 0
  @trigger = EventTrigger.new
end

Public Instance Methods

exec(sequence) click to toggle source

Execute a single cycle of sequencing (perform and step) @param [Array] sequence The sequence to execute a single cycle of @return [Boolean] Whether perform and step both finished

# File lib/sequencer/core.rb, line 19
def exec(sequence)
  perform(sequence) && step(sequence)
end
perform(sequence) click to toggle source

Represents performance of a single sequence frame

Order of events:

  1. If Event#next for the current pointer, fire

  2. If EventTrigger#stop, fire Event#stop, otherwise:

  3. If EventTrigger#reset, fire Event#reset

  4. Fire Event#perform with the sequence frame

@param [Array] sequence @return [Boolean] Whether Event#perform event was fired

# File lib/sequencer/core.rb, line 47
def perform(sequence)
  data = sequence.at(@pointer)
  @event.do_next(@pointer, data) if @event.next?(@pointer)
  if @trigger.stop?(@pointer, data)
    @event.do_stop
    false
  else
    reset_pointer if @trigger.reset?(@pointer, data)
    @event.do_perform(data)
    true
  end
end
reset_pointer() click to toggle source

Set the pointer to the loop start point @return [Fixnum]

# File lib/sequencer/core.rb, line 62
def reset_pointer
  @pointer = @loop.next
end
step(sequence) click to toggle source

Step the sequencer and fire Event#step event @param [Array] sequence @return [Boolean]

# File lib/sequencer/core.rb, line 26
def step(sequence)
  if reset_pointer?(:length => sequence.length)
    reset_pointer
  else
    @pointer += 1
  end
  @event.do_step
  true
end

Private Instance Methods

reset_pointer?(options = {}) click to toggle source

Is the pointer at the point where it needs to be reset? @param [Hash] options @option options [Fixnum] :length The length of the sequence (used when the default loop is active) @return [Boolean]

# File lib/sequencer/core.rb, line 72
def reset_pointer?(options = {})
  !@loop.disabled? && !@loop.in_bounds?(@pointer + 1, :length => options[:length])
end