Class: MIDIEye::Source
- Inherits:
-
Object
- Object
- MIDIEye::Source
- Defined in:
- lib/midi-eye/source.rb
Overview
Retrieves new messages from a unimidi input buffer
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#pointer ⇒ Object
readonly
Returns the value of attribute pointer.
Class Method Summary collapse
-
.compatible?(input) ⇒ Boolean
Whether the given object is a UniMIDI input.
Instance Method Summary collapse
-
#initialize(input) ⇒ Source
constructor
A new instance of Source.
-
#poll(&block) ⇒ Object
Grabs new messages from the input buffer.
-
#uses?(input) ⇒ Boolean
If this source was created from the given input.
Constructor Details
#initialize(input) ⇒ Source
16 17 18 19 20 |
# File 'lib/midi-eye/source.rb', line 16 def initialize(input) @parser = Nibbler.new @pointer = 0 @device = input end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
6 7 8 |
# File 'lib/midi-eye/source.rb', line 6 def device @device end |
#pointer ⇒ Object (readonly)
Returns the value of attribute pointer.
6 7 8 |
# File 'lib/midi-eye/source.rb', line 6 def pointer @pointer end |
Class Method Details
.compatible?(input) ⇒ Boolean
Whether the given object is a UniMIDI input
11 12 13 |
# File 'lib/midi-eye/source.rb', line 11 def self.compatible?(input) input.respond_to?(:gets) && input.respond_to?(:buffer) end |
Instance Method Details
#poll(&block) ⇒ Object
Grabs new messages from the input buffer
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/midi-eye/source.rb', line 23 def poll(&block) = @device.buffer.slice(@pointer, @device.buffer.length - @pointer) @pointer = @device.buffer.length .compact.each do || = begin @parser.parse([:data], :timestamp => [:timestamp]) rescue nil end objects = [].flatten.compact yield(objects) end end |
#uses?(input) ⇒ Boolean
If this source was created from the given input
40 41 42 |
# File 'lib/midi-eye/source.rb', line 40 def uses?(input) @device == input end |