Class: Portmidi::Input
- Inherits:
-
Object
- Object
- Portmidi::Input
- Defined in:
- lib/portmidi/input.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(device_id, buffer_size = 512) ⇒ Input
constructor
A new instance of Input.
- #poll ⇒ Object
- #read(buffer_size = 1) ⇒ Object
Constructor Details
#initialize(device_id, buffer_size = 512) ⇒ Input
Returns a new instance of Input.
3 4 5 6 7 8 9 10 |
# File 'lib/portmidi/input.rb', line 3 def initialize(device_id, buffer_size = 512) in_stream_ptr = FFI::MemoryPointer.new(:pointer) if (errnum = PM_Map.Pm_OpenInput(in_stream_ptr, device_id, nil, buffer_size, nil, nil)) == 0 @in_stream = in_stream_ptr.read_pointer else raise "Could not open Device #{device_id} as output device" end end |
Instance Method Details
#close ⇒ Object
12 13 14 |
# File 'lib/portmidi/input.rb', line 12 def close PM_Map.Pm_Close(@in_stream) end |
#poll ⇒ Object
16 17 18 |
# File 'lib/portmidi/input.rb', line 16 def poll PM_Map.Pm_Poll(@in_stream) != 0 end |
#read(buffer_size = 1) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/portmidi/input.rb', line 20 def read(buffer_size = 1) event_pointer = FFI::MemoryPointer.new(PM_Map::Event, buffer_size) read = PM_Map::Pm_Read(@in_stream, event_pointer, buffer_size); if read > 0 events = [] read.times do |i| events << parseEvent(PM_Map::Event.new(event_pointer[i])) end return events elsif read < 0 raise DeviceError, read, "read failed" else return nil end end |