Class: Musa::Series::Constructors::QueueSerie Private
- Includes:
- Serie::Base, Serie::WithSources
- Defined in:
- lib/musa-dsl/series/queue-serie.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.
Serie that processes multiple source series in queue/sequence fashion.
Combines multiple series by playing them sequentially - when one
series exhausts, moves to the next. New series can be added dynamically
with << operator.
All queued series must be instances (not prototypes). The queue can
be cleared with clear method.
Instance Method Summary collapse
-
#+(other) ⇒ Sequence
included
from Operations
Appends another serie (operator alias for after).
-
#<<(serie) ⇒ self
private
Adds serie to queue.
-
#after(*series) ⇒ Sequence
included
from Operations
Appends series sequentially.
-
#anticipate {|current, next_value| ... } ⇒ Anticipate
included
from Operations
Evaluates block one step ahead (anticipate).
-
#autorestart ⇒ Autorestart
included
from Operations
Auto-restarts serie when exhausted.
-
#buffered(sync: false) ⇒ BufferSerie, SyncBufferSerie
included
from Operations
Creates a buffered serie allowing multiple independent iterations over same source.
-
#clear ⇒ self
private
Clears all series from queue.
-
#compact_timed ⇒ TimedCompacter
included
from Operations
Removes timed events where all values are nil.
-
#composer { ... } ⇒ ComposerAsOperationSerie
included
from Operations
Creates a composer transformation pipeline for complex multi-stage transformations.
-
#cut(length) ⇒ Cutter
included
from Operations
Cuts serie into chunks of specified length.
-
#defined? ⇒ Boolean
included
from Serie::Prototyping
Checks if serie state is defined (not undefined).
-
#flatten ⇒ Flattener
included
from Operations
Flattens nested series into single level.
-
#flatten_timed ⇒ TimedFlattener
included
from Operations
Splits compound timed values into individual timed events.
-
#hashify(*keys) ⇒ HashFromSeriesArray
included
from Operations
Converts array values to hash with specified keys.
- #infinite? ⇒ Boolean private
-
#initialize(series) ⇒ QueueSerie
constructor
private
A new instance of QueueSerie.
-
#instance(built = nil) ⇒ Serie
(also: #i)
included
from Serie::Prototyping
Creates or returns instance of serie.
-
#instance? ⇒ Boolean
included
from Serie::Prototyping
Checks if serie is in instance state.
-
#lazy {|previous| ... } ⇒ LazySerieEval
included
from Operations
Delays evaluation to next step (lazy evaluation).
-
#lock ⇒ Locker
included
from Operations
Locks serie preventing further modifications.
-
#map(isolate_values: nil) {|value| ... } ⇒ ProcessWith
included
from Operations
Maps values via transformation block.
-
#max_size(length) ⇒ LengthLimiter
included
from Operations
Limits serie to maximum number of values.
-
#merge ⇒ MergeSerieOfSeries
included
from Operations
Merges serie of series into single serie.
-
#multiplex(*indexed_series, **hash_series) ⇒ MultiplexSelector
included
from Operations
Multiplexes values from multiple series based on selector.
-
#process_with(**parameters) {|value, parameters| ... } ⇒ Processor
included
from Operations
Processes values with parameterized block.
-
#prototype ⇒ Serie
(also: #p)
included
from Serie::Prototyping
Returns prototype of serie.
-
#prototype? ⇒ Boolean
included
from Serie::Prototyping
Checks if serie is in prototype state.
-
#proxy ⇒ Object
included
from Operations
TODO add test case.
-
#quantize(reference: nil, step: nil, value_attribute: nil, stops: nil, predictive: nil, left_open: nil, right_open: nil) ⇒ RawQuantizer, PredictiveQuantizer
included
from Operations
Quantizes time-value serie to discrete steps.
-
#queued ⇒ QueueSerie
included
from Operations
Wraps this serie in a queue.
-
#randomize(random: nil) ⇒ Randomizer
included
from Operations
Randomizes order of values.
-
#remove(block = nil) {|value| ... } ⇒ Remover
included
from Operations
Removes values matching condition.
-
#repeat(times = nil, condition: nil) { ... } ⇒ Repeater, InfiniteRepeater
included
from Operations
Repeats serie multiple times or conditionally.
-
#reverse ⇒ Reverser
included
from Operations
Reverses order of values.
-
#select(block = nil) {|value| ... } ⇒ Selector
included
from Operations
Selects values matching condition.
-
#shift(shift) ⇒ Shifter
included
from Operations
Rotates serie elements circularly.
-
#skip(length) ⇒ Skipper
included
from Operations
Skips first N values.
-
#sources ⇒ Array<Serie>, ...
included
from Serie::WithSources
Upstream source series.
-
#sources=(series) ⇒ Object
included
from Serie::WithSources
Sets the sources series.
-
#split ⇒ Splitter
included
from Operations
Serie splitter for decomposing hash/array values into component series.
-
#state ⇒ Symbol
included
from Serie::Prototyping
Returns current state of serie.
-
#switch(*indexed_series, **hash_series) ⇒ Switcher
included
from Operations
Switches between multiple series based on selector values.
-
#switch_serie(*indexed_series, **hash_series) ⇒ SwitchFullSerie
included
from Operations
Switches to entirely different series based on selector.
-
#undefined? ⇒ Boolean
included
from Serie::Prototyping
Checks if serie is in undefined state.
-
#union_timed(*other_timed_series, key: nil, **other_key_timed_series) ⇒ TimedUnionOfArrayOfTimedSeries, TimedUnionOfHashOfTimedSeries
included
from Operations
Combines this timed serie with others via TIMED_UNION.
-
#with(*with_series, on_restart: nil, isolate_values: nil, **with_key_series) {|main_value, with_values, with_key_values| ... } ⇒ With
(also: #eval)
included
from Operations
Combines multiple series for mapping.
Constructor Details
#initialize(series) ⇒ QueueSerie
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 a new instance of QueueSerie.
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/musa-dsl/series/queue-serie.rb', line 91 def initialize(series) self.sources = series # A queue with nothing in it yet is not undecided: it is a queue waiting # for material. Resolving it from its sources gives :undefined -- there # is nothing to ask -- and an undefined serie cannot be instantiated, # which leaves exactly the case the queue exists for out of reach. So an # empty queue is a prototype, like every other freshly built serie, and # the material arrives on its instance (`<<` only takes instances). mark_as_prototype! if @sources.empty? init end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, **key_args, &block) ⇒ Object (private)
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.
172 173 174 175 176 177 178 |
# File 'lib/musa-dsl/series/queue-serie.rb', line 172 private def method_missing(method_name, *args, **key_args, &block) if @current&.respond_to?(method_name) @current.send method_name, *args, **key_args, &block else super end end |
Instance Method Details
#+(other) ⇒ Sequence Originally defined in module Operations
Appends another serie (operator alias for after).
#<<(serie) ⇒ self
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.
Adds serie to queue.
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/musa-dsl/series/queue-serie.rb', line 113 def <<(serie) # Material is queued on an instance: a prototype is the template every # instance is built from, and putting one instance inside it would give # all of them the same serie to consume. # raise ArgumentError, "Only an instance queue can be fed" unless instance? raise ArgumentError, "Only an instance serie can be queued" unless serie.instance? @sources << serie @current ||= @sources[@index] self end |
#after(*series) ⇒ Sequence Originally defined in module Operations
Appends series sequentially.
Alias for MERGE - plays this serie, then others in sequence.
#anticipate {|current, next_value| ... } ⇒ Anticipate Originally defined in module Operations
Evaluates block one step ahead (anticipate).
Block receives current value and NEXT value (peeked). Enables look-ahead transformations and transitions.
#autorestart ⇒ Autorestart Originally defined in module Operations
The serie ENDS at each pass -- yielding nil -- and restarts on the
next call. That nil is the signal that a pass finished, which is what
makes the repetition countable; it also means infinite? is false and
that to_a stops at the end of the first pass. For a serie with no
seam in it, use repeat.
Auto-restarts serie when exhausted.
Creates an infinite serie from an original serie that automatically restarts from beginning when it reaches the end.
#buffered(sync: false) ⇒ BufferSerie, SyncBufferSerie Originally defined in module Operations
Creates a buffered serie allowing multiple independent iterations over same source.
Provides buffering mechanism enabling multiple "readers" to independently iterate over the same serie source without interfering with each other.
Buffering Modes
- Async (default): Buffers fill independently, each progresses at own pace
- Sync: All buffers synchronized, restart affects all
Use Cases
- Multiple voices reading same melodic sequence at different speeds
- Polyphonic playback from single source
- Canonic structures (rounds, fugues)
- Independent transformations of same base material
Memory Management
History is automatically cleaned when all buffers have progressed past old values, preventing unbounded memory growth.
#clear ⇒ self
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.
Clears all series from queue.
130 131 132 133 134 |
# File 'lib/musa-dsl/series/queue-serie.rb', line 130 def clear @sources.clear init self end |
#compact_timed ⇒ TimedCompacter Originally defined in module Operations
Removes timed events where all values are nil.
Filters out temporal "gaps" where no sources have active values. Useful after union operations that create nil placeholders, or for cleaning sparse sequences.
Removal logic:
- Direct nil:
{ time: t, value: nil }→ removed - All-nil Hash:
{ time: t, value: { a: nil, b: nil } }→ removed - Partial Hash:
{ time: t, value: { a: 1, b: nil } }→ kept (has non-nil) - All-nil Array:
{ time: t, value: [nil, nil] }→ removed - Partial Array:
{ time: t, value: [1, nil] }→ kept (has non-nil)
#composer { ... } ⇒ ComposerAsOperationSerie Originally defined in module Operations
Creates a composer transformation pipeline for complex multi-stage transformations.
Composer provides declarative DSL for building transformation pipelines with multiple inputs, outputs, and intermediate processing stages.
Composer Concepts
- Pipelines: Named transformation chains
- Inputs: Named input series (proxied and buffered)
- Outputs: Named output series
- Operations: Transformation steps in pipeline
- Auto-commit: Automatic finalization of pipelines
DSL Structure
A pipeline is declared by NAMING it and listing its operations; the names
are then wired together with route. Operations are symbols (reverse)
or hashes ({ map: ... }, { skip: 1 }, { S: [...] }). input and
output are pipelines like any other — they are simply the ones the
Composer creates for you, and can be renamed or multiplied through the
inputs: and outputs: keywords.
composer do
stage1 operation1, operation2
stage2 operation3
route input, to: stage1
route stage1, to: stage2
route stage2, to: output
end
Musical Applications
- Complex multi-voice processing
- Effect chains and routing
- Algorithmic composition pipelines
- Multi-stage transformations
- Modular synthesis-style routing
#cut(length) ⇒ Cutter Originally defined in module Operations
Cuts serie into chunks of specified length.
Returns a serie of SERIES, each yielding length values.
The chunks are series and not arrays, which is what keeps the whole thing
lazy -- nothing is materialised until each chunk is consumed. Ask for the
arrays explicitly with to_a(recursive: true).
#defined? ⇒ Boolean Originally defined in module Serie::Prototyping
Checks if serie state is defined (not undefined).
#flatten ⇒ Flattener Originally defined in module Operations
Flattens nested series into single level.
Recursively consumes series elements that are themselves series.
#flatten_timed ⇒ TimedFlattener Originally defined in module Operations
Splits compound timed values into individual timed events.
Converts events with Hash or Array values into separate timed events per element, preserving time and extra attributes. Direct values pass through unchanged.
Hash values → Hash of timed events (keyed by original keys):
{ time: 0, value: { a: 1, b: 2 }, velocity: { a: 80, b: 90 } }
# becomes:
{ a: { time: 0, value: 1, velocity: 80 },
b: { time: 0, value: 2, velocity: 90 } }
Array values → Array of timed events (indexed):
{ time: 0, value: [1, 2], velocity: [80, 90] }
# becomes:
[{ time: 0, value: 1, velocity: 80 },
{ time: 0, value: 2, velocity: 90 }]
Direct values → Pass through unchanged (already flat)
Use Cases
- Separate polyphonic events into individual voices
- Split multi-track sequences for independent processing
- Prepare for voice-specific routing via
split - Enable per-voice filtering with
compact_timed
#hashify(*keys) ⇒ HashFromSeriesArray Originally defined in module Operations
Converts array values to hash with specified keys.
Takes array-valued serie and converts to hash using provided keys.
#infinite? ⇒ Boolean
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.
162 163 164 |
# File 'lib/musa-dsl/series/queue-serie.rb', line 162 def infinite? !!@sources.find(&:infinite?) end |
#instance(built = nil) ⇒ Serie Also known as: i Originally defined in module Serie::Prototyping
Creates or returns instance of serie.
- If already instance, returns self
- If prototype, creates new instance by cloning
- If undefined, raises PrototypingError
Cloning Process
- Clones serie structure
- Marks clone as :instance
- Propagates instance creation to sources
- Calls init if defined
Each call creates independent instance with separate state.
#instance? ⇒ Boolean Originally defined in module Serie::Prototyping
Checks if serie is in instance state.
#lazy {|previous| ... } ⇒ LazySerieEval Originally defined in module Operations
Delays evaluation to next step (lazy evaluation).
Block receives previous value and evaluates for current step. Enables state-dependent transformations.
#lock ⇒ Locker Originally defined in module Operations
Locks serie preventing further modifications.
Returns locked copy that cannot be transformed further.
#map(isolate_values: nil) {|value| ... } ⇒ ProcessWith Originally defined in module Operations
Maps values via transformation block.
Simplest and most common transformation. Applies block to each value.
Shorthand for with without additional series.
#max_size(length) ⇒ LengthLimiter Originally defined in module Operations
Limits serie to maximum number of values.
Stops after N values regardless of source length.
#merge ⇒ MergeSerieOfSeries Originally defined in module Operations
Merges serie of series into single serie.
Flattens one level: consumes serie where each element is itself a serie, merging them sequentially.
#multiplex(*indexed_series, **hash_series) ⇒ MultiplexSelector Originally defined in module Operations
Multiplexes values from multiple series based on selector.
Like switch but returns composite values instead of switching.
#process_with(**parameters) {|value, parameters| ... } ⇒ Processor Originally defined in module Operations
Processes values with parameterized block.
Generic processor passing values and parameters to block.
#prototype ⇒ Serie Also known as: p Originally defined in module Serie::Prototyping
Returns prototype of serie.
- If already prototype, returns self
- If instance, returns original prototype (if available)
- If undefined, raises PrototypingError
#prototype? ⇒ Boolean Originally defined in module Serie::Prototyping
Checks if serie is in prototype state.
#proxy ⇒ Object Originally defined in module Operations
TODO add test case
#quantize(reference: nil, step: nil, value_attribute: nil, stops: nil, predictive: nil, left_open: nil, right_open: nil) ⇒ RawQuantizer, PredictiveQuantizer Originally defined in module Operations
Quantizes time-value serie to discrete steps.
Quantization Modes
- Raw: Rounds values to nearest step, interpolates between points
- Predictive: Predicts crossings of quantization boundaries
Applications
- Quantize MIDI controller data to discrete values
- Convert continuous pitch bends to semitones
- Snap timing to grid
- Generate stepped automation curves
- Convert analog input to digital steps
#queued ⇒ QueueSerie Originally defined in module Operations
Wraps this serie in a queue.
#randomize(random: nil) ⇒ Randomizer Originally defined in module Operations
Randomizes order of values.
Shuffles values randomly. Requires finite serie.
#remove(block = nil) {|value| ... } ⇒ Remover Originally defined in module Operations
Removes values matching condition.
Filters out values where block returns true.
#repeat(times = nil, condition: nil) { ... } ⇒ Repeater, InfiniteRepeater Originally defined in module Operations
Repeats serie multiple times or conditionally.
Three modes:
- times: Repeat exact number of times
- condition: Repeat while condition true
- neither: Infinite repetition
#reverse ⇒ Reverser Originally defined in module Operations
Reverses order of values.
Consumes entire serie and returns values in reverse order. Requires finite serie.
#select(block = nil) {|value| ... } ⇒ Selector Originally defined in module Operations
Selects values matching condition.
Keeps only values where block returns true.
#shift(shift) ⇒ Shifter Originally defined in module Operations
Rotates serie elements circularly.
Performs circular rotation of elements:
- Negative values rotate left (first elements move to end)
- Positive values rotate right (last elements move to beginning)
- Zero performs no rotation
Note: Right rotation (positive values) requires finite series as the entire serie must be loaded into memory for rotation.
#skip(length) ⇒ Skipper Originally defined in module Operations
Skips first N values.
Discards first length values, returns rest.
#sources ⇒ Array<Serie>, ... Originally defined in module Serie::WithSources
Returns upstream source series.
#sources=(series) ⇒ Object Originally defined in module Serie::WithSources
Sets the sources series.
#split ⇒ Splitter Originally defined in module Operations
Serie splitter for decomposing hash/array values into component series.
Splits series of hash or array values into individual component series, enabling independent access to each component.
Splitting Modes
- Hash mode: Split
{pitch: 60, velocity: 96}into separate series for:pitchand:velocity - Array mode: Split
[60, 96]into separate series for indices 0, 1
Component Access
- Hash:
splitter[:pitch],splitter[:velocity] - Array:
splitter[0],splitter[1] - Enumerable:
splitter.each { |component| ... }
Use Cases
- Separate polyphonic voices from single source
- Independent processing of musical parameters
- Extract specific components (pitch, duration, velocity, etc.)
- Multi-track decomposition
#state ⇒ Symbol Originally defined in module Serie::Prototyping
Returns current state of serie.
Attempts to resolve undefined state from sources before returning. State is one of: :prototype, :instance, or :undefined.
#switch(*indexed_series, **hash_series) ⇒ Switcher Originally defined in module Operations
Switches between multiple series based on selector values.
Uses selector serie to choose which source serie to read from. Selector values can be indices (Integer) or keys (Symbol).
#switch_serie(*indexed_series, **hash_series) ⇒ SwitchFullSerie Originally defined in module Operations
Switches to entirely different series based on selector.
Changes which serie is being consumed entirely.
#undefined? ⇒ Boolean Originally defined in module Serie::Prototyping
Checks if serie is in undefined state.
#union_timed(*other_timed_series, key: nil, **other_key_timed_series) ⇒ TimedUnionOfArrayOfTimedSeries, TimedUnionOfHashOfTimedSeries Originally defined in module Operations
Combines this timed serie with others via TIMED_UNION.
Convenience method for unioning series, supporting both array and hash modes. Calls Constructors#TIMED_UNION constructor with appropriate parameters.
Array mode: s1.union_timed(s2, s3)
Hash mode: s1.union_timed(key: :melody, bass: s2, drums: s3)
#with(*with_series, on_restart: nil, isolate_values: nil, **with_key_series) {|main_value, with_values, with_key_values| ... } ⇒ With Also known as: eval Originally defined in module Operations
Combines multiple series for mapping.
Synchronously iterates multiple series, passing all values to block. Enables multi-voice transformations and combinations.
Parameters
- with_series: Positional series (passed as array to block)
- with_key_series: Named series (passed as keywords to block)
- on_restart: Block called on restart
- isolate_values: Clone values to prevent mutation
Block Parameters
Block receives:
- Main serie value (first argument)
- Positional with_series values (array)
- Keyword with_key_series values (keywords)