Class: Musa::Sequencer::BaseSequencer::MoveControl

Inherits:
EventHandler show all
Defined in:
lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb

Overview

Control object for move operations.

Wraps EveryControl to provide move-specific lifecycle management. Delegates timing control to EveryControl while adding move-specific callbacks and state.

Delegation Pattern

MoveControl delegates to EveryControl for:

  • Duration and till timing control
  • Iteration scheduling
  • Stop conditions

Adds move-specific features:

  • on_stop callbacks when movement completes
  • after callbacks with delays
  • Stopped state synchronization

Examples:

Basic move control

control = sequencer.move(from: 0, to: 100, duration: 4r, every: 1/4r) { |v| }
control.on_stop { puts "Movement finished!" }
control.after(2r) { puts "2 bars after finish" }
control.stop  # Manually halt movement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, duration: nil, till: nil, on_stop: nil, after_bars: nil, after: nil) ⇒ MoveControl

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 move control with timing parameters.

Parameters:

  • parent (EventHandler)

    parent event handler

  • duration (Rational, nil) (defaults to: nil)

    maximum duration in bars

  • till (Rational, nil) (defaults to: nil)

    absolute stop position

  • on_stop (Proc, nil) (defaults to: nil)

    stop callback

  • after_bars (Rational, nil) (defaults to: nil)

    delay for after callback

  • after (Proc, nil) (defaults to: nil)

    after callback block



528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb', line 528

def initialize(parent, duration: nil, till: nil, on_stop: nil, after_bars: nil, after: nil)
  super parent

  @every_control = EveryControl.new(self, duration: duration, till: till)
  @manually_stopped = false

  @do_on_stop = []
  @do_after = []

  @do_on_stop << on_stop if on_stop
  self.after after_bars, &after if after

  @every_control.on_stop do
    @stop = true
    @do_on_stop.each(&:call)
  end
end

Instance Attribute Details

#do_afterArray<Hash> (readonly)

Returns after callbacks with delays.

Returns:

  • (Array<Hash>)

    after callbacks with delays



516
517
518
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb', line 516

def do_after
  @do_after
end

#do_on_stopArray<Proc> (readonly)

Returns stop callbacks.

Returns:

  • (Array<Proc>)

    stop callbacks



514
515
516
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb', line 514

def do_on_stop
  @do_on_stop
end

#every_controlEveryControl (readonly)

Returns underlying every control for timing.

Returns:



512
513
514
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb', line 512

def every_control
  @every_control
end

Instance Method Details

#after(bars = nil) { ... } ⇒ void

This method returns an undefined value.

Registers callback to execute after movement terminates naturally. NOT called on manual stop (.stop).

Examples:

Delayed callback

control.after(2r) { puts "2 bars after movement ends" }

Parameters:

  • bars (Numeric, nil) (defaults to: nil)

    delay in bars after natural termination (default: 0)

Yields:

  • after callback block



567
568
569
570
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb', line 567

def after(bars = nil, &block)
  bars ||= 0
  @do_after << { bars: bars.rationalize, block: block }
end

#manually_stopped?Boolean

Checks if movement was stopped manually (via .stop).

Returns:

  • (Boolean)

    true if manually stopped



588
589
590
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb', line 588

def manually_stopped?
  @manually_stopped
end

#on_stop { ... } ⇒ void

This method returns an undefined value.

Registers callback for when movement stops (any reason, including manual stop).

Yields:

  • stop callback block



552
553
554
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb', line 552

def on_stop(&block)
  @do_on_stop << block
end

#stopvoid

This method returns an undefined value.

Stops movement manually.

Sets manually_stopped flag before delegating to every_control. After callbacks will NOT fire on manual stop.



579
580
581
582
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb', line 579

def stop
  @manually_stopped = true
  @every_control.stop
end

#stopped?Boolean

Checks if movement is stopped.

Returns:

  • (Boolean)

    true if stopped



596
597
598
# File 'lib/musa-dsl/sequencer/base-sequencer-implementation-move.rb', line 596

def stopped?
  @stop
end