Class: Musa::Series::Constructors::FromArray Private
- Includes:
- Serie::Base
- Defined in:
- lib/musa-dsl/series/main-serie-constructors.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 constructor that creates a serie from an array of values.
Iterates through array elements, returning nil when exhausted. Supports optional module extensions for enhanced functionality.
Instance Attribute Summary collapse
- #values ⇒ Object private
Instance Method Summary collapse
-
#+(other) ⇒ Sequence
included
from Operations
Appends another serie (operator alias for after).
-
#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.
-
#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.
-
#initialize(values = nil, extends = nil) ⇒ FromArray
constructor
private
A new instance of FromArray.
-
#instance ⇒ 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.
-
#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(values = nil, extends = nil) ⇒ FromArray
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 FromArray.
537 538 539 540 541 542 543 544 545 546 547 |
# File 'lib/musa-dsl/series/main-serie-constructors.rb', line 537 def initialize(values = nil, extends = nil) @values = values mark_as_prototype! x = self extends.arrayfy.each do |e| x.extend(e) end init end |
Instance Attribute Details
#values ⇒ Object
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.
549 550 551 |
# File 'lib/musa-dsl/series/main-serie-constructors.rb', line 549 def values @values end |
Instance Method Details
#+(other) ⇒ Sequence Originally defined in module Operations
Appends another serie (operator alias for after).
#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
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.
#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
composer do
input_name >> operation1 >> operation2 >> :output_name
:other_input >> transform >> :other_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 serie of arrays, each containing length values.
#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.
#instance ⇒ 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.
#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)