module AlsaRawMIDI::API::Device

Wrapper for ALSA methods dealing with devices

Public Instance Methods

close(handle) click to toggle source

Close the device with the given handle @param [Integer] handle @return [Boolean]

# File lib/alsa-rawmidi/api.rb, line 322
def close(handle)
  API.snd_rawmidi_drain(handle)
  API.snd_rawmidi_close(handle)
  true
end
get_info(id, direction) click to toggle source

@param [Integer] id @param [Symbol] direction @return [SndCtlCardInfo]

# File lib/alsa-rawmidi/api.rb, line 307
def get_info(id, direction)
  stream_key = case direction
  when :input then :SND_RAWMIDI_STREAM_INPUT
  when :output then :SND_RAWMIDI_STREAM_OUTPUT
  end
  stream = API::CONSTANTS[stream_key]
  info = API::SndRawMIDIInfo.new
  API.snd_rawmidi_info_set_device(info.pointer, id)
  API.snd_rawmidi_info_set_stream(info.pointer, stream)
  info
end
open(id) { |handle_pointer| ... } click to toggle source

Open the device with the given id @param [Integer] id @param [Proc] block @return [Integer]

# File lib/alsa-rawmidi/api.rb, line 332
def open(id, &block)
  handle_pointer = FFI::MemoryPointer.new(FFI.type_size(:int))
  yield(handle_pointer)
  handle_pointer.read_int
end