Class: Musa::Sequencer::BaseSequencer::EveryControl
- Inherits:
-
EventHandler
- Object
- EventHandler
- Musa::Sequencer::BaseSequencer::EveryControl
- Defined in:
- lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb
Overview
Control object for every loops.
Manages lifecycle of every loop including stopping conditions, callbacks, and execution tracking. Extends EventHandler to support event-based control (e.g., launching custom events).
Stopping Conditions
- duration: Maximum loop duration in bars
- till: Absolute position to stop at
- condition: Proc returning true to continue, false to stop
- manual stop: Call
control.stopto halt loop
Callbacks
- on_stop: Called when loop stops (any reason, including manual stop)
- after: Called only on natural termination (duration/till/condition/nil-interval), NOT on manual stop
Execution Tracking
- _start_position: Position when loop started
- _execution_counter: Number of iterations executed
Instance Attribute Summary collapse
-
#_execution_counter ⇒ Integer
private
Number of iterations executed.
-
#_start_position ⇒ Rational
private
Position when loop started.
-
#condition_block ⇒ Proc?
readonly
Condition block (returns true to continue).
-
#do_after ⇒ Array<Hash>
readonly
After callbacks with delays.
-
#do_on_stop ⇒ Array<Proc>
readonly
Callbacks when loop stops.
-
#duration_value ⇒ Rational?
readonly
Maximum duration in bars.
-
#till_value ⇒ Rational?
readonly
Absolute position to stop at.
Instance Method Summary collapse
-
#after(bars = nil) { ... } ⇒ void
private
Registers callback to execute after loop terminates naturally.
-
#condition { ... } ⇒ void
private
Sets continuation condition.
-
#duration(value) ⇒ void
private
Sets maximum loop duration.
-
#initialize(parent, duration: nil, till: nil, condition: nil, on_stop: nil, after_bars: nil, after: nil) ⇒ EveryControl
constructor
private
Creates every loop control.
-
#on_stop { ... } ⇒ void
private
Registers callback for when loop stops (any reason, including manual stop).
-
#till(value) ⇒ void
private
Sets absolute stop position.
Constructor Details
#initialize(parent, duration: nil, till: nil, condition: nil, on_stop: nil, after_bars: nil, after: nil) ⇒ EveryControl
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates every loop control.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 129 def initialize(parent, duration: nil, till: nil, condition: nil, on_stop: nil, after_bars: nil, after: nil) super parent @duration_value = duration @till_value = till @condition_block = condition @do_on_stop = [] @do_after = [] @do_on_stop << on_stop if on_stop self.after , &after if after end |
Instance Attribute Details
#_execution_counter ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns number of iterations executed.
116 117 118 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 116 def _execution_counter @_execution_counter end |
#_start_position ⇒ Rational
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns position when loop started.
113 114 115 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 113 def _start_position @_start_position end |
#condition_block ⇒ Proc? (readonly)
Returns condition block (returns true to continue).
105 106 107 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 105 def condition_block @condition_block end |
#do_after ⇒ Array<Hash> (readonly)
Returns after callbacks with delays.
109 110 111 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 109 def do_after @do_after end |
#do_on_stop ⇒ Array<Proc> (readonly)
Returns callbacks when loop stops.
107 108 109 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 107 def do_on_stop @do_on_stop end |
#duration_value ⇒ Rational? (readonly)
Returns maximum duration in bars.
101 102 103 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 101 def duration_value @duration_value end |
#till_value ⇒ Rational? (readonly)
Returns absolute position to stop at.
103 104 105 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 103 def till_value @till_value end |
Instance Method Details
#after(bars = nil) { ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Registers callback to execute after loop terminates naturally. NOT called on manual stop (.stop).
203 204 205 206 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 203 def after( = nil, &block) ||= 0 @do_after << { bars: .rationalize, block: block } end |
#condition { ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Sets continuation condition.
173 174 175 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 173 def condition(&block) @condition_block = block end |
#duration(value) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Sets maximum loop duration.
151 152 153 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 151 def duration(value) @duration_value = value.rationalize end |
#on_stop { ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Registers callback for when loop stops (any reason, including manual stop).
184 185 186 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 184 def on_stop(&block) @do_on_stop << block end |
#till(value) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Sets absolute stop position.
162 163 164 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 162 def till(value) @till_value = value.rationalize end |