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
youpy-scissor-0.0.20 lib/scissor/sequence.rb
youpy-scissor-0.0.21 lib/scissor/sequence.rb
scissor-0.6.0 lib/scissor/sequence.rb
scissor-0.5.0 lib/scissor/sequence.rb
scissor-0.4.0 lib/scissor/sequence.rb
scissor-0.3.0 lib/scissor/sequence.rb
scissor-0.2.9 lib/scissor/sequence.rb
scissor-0.2.8 lib/scissor/sequence.rb
scissor-0.2.7 lib/scissor/sequence.rb
scissor-0.2.6 lib/scissor/sequence.rb
scissor-0.2.5 lib/scissor/sequence.rb
scissor-0.2.4 lib/scissor/sequence.rb
scissor-0.2.3 lib/scissor/sequence.rb
scissor-0.2.2 lib/scissor/sequence.rb
scissor-0.2.1 lib/scissor/sequence.rb
scissor-0.2.0 lib/scissor/sequence.rb
scissor-0.1.2 lib/scissor/sequence.rb
scissor-0.1.1 lib/scissor/sequence.rb
scissor-0.1.0 lib/scissor/sequence.rb
scissor-0.0.26 lib/scissor/sequence.rb