Module: AlsaRawMIDI::API::Input
Overview
Wrapper for ALSA methods dealing with input
Constant Summary collapse
- BUFFER_SIZE =
256
Instance Method Summary collapse
-
#open(id) ⇒ Fixnum
Open the output with the given ID.
-
#poll(handle) ⇒ String
Get the next bytes from the buffer.
Instance Method Details
#open(id) ⇒ Fixnum
Open the output with the given ID
246 247 248 249 250 |
# File 'lib/alsa-rawmidi/api.rb', line 246 def open(id) API::Device.open(id) do |pointer| API.snd_rawmidi_open(pointer, nil, id, API::CONSTANTS[:SND_RAWMIDI_NONBLOCK]) end end |
#poll(handle) ⇒ String
Get the next bytes from the buffer
254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/alsa-rawmidi/api.rb', line 254 def poll(handle) buffer = FFI::MemoryPointer.new(:uint8, BUFFER_SIZE) if (err = API.snd_rawmidi_read(handle, buffer, BUFFER_SIZE)) < 0 raise "Can't read MIDI input: #{API.snd_strerror(err)}" unless err.eql?(-11) end # Upon success, err is positive and equal to the number of bytes read # into the buffer. if err > 0 bytes = buffer.get_bytes(0,err).unpack("a*").first.unpack("H*") bytes.first.upcase end end |