Module: AlsaRawMIDI::API::Output

Extended by:
Output
Included in:
Output
Defined in:
lib/alsa-rawmidi/api.rb

Overview

Wrapper for ALSA methods dealing with output

Instance Method Summary collapse

Instance Method Details

#open(id) ⇒ Fixnum

Open the output with the given ID

Parameters:

  • id (Fixnum)

Returns:

  • (Fixnum)


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

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 (Fixnum)
  • data (Array<Fixnum>)

Returns:

  • (Boolean)


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

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