Class: Musa::Clock::Clock Abstract
Overview
Subclass and implement #run and #terminate
Abstract base class for all clock implementations.
This class defines the interface and callback infrastructure that all
concrete clock implementations must follow. Subclasses must implement
the run and terminate methods.
Callback System
Clocks maintain three callback collections:
- on_start: Called when clock starts running
- on_stop: Called when clock stops
- on_change_position: Called when position changes (seek/jump)
Subclass Responsibilities
Concrete clocks must:
- Implement
run(&block)- Start generating ticks, yield for each tick - Implement
terminate- Stop the clock - Call registered callbacks at appropriate times
- Manage @run state properly
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize ⇒ Clock
constructor
Initializes the clock with empty callback collections.
-
#on_change_position {|bars, beats, midi_beats| ... } ⇒ void
Registers a callback to be called when playback position changes.
-
#on_start { ... } ⇒ void
Registers a callback to be called when the clock starts.
-
#on_stop { ... } ⇒ void
Registers a callback to be called when the clock stops.
-
#run { ... } ⇒ void
Starts the clock running and generates ticks.
-
#running? ⇒ Boolean
Checks if the clock is currently running.
-
#terminate ⇒ void
Stops the clock and terminates the run loop.
Constructor Details
#initialize ⇒ Clock
Initializes the clock with empty callback collections.
71 72 73 74 75 76 |
# File 'lib/musa-dsl/transport/clock.rb', line 71 def initialize @run = nil @on_start = [] @on_stop = [] @on_change_position = [] end |
Instance Method Details
#on_change_position {|bars, beats, midi_beats| ... } ⇒ void
This method returns an undefined value.
Registers a callback to be called when playback position changes.
This is typically used for handling seek/jump operations where the transport position changes non-linearly.
126 127 128 |
# File 'lib/musa-dsl/transport/clock.rb', line 126 def on_change_position(&block) @on_change_position << block end |
#on_start { ... } ⇒ void
This method returns an undefined value.
Registers a callback to be called when the clock starts.
Multiple callbacks can be registered and will be called in order.
94 95 96 |
# File 'lib/musa-dsl/transport/clock.rb', line 94 def on_start(&block) @on_start << block end |
#on_stop { ... } ⇒ void
This method returns an undefined value.
Registers a callback to be called when the clock stops.
Multiple callbacks can be registered and will be called in order.
107 108 109 |
# File 'lib/musa-dsl/transport/clock.rb', line 107 def on_stop(&block) @on_stop << block end |
#run { ... } ⇒ void
This method typically runs in a loop until #terminate is called.
Subclasses should call @on_start callbacks when starting.
Subclasses should call @on_stop callbacks when stopping.
This method returns an undefined value.
Starts the clock running and generates ticks.
This method should block and yield once per tick. Subclasses must implement this method.
143 144 145 |
# File 'lib/musa-dsl/transport/clock.rb', line 143 def run raise NotImplementedError end |
#running? ⇒ Boolean
Checks if the clock is currently running.
81 82 83 |
# File 'lib/musa-dsl/transport/clock.rb', line 81 def running? @run end |
#terminate ⇒ void
After calling this, #run should exit.
This method returns an undefined value.
Stops the clock and terminates the run loop.
Subclasses must implement this method to cleanly stop the clock.
156 157 158 |
# File 'lib/musa-dsl/transport/clock.rb', line 156 def terminate raise NotImplementedError end |