Class: StepSequencer::SoundBuilder::DefaultEffects::Scale

Inherits:
Object
  • Object
show all
Defined in:
lib/step_sequencer/sound_builder/default_effects/scale.rb

Constant Summary collapse

Scales =

Each returns an array of floats, representing pitch change from original

{
  equal_temperament: begin
    twelth_root_of_two = "2 ** (1 / 12)".rational_eval
    1.upto(12).reduce([twelth_root_of_two]) do |memo|
      memo.concat([memo[-1] * twelth_root_of_two])
    end
  end
}

Class Method Summary collapse

Class Method Details

.build(sources:, scale:, inverse: false, speed_correction: true) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/step_sequencer/sound_builder/default_effects/scale.rb', line 19

def self.build(sources:, scale:, inverse: false, speed_correction: true)
  pitch_changes = Scales.fetch(scale).yield_self do |notes|
    inverse ? notes.map(&Rational(1).method(:/)) : notes
  end
  sources.map do |source|
    pitch_changes.flat_map do |pitch_change|
      builder.build(
        sources: [source],
        effect: :Pitch,
        args: [value: pitch_change, speed_correction: speed_correction]
      )
    end
  end
end