Module: AlsaRawMIDI::API::Output

Defined in:
lib/alsa-rawmidi/api.rb

Overview

Wrapper for ALSA methods dealing with output

Class Method Summary collapse

Class Method Details

.open(id) ⇒ Integer

Open the output with the given ID

Parameters:

  • id (Integer)

Returns:

  • (Integer)


289
290
291
292
293
# File 'lib/alsa-rawmidi/api.rb', line 289

def open(id)
  API::Device.open(id) do |pointer|
    API.snd_rawmidi_open(nil, pointer, id, 0)
  end
end

.puts(handle, data) ⇒ Boolean

Send the given MIDI data to the output with the given handle

Parameters:

  • handle (Integer)
  • data (Array<Integer>)

Returns:

  • (Boolean)


276
277
278
279
280
281
282
283
284
# File 'lib/alsa-rawmidi/api.rb', line 276

def puts(handle, data)
  format = 'C' * data.size
  pointer = FFI::MemoryPointer.new(data.size)
  bytes = pointer.put_bytes(0, data.pack(format))

  API.snd_rawmidi_write(handle, bytes.to_i, data.size)
  API.snd_rawmidi_drain(handle)
  true
end