class CoreMIDI::Device

@private

Public Class Methods

new(id, device_pointer, options = {}) click to toggle source
# File lib/mtk/io/unimidi_output.rb, line 85
def initialize(id, device_pointer, options = {})
  include_if_offline = options[:include_offline] || false
  @id = id
  @resource = device_pointer
  @entities = []

  prop = Map::CF.CFStringCreateWithCString( nil, "name", 0 )
  begin
    name_ptr = FFI::MemoryPointer.new(:pointer)
    Map::MIDIObjectGetStringProperty(@resource, prop, name_ptr)
    name = name_ptr.read_pointer
    len = Map::CF.CFStringGetMaximumSizeForEncoding(Map::CF.CFStringGetLength(name), :kCFStringEncodingUTF8)
    bytes = FFI::MemoryPointer.new(len + 1)
    raise RuntimeError.new("CFStringGetCString") unless Map::CF.CFStringGetCString(name, bytes, len, :kCFStringEncodingUTF8)
    @name = bytes.read_string
  ensure
    Map::CF.CFRelease(name) unless name.nil? || name.null?
    Map::CF.CFRelease(prop) unless prop.null?
  end
  populate_entities(:include_offline => include_if_offline)
end