Module: AlsaRawMIDI::API::Device

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

Overview

Wrapper for ALSA methods dealing with devices

Instance Method Summary collapse

Instance Method Details

#close(handle) ⇒ Boolean

Close the device with the given handle

Parameters:

  • handle (Fixnum)

Returns:

  • (Boolean)


322
323
324
325
326
# 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) ⇒ SndCtlCardInfo

Parameters:

  • id (Fixnum)
  • direction (Symbol)

Returns:



307
308
309
310
311
312
313
314
315
316
317
# 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, &block) {|handle_pointer| ... } ⇒ Fixnum

Open the device with the given id

Parameters:

  • id (Fixnum)
  • block (Proc)

Yields:

  • (handle_pointer)

Returns:

  • (Fixnum)


332
333
334
335
336
# 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