Class: Musa::Sequencer::Sequencer
- Extended by:
- Forwardable
- Defined in:
- lib/musa-dsl/sequencer/sequencer-dsl.rb
Overview
High-level DSL wrapper for BaseSequencer.
Provides user-friendly interface with block context management via
with method. Wraps BaseSequencer methods to automatically evaluate
blocks in DSL context, enabling clean musical composition code.
DSL Context
Blocks passed to scheduling methods (now, at, wait, play, every, move)
are evaluated in DSL context via with, providing access to sequencer
methods and allowing for cleaner composition syntax.
Delegation
Delegates most methods to either BaseSequencer or DSLContext:
- Timing: beats_per_bar, ticks_per_beat, position, tick, reset
- Scheduling: now, at, wait, play, play_timed, every, move
- Events: launch, on
- Inspection: size, empty?, everying, playing, moving
Musical Applications
Provides composer-friendly API for:
- Musical composition scripts
- Interactive sequencing
- Live coding
- Algorithmic composition
Defined Under Namespace
Classes: DSLContext
Instance Method Summary collapse
-
#at(position, *value_parameters, **key_parameters) { ... } ⇒ EventHandler
Schedules block to execute at specified position.
-
#beats_per_bar ⇒ Integer?
Returns beats per bar (time signature numerator).
-
#before_tick { ... } ⇒ Object
Registers handler called before each tick.
-
#debug ⇒ Boolean
Returns or enables debug mode.
-
#empty? ⇒ Boolean
Checks if sequencer has no scheduled events.
-
#event_handler ⇒ EventHandler
Returns the event handler for launch/on events.
-
#every(interval, duration: nil, till: nil, **options) { ... } ⇒ EveryControl
Executes block repeatedly at interval.
-
#everying ⇒ EveryingControl
Returns control for active every loops.
-
#initialize(beats_per_bar = nil, ticks_per_beat = nil, offset: nil, sequencer: nil, logger: nil, do_log: nil, do_error_log: nil, log_position_format: nil, dsl_context_class: nil, keep_block_context: nil) { ... } ⇒ Sequencer
constructor
Creates sequencer with optional initialization block.
-
#launch(event_name, *parameters, **key_parameters) ⇒ void
Triggers an event by name.
-
#logger ⇒ Logger?
Returns the sequencer's logger instance.
-
#move(from: nil, to: nil, duration: nil, step: nil, **options) {|value| ... } ⇒ MoveControl
Interpolates values over time.
-
#moving ⇒ MovingControl
Returns control for active move interpolations.
-
#now(*value_parameters, **key_parameters) { ... } ⇒ EventHandler
Executes block immediately at current position.
-
#offset ⇒ Rational?
Returns the sequencer's starting position offset.
-
#on(event_name) { ... } ⇒ void
Registers handler for named event.
-
#on_debug_at { ... } ⇒ Object
Registers debug handler for specific position.
-
#on_error {|Exception| ... } ⇒ Object
Registers error handler for sequencer errors.
-
#on_fast_forward { ... } ⇒ Object
Registers handler called during fast-forward operations.
-
#play(serie, decoder: nil, mode: nil, **options) {|element| ... } ⇒ PlayControl
Plays a series using the decoder.
-
#play_timed(timed_serie, **options) {|element, duration| ... } ⇒ PlayControl
Plays a timed series with explicit timing.
-
#playing ⇒ PlayingControl
Returns control for active play operations.
-
#position ⇒ Rational
Returns current sequencer position in bars.
-
#position=(value) ⇒ void
Sets the current sequencer position.
-
#quantize_position(reference, step, offset: nil) ⇒ Rational
Quantizes a position to a grid.
-
#raw_at(position) { ... } ⇒ Object
Schedules block at position without DSL context wrapping.
-
#reset ⇒ void
Resets sequencer to initial state.
-
#run ⇒ void
Runs the sequencer until all events complete.
-
#size ⇒ Integer
Returns number of scheduled events.
-
#tick ⇒ void
Advances sequencer by one tick and processes events.
-
#tick_duration ⇒ Rational?
Returns duration of a single tick.
-
#ticks_per_bar ⇒ Integer?
Returns total ticks per bar.
-
#ticks_per_beat ⇒ Integer?
Returns ticks per beat (timing resolution).
-
#wait(duration, *value_parameters, **key_parameters) { ... } ⇒ EventHandler
Schedules block after waiting specified duration.
-
#with(*value_parameters, **key_parameters) { ... } ⇒ Object
Evaluates block in DSL context.
Constructor Details
#initialize(beats_per_bar = nil, ticks_per_beat = nil, offset: nil, sequencer: nil, logger: nil, do_log: nil, do_error_log: nil, log_position_format: nil, dsl_context_class: nil, keep_block_context: nil) { ... } ⇒ Sequencer
Creates sequencer with optional initialization block.
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 373 def initialize( = nil, ticks_per_beat = nil, offset: nil, sequencer: nil, logger: nil, do_log: nil, do_error_log: nil, log_position_format: nil, dsl_context_class: nil, keep_block_context: nil, &block) @sequencer = sequencer @sequencer ||= BaseSequencer.new , ticks_per_beat, offset: offset, logger: logger, do_log: do_log, do_error_log: do_error_log, log_position_format: log_position_format dsl_context_class ||= DSLContext @dsl = dsl_context_class.new @sequencer, keep_block_context: keep_block_context @dsl.with &block if block_given? end |
Instance Method Details
#at(position, *value_parameters, **key_parameters) { ... } ⇒ EventHandler
Schedules block to execute at specified position.
Delegated from Musa::Sequencer::Sequencer::DSLContext#at.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 227
|
#beats_per_bar ⇒ Integer?
Returns beats per bar (time signature numerator).
Delegated from BaseSequencer#beats_per_bar.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 62
|
#before_tick { ... } ⇒ Object
Registers handler called before each tick.
Delegated from BaseSequencer#before_tick.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 132
|
#debug ⇒ Boolean
Returns or enables debug mode.
Delegated from Musa::Sequencer::Sequencer::DSLContext#debug.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 210
|
#empty? ⇒ Boolean
Checks if sequencer has no scheduled events.
Delegated from BaseSequencer#empty?.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 104
|
#event_handler ⇒ EventHandler
Returns the event handler for launch/on events.
Delegated from BaseSequencer#event_handler.
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 175 def_delegators :@sequencer, :beats_per_bar, :ticks_per_beat, :ticks_per_bar, :tick_duration, :offset, :size, :empty?, :on_debug_at, :on_error, :on_fast_forward, :before_tick, :raw_at, :tick, :reset, :position=, :event_handler |
#every(interval, duration: nil, till: nil, **options) { ... } ⇒ EveryControl
Executes block repeatedly at interval.
Delegated from Musa::Sequencer::Sequencer::DSLContext#every.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 271
|
#everying ⇒ EveryingControl
Returns control for active every loops.
Delegated from Musa::Sequencer::Sequencer::DSLContext#everying.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 296
|
#launch(event_name, *parameters, **key_parameters) ⇒ void
This method returns an undefined value.
Triggers an event by name.
Delegated from Musa::Sequencer::Sequencer::DSLContext#launch.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 317
|
#logger ⇒ Logger?
Returns the sequencer's logger instance.
Delegated from Musa::Sequencer::Sequencer::DSLContext#logger.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 203
|
#move(from: nil, to: nil, duration: nil, step: nil, **options) {|value| ... } ⇒ MoveControl
Interpolates values over time.
Delegated from Musa::Sequencer::Sequencer::DSLContext#move.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 283
|
#moving ⇒ MovingControl
Returns control for active move interpolations.
Delegated from Musa::Sequencer::Sequencer::DSLContext#moving.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 310
|
#now(*value_parameters, **key_parameters) { ... } ⇒ EventHandler
Executes block immediately at current position.
Delegated from Musa::Sequencer::Sequencer::DSLContext#now.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 217
|
#offset ⇒ Rational?
Returns the sequencer's starting position offset.
Delegated from BaseSequencer#offset.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 90
|
#on(event_name) { ... } ⇒ void
This method returns an undefined value.
Registers handler for named event.
Delegated from Musa::Sequencer::Sequencer::DSLContext#on.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 327
|
#on_debug_at { ... } ⇒ Object
Registers debug handler for specific position.
Delegated from BaseSequencer#on_debug_at.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 111
|
#on_error {|Exception| ... } ⇒ Object
Registers error handler for sequencer errors.
Delegated from BaseSequencer#on_error.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 118
|
#on_fast_forward { ... } ⇒ Object
Registers handler called during fast-forward operations.
Delegated from BaseSequencer#on_fast_forward.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 125
|
#play(serie, decoder: nil, mode: nil, **options) {|element| ... } ⇒ PlayControl
Plays a series using the decoder.
Delegated from Musa::Sequencer::Sequencer::DSLContext#play.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 249
|
#play_timed(timed_serie, **options) {|element, duration| ... } ⇒ PlayControl
Plays a timed series with explicit timing.
Delegated from Musa::Sequencer::Sequencer::DSLContext#play_timed.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 261
|
#playing ⇒ PlayingControl
Returns control for active play operations.
Delegated from Musa::Sequencer::Sequencer::DSLContext#playing.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 303
|
#position ⇒ Rational
Returns current sequencer position in bars.
Delegated from Musa::Sequencer::Sequencer::DSLContext#position.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 186
|
#position=(value) ⇒ void
This method returns an undefined value.
Sets the current sequencer position.
Delegated from BaseSequencer#position=.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 161
|
#quantize_position(reference, step, offset: nil) ⇒ Rational
Quantizes a position to a grid.
Delegated from Musa::Sequencer::Sequencer::DSLContext#quantize_position.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 193
|
#raw_at(position) { ... } ⇒ Object
Schedules block at position without DSL context wrapping.
Delegated from BaseSequencer#raw_at.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 139
|
#reset ⇒ void
This method returns an undefined value.
Resets sequencer to initial state.
Delegated from BaseSequencer#reset.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 154
|
#run ⇒ void
This method returns an undefined value.
Runs the sequencer until all events complete.
Delegated from Musa::Sequencer::Sequencer::DSLContext#run.
342 |
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 342 def_delegators :@dsl, :position, :quantize_position, :logger, :debug |
#size ⇒ Integer
Returns number of scheduled events.
Delegated from BaseSequencer#size.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 97
|
#tick ⇒ void
This method returns an undefined value.
Advances sequencer by one tick and processes events.
Delegated from BaseSequencer#tick.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 147
|
#tick_duration ⇒ Rational?
Returns duration of a single tick.
Delegated from BaseSequencer#tick_duration.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 83
|
#ticks_per_bar ⇒ Integer?
Returns total ticks per bar.
Delegated from BaseSequencer#ticks_per_bar.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 76
|
#ticks_per_beat ⇒ Integer?
Returns ticks per beat (timing resolution).
Delegated from BaseSequencer#ticks_per_beat.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 69
|
#wait(duration, *value_parameters, **key_parameters) { ... } ⇒ EventHandler
Schedules block after waiting specified duration.
Delegated from Musa::Sequencer::Sequencer::DSLContext#wait.
|
|
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 238
|
#with(*value_parameters, **key_parameters) { ... } ⇒ Object
Evaluates block in DSL context.
Provides with method for evaluating blocks with DSL context access.
The block is executed in the DSL context, giving it direct access to
sequencer methods like at, wait, play, every, move without needing to
reference the sequencer object.
458 459 460 |
# File 'lib/musa-dsl/sequencer/sequencer-dsl.rb', line 458 def with(*value_parameters, **key_parameters, &block) @dsl.with(*value_parameters, **key_parameters, &block) end |