module RawMIDI::API::Card

Public Class Methods

each_id() { |id| ... } click to toggle source
# File lib/rawmidi/api.rb, line 87
def self.each_id
  return enum_for(__method__) unless block_given?

  card_p = FFI::MemoryPointer.new(:int).write_int(-1)

  loop do
    status = API.snd_card_next(card_p)
    fail Error, API.snd_strerror(status) if status < 0
    id = card_p.read_int

    break if id < 0
    yield id
  end
end
get_longname(id) click to toggle source
# File lib/rawmidi/api.rb, line 131
def self.get_longname(id)
  name_pp = FFI::MemoryPointer.new(:pointer)
  status = API.snd_card_get_longname(id, name_pp)
  fail Error, API.snd_strerror(status) if status < 0

  name_p = name_pp.read_pointer
  name = name_p.read_string
  LibC.free(name_p)

  name
end
get_name(id) click to toggle source
# File lib/rawmidi/api.rb, line 119
def self.get_name(id)
  name_pp = FFI::MemoryPointer.new(:pointer)
  status = API.snd_card_get_name(id, name_pp)
  fail Error, API.snd_strerror(status) if status < 0

  name_p = name_pp.read_pointer
  name = name_p.read_string
  LibC.free(name_p)

  name
end
with_control(card) { |ctl_p| ... } click to toggle source
# File lib/rawmidi/api.rb, line 102
def self.with_control(card)
  return enum_for(__method__, card) unless block_given?

  ctl_pp = FFI::MemoryPointer.new(:pointer)
  status = API.snd_ctl_open(ctl_pp, "hw:#{card}", :readonly)
  if status < 0
    fail Error, "cannot open control for card #{card}: #{API.snd_strerror(status)}"
  end

  ctl_p = ctl_pp.read_pointer
  res = yield(ctl_p)

  API.snd_ctl_close(ctl_p)

  res
end