Class: Ramekin::Bends

Inherits:
Processor show all
Defined in:
lib/ramekin/bends.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



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/ramekin/bends.rb', line 167

def call(&b)
  each do |el|
    if NoteEvent === el && !el.rest?
      flush!(&b)
      @last_note = el
      el.meta[:bends] = []
    elsif Token === el && el.type == :amp
      next error! 'bend must be followed by a note' unless NoteEvent === peek
      next error! 'cannot bend to a rest' if peek.rest?
      next error! 'bend must come after a note' if @last_note.nil?

      to_note = next!

      if Bend === @last_note
        @last_note.notes << to_note
      else
        @last_note = Bend.new(@last_note, to_note)
      end
    else
      flush!(&b)
      yield el
    end
  end

  flush!(&b)
end

#flush! {|@last_note| ... } ⇒ Object

Yields:

  • (@last_note)


162
163
164
165
# File 'lib/ramekin/bends.rb', line 162

def flush!
  yield @last_note if @last_note
  @last_note = nil
end