Class: Ramekin::RestAggregator

Inherits:
Processor show all
Defined in:
lib/ramekin/note_aggregator.rb

Instance Attribute Summary

Attributes inherited from Processor

#stream

Instance Method Summary collapse

Methods inherited from Processor

#buffer, call, compose, #each, #next!, #peek

Instance Method Details

#call(&b) ⇒ Object



265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/ramekin/note_aggregator.rb', line 265

def call(&b)
  each do |evt|
    if NoteEvent === evt && evt.rest?
      buffer << evt
      next
    end

    flush!(&b)
    yield evt
  end

  flush!(&b)
end

#flush! {|CombinedRestEvent.new(buffer)| ... } ⇒ Object

Yields:



259
260
261
262
263
# File 'lib/ramekin/note_aggregator.rb', line 259

def flush!(&b)
  return if buffer.empty?
  yield CombinedRestEvent.new(buffer)
  @buffer = []
end