Class: Scissor::Sequence
- Inherits:
-
Object
- Object
- Scissor::Sequence
- Defined in:
- lib/scissor/sequence.rb
Instance Method Summary collapse
- #apply(instruments) ⇒ Object
-
#initialize(pattern, duration_per_step) ⇒ Sequence
constructor
A new instance of Sequence.
Constructor Details
#initialize(pattern, duration_per_step) ⇒ Sequence
Returns a new instance of Sequence.
3 4 5 6 |
# File 'lib/scissor/sequence.rb', line 3 def initialize(pattern, duration_per_step) @pattern = pattern @duration_per_step = duration_per_step end |
Instance Method Details
#apply(instruments) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/scissor/sequence.rb', line 8 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 |