class Sequencer::Core
The core sequencer
Attributes
Public Class Methods
# File lib/sequencer/core.rb, line 9 def initialize @event = Event.new @loop = Loop.new @pointer = 0 @trigger = EventTrigger.new end
Public Instance Methods
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
Represents performance of a single sequence frame
Order of events:
-
If
Event#next
for the current pointer, fire -
If
EventTrigger#stop
, fireEvent#stop
, otherwise: -
If
EventTrigger#reset
, fire Event#reset -
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
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 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
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