Sha256: 9f553c374fbc40f523437e2249f8e41fd6ce383bff4f46d8778706b453f7b4b0

Contents?: true

Size: 789 Bytes

Versions: 24

Compression:

Stored size: 789 Bytes

Contents

module Scissor
  class Sequence
    def initialize(pattern, duration_per_step)
      @pattern = pattern
      @duration_per_step = duration_per_step
    end

    def apply(instruments)
      @pattern.split(//).inject(Scissor()) do |result, c|
        if instruments.include?(c.to_sym)
          instrument = instruments[c.to_sym]

          if instrument.is_a?(Proc)
            instrument = instrument.call(c)
          end

          if @duration_per_step > instrument.duration
            result += instrument + Scissor.silence(@duration_per_step - instrument.duration)
          else
            result += instrument.slice(0, @duration_per_step)
          end
        else
          result += Scissor.silence(@duration_per_step)
        end

        result
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
scissor-0.0.25 lib/scissor/sequence.rb
scissor-0.0.24 lib/scissor/sequence.rb
scissor-0.0.23 lib/scissor/sequence.rb
scissor-0.0.22 lib/scissor/sequence.rb