Module: Musa::Extension::ExplodeRanges

Defined in:
lib/musa-dsl/core-ext/array-explode-ranges.rb

Overview

Note:

This refinement must be activated with using Musa::Extension::ExplodeRanges

Refinement that expands Range objects within arrays into their constituent elements.

This is particularly useful in musical contexts where arrays may contain both individual values and ranges (like MIDI note ranges or channel ranges), and you need to work with the fully expanded list.

Use Cases

  • Expanding MIDI channel specifications: [0, 2..4, 7] → [0, 2, 3, 4, 7]
  • Expanding note ranges in chord definitions
  • Processing mixed literal and range values in musical parameters
  • Any scenario where ranges need to be flattened for iteration

Methods Added

Array

Examples:

Basic usage

using Musa::Extension::ExplodeRanges

[1, 3..5, 8].explode_ranges
# => [1, 3, 4, 5, 8]

MIDI channels

using Musa::Extension::ExplodeRanges

channels = [0, 2..4, 7, 9..10]
channels.explode_ranges
# => [0, 2, 3, 4, 7, 9, 10]

Mixed with other array methods

using Musa::Extension::ExplodeRanges

[1..3, 5, 7..9].explode_ranges.map { |n| n * 2 }
# => [2, 4, 6, 10, 14, 16, 18]

See Also: