class MIDIEye::Source
Retrieves new messages from a unimidi input buffer
Attributes
device[R]
pointer[R]
Public Class Methods
compatible?(input)
click to toggle source
Whether the given object is a UniMIDI input @param [Object] input @return [Boolean]
# File lib/midi-eye/source.rb, line 11 def self.compatible?(input) input.respond_to?(:gets) && input.respond_to?(:buffer) end
new(input)
click to toggle source
@param [UniMIDI::Input] input
# File lib/midi-eye/source.rb, line 16 def initialize(input) @parser = Nibbler.new @pointer = 0 @device = input end
Public Instance Methods
poll() { |objects| ... }
click to toggle source
Grabs new messages from the input buffer
# File lib/midi-eye/source.rb, line 23 def poll(&block) messages = @device.buffer.slice(@pointer, @device.buffer.length - @pointer) @pointer = @device.buffer.length messages.compact.each do |raw_message| parsed_messages = begin @parser.parse(raw_message[:data], :timestamp => raw_message[:timestamp]) rescue nil end objects = [parsed_messages].flatten.compact yield(objects) end end
uses?(input)
click to toggle source
If this source was created from the given input @param [UniMIDI::Input] input @return [Boolean]
# File lib/midi-eye/source.rb, line 40 def uses?(input) @device == input end