Class: TEF::Sequencing::BaseSequence
- Inherits:
-
Object
- Object
- TEF::Sequencing::BaseSequence
- Defined in:
- lib/tef/Sequencing/BaseSequence.rb
Overview
Base sequence class.
It implements the minium necessary tools to make different Sequences work together nicely. It’s main function is to provide #append_events, which is used by a Player to fetch the next queued event for execution.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#end_time ⇒ Numeric?
readonly
End time of this sequence, in local time.
-
#offset ⇒ Numeric, Time
readonly
The offset to apply to this Sequence, used when converting between local-time and parent-time.
-
#slope ⇒ Numeric
readonly
Slope to apply to this sequence.
-
#start_time ⇒ Numeric
readonly
Start time of this sequence, in local time.
-
#state ⇒ Symbol
readonly
purposes.
Instance Method Summary collapse
-
#append_events(collector) ⇒ Object
Look for the next possible event that this sequence wants to execute.
- #destroy! ⇒ Object
-
#initialize(offset, slope, **options) ⇒ BaseSequence
constructor
Initialize a BaseSequence.
- #overload_append_events(_collector) ⇒ Object
- #parent_end_time ⇒ Object
- #parent_end_time=(new_time) ⇒ Object
- #parent_start_time ⇒ Object
- #setup ⇒ Object
- #teardown ⇒ Object
Constructor Details
#initialize(offset, slope, **options) ⇒ BaseSequence
Initialize a BaseSequence.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 48 def initialize(offset, slope, **) @start_time ||= [:start_time] || 0; @end_time ||= [:end_time]; @offset = offset; @slope = slope.round(6); # Explanation: For some bizarre reason, rounding is necessary # to avoid a glitch in the timing math. 6 digits of precision # should be precise enough anyways. @state = :uninitialized @opts_hash = ; end |
Instance Attribute Details
#end_time ⇒ Numeric? (readonly)
Returns End time of this sequence, in local time. Specifies when to call #teardown. Can be left as nil for no automatic teardown.
20 21 22 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 20 def end_time @end_time end |
#offset ⇒ Numeric, Time (readonly)
Returns The offset to apply to this Sequence, used when converting between local-time and parent-time.
This MAY be modified during runtime, though this may cause some events to be skipped!.
27 28 29 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 27 def offset @offset end |
#slope ⇒ Numeric (readonly)
Returns Slope to apply to this sequence.
30 31 32 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 30 def slope @slope end |
#start_time ⇒ Numeric (readonly)
Returns Start time of this sequence, in local time. Specifies when to call #setup.
16 17 18 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 16 def start_time @start_time end |
#state ⇒ Symbol (readonly)
purposes. Can be:
-
:uninitialized (right after construction)
-
:running (after having called setup())
-
:idle (after teardown() was called)
37 38 39 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 37 def state @state end |
Instance Method Details
#append_events(collector) ⇒ Object
When using BaseSequence as base class, the user shall overload #overload_append_events rather than this function!
Look for the next possible event that this sequence wants to execute. Will ensure that this sequence’s #setup and #teardown blocks are called at the appropriate time.
Should only be called by a Player or another sequence!
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 100 def append_events(collector) return if @state == :uninitialized local_collector = collector.offset_collector(@offset, @slope); # Return if the collector has events before our start time return if local_collector.has_events? && local_collector.event_time < @start_time if !@end_time.nil? if @state == :running local_collector.add_event({ time: [@end_time, local_collector.start_time + 0.01].max, code: proc { self.teardown() } }) end return if local_collector.start_time >= @end_time end if @state == :idle local_collector.add_event({ time: [@start_time, local_collector.start_time + 0.01].max, code: proc { self.setup() } }); end overload_append_events(local_collector) end |
#destroy! ⇒ Object
132 133 134 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 132 def destroy!() teardown() if @state == :running end |
#overload_append_events(_collector) ⇒ Object
130 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 130 def overload_append_events(_collector) end |
#parent_end_time ⇒ Object
66 67 68 69 70 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 66 def parent_end_time return nil if @end_time.nil? @offset + @end_time / @slope end |
#parent_end_time=(new_time) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 72 def parent_end_time=(new_time) if(new_time.nil?) @end_time = nil; return; end @end_time = (new_time - @offset) * @slope; end |
#parent_start_time ⇒ Object
63 64 65 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 63 def parent_start_time @offset + @start_time / @slope end |
#setup ⇒ Object
81 82 83 84 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 81 def setup() return unless @state == :idle @state = :running end |
#teardown ⇒ Object
86 87 88 89 |
# File 'lib/tef/Sequencing/BaseSequence.rb', line 86 def teardown() return unless @state == :running @state = :idle end |