Class: Sequencer::Core

Inherits:
Object
  • Object
show all
Defined in:
lib/sequencer/core.rb

Overview

The core sequencer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCore

Returns a new instance of Core


9
10
11
12
13
14
# File 'lib/sequencer/core.rb', line 9

def initialize
  @event = Event.new
  @loop = Loop.new
  @pointer = 0
  @trigger = EventTrigger.new
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event


6
7
8
# File 'lib/sequencer/core.rb', line 6

def event
  @event
end

#loopObject (readonly)

Returns the value of attribute loop


6
7
8
# File 'lib/sequencer/core.rb', line 6

def loop
  @loop
end

#pointerObject

Returns the value of attribute pointer


7
8
9
# File 'lib/sequencer/core.rb', line 7

def pointer
  @pointer
end

#triggerObject (readonly)

Returns the value of attribute trigger


6
7
8
# File 'lib/sequencer/core.rb', line 6

def trigger
  @trigger
end

Instance Method Details

#exec(sequence) ⇒ Boolean

Execute a single cycle of sequencing (perform and step)

Parameters:

  • sequence (Array)

    The sequence to execute a single cycle of

Returns:

  • (Boolean)

    Whether perform and step both finished


19
20
21
# File 'lib/sequencer/core.rb', line 19

def exec(sequence)
  perform(sequence) && step(sequence)
end

#perform(sequence) ⇒ Boolean

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

Parameters:

  • sequence (Array)

Returns:

  • (Boolean)

    Whether Event#perform event was fired


47
48
49
50
51
52
53
54
55
56
57
58
# 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_pointerFixnum

Set the pointer to the loop start point

Returns:

  • (Fixnum)

62
63
64
# File 'lib/sequencer/core.rb', line 62

def reset_pointer
  @pointer = @loop.next
end

#step(sequence) ⇒ Boolean

Step the sequencer and fire Event#step event

Parameters:

  • sequence (Array)

Returns:

  • (Boolean)

26
27
28
29
30
31
32
33
34
# 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