Class: Musa::Sequencer::BaseSequencer::PlayControl Private
- Inherits:
-
EventHandler
- Object
- EventHandler
- Musa::Sequencer::BaseSequencer::PlayControl
- Defined in:
- lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Control object for play operations.
Manages play lifecycle including pause/continue and after callbacks. Extends EventHandler to support custom events and hierarchical control.
Pause/Continue
When paused:
- Stores continuation parameters (series state, evaluator, etc.)
- Stops processing series
- Awaits continue call
When continued:
- Restores continuation parameters
- Resumes play from stored position
After Callbacks
Executed after play completes, with optional delay in bars.
Instance Attribute Summary collapse
-
#do_after ⇒ Array<Hash>
readonly
private
After callbacks with delays (only on natural termination).
-
#do_on_stop ⇒ Array<Proc>
readonly
private
Callbacks when play stops (any reason, including manual stop).
Instance Method Summary collapse
-
#_finished!(sequencer, position) ⇒ void
private
Records that the play has ended, and where.
-
#after(bars = nil) { ... } ⇒ void
private
Registers callback to execute after play completes naturally (series exhausted).
-
#continue ⇒ void
private
Continues from pause.
-
#initialize(parent, on_stop: nil, after_bars: nil, after: nil) ⇒ PlayControl
constructor
private
Creates play control with optional callbacks.
-
#on_stop { ... } ⇒ void
private
Registers callback for when play stops (any reason, including manual stop).
-
#pause ⇒ void
private
Pauses play and stores continuation state.
-
#store_continuation(sequencer:, serie:, neumalang_context:, mode:, decoder:, play_eval:, mode_args:) ⇒ void
private
Stores state for continue operation.
Constructor Details
#initialize(parent, on_stop: nil, after_bars: nil, after: nil) ⇒ PlayControl
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 play control with optional callbacks.
297 298 299 300 301 302 303 304 305 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb', line 297 def initialize(parent, on_stop: nil, after_bars: nil, after: nil) super parent @do_on_stop = [] @do_after = [] @do_on_stop << on_stop if on_stop after(, &after) if after end |
Instance Attribute Details
#do_after ⇒ Array<Hash> (readonly)
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 after callbacks with delays (only on natural termination).
287 288 289 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb', line 287 def do_after @do_after end |
#do_on_stop ⇒ Array<Proc> (readonly)
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 callbacks when play stops (any reason, including manual stop).
285 286 287 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb', line 285 def do_on_stop @do_on_stop end |
Instance Method Details
#_finished!(sequencer, position) ⇒ 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.
Records that the play has ended, and where.
Only the termination branch of _play calls this. It exists because the
control can reach the caller already dead -- see #after.
385 386 387 388 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb', line 385 def _finished!(sequencer, position) @finished_sequencer = sequencer @finished_at = position end |
#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 play completes naturally (series exhausted). Not called on manual stop.
403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb', line 403 def after( = nil, &block) ||= 0 # Already over: `after(2)` means "two bars after it ends", and it ended # at @finished_at, so that is where this goes. Registering it in the # list would be registering it after the only moment anything reads the # list, which is what used to happen to every play that resolved within # one instant -- a chord written as a serie of `forward_duration: 0` # elements, a lone event with no duration -- and the callback simply # never ran (issue #84). return @finished_sequencer.at(@finished_at + .rationalize, &block) if @finished_at @do_after << { bars: .rationalize, block: block } end |
#continue ⇒ 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.
Continues from pause.
Restores paused state and resumes play using stored continuation.
354 355 356 357 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb', line 354 def continue super @continuation_sequencer&.continuation_play(@continuation_parameters) 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 play stops (any reason, including manual stop).
366 367 368 369 370 371 372 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb', line 366 def on_stop(&block) # Already over: on_stop means "when it terminates", and it has. The # normal path calls these directly too, rather than scheduling them. return block.call if @finished_at @do_on_stop << block end |
#pause ⇒ 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.
Pauses play and stores continuation state.
Sets paused flag. Continuation must be stored separately via store_continuation.
315 316 317 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb', line 315 def pause @paused = true end |
#store_continuation(sequencer:, serie:, neumalang_context:, mode:, decoder:, play_eval:, mode_args:) ⇒ 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.
Stores state for continue operation.
Saves all parameters needed to resume play from current position. Called automatically by _play when paused.
335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-play.rb', line 335 def store_continuation(sequencer:, serie:, neumalang_context:, mode:, decoder:, play_eval:, mode_args:) @continuation_sequencer = sequencer @continuation_parameters = { serie: serie, control: self, neumalang_context: neumalang_context, mode: mode, decoder: decoder, play_eval: play_eval, mode_args: mode_args } end |