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.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 125 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.
112 113 114 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 112 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.
109 110 111 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 109 def _start_position @_start_position end |
#condition_block ⇒ Proc? (readonly)
Returns condition block (returns true to continue).
101 102 103 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 101 def condition_block @condition_block end |
#do_after ⇒ Array<Hash> (readonly)
Returns after callbacks with delays.
105 106 107 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 105 def do_after @do_after end |
#do_on_stop ⇒ Array<Proc> (readonly)
Returns callbacks when loop stops.
103 104 105 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 103 def do_on_stop @do_on_stop end |
#duration_value ⇒ Rational? (readonly)
Returns maximum duration in bars.
97 98 99 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 97 def duration_value @duration_value end |
#till_value ⇒ Rational? (readonly)
Returns absolute position to stop at.
99 100 101 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 99 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).
199 200 201 202 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 199 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.
169 170 171 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 169 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.
147 148 149 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 147 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).
180 181 182 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 180 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.
158 159 160 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-every.rb', line 158 def till(value) @till_value = value.rationalize end |