class CoreMIDI::Entity

A MIDI entity can have any number of MIDI endpoints, each of which is a source or destination of a 16-channel MIDI stream. By grouping a device's endpoints into entities, the system has enough information for an application to make reasonable default assumptions about how to communicate in a bi-directional manner with each entity, as is necessary in MIDI librarian applications.

developer.apple.com/library/ios/documentation/CoreMidi/Reference/MIDIServices_Reference/Reference/reference.html

Attributes

endpoints[R]
manufacturer[R]
model[R]
name[R]
resource[R]

Public Class Methods

new(resource, options = {}) click to toggle source

@param [FFI::Pointer] resource A pointer to the underlying entity @param [Hash] options @option options [Boolean] :include_offline Include offline endpoints in the list

# File lib/coremidi/entity.rb, line 21
def initialize(resource, options = {})
  @endpoints = {
    source: [],
    destination: []
  }
  @resource = resource
  populate(options)
end

Public Instance Methods

online?() click to toggle source

Is the entity online? @return [Boolean]

# File lib/coremidi/entity.rb, line 44
def online?
  get_int(:offline) == 0
end
populate_endpoint_ids(starting_id) click to toggle source

Assign all of this Entity's endpoints an consecutive local id @param [Integer] starting_id @return [Integer]

# File lib/coremidi/entity.rb, line 33
def populate_endpoint_ids(starting_id)
  counter = 0
  @endpoints.values.flatten.each do |endpoint|
    endpoint.id = counter + starting_id
    counter += 1
  end
  counter
end

Private Instance Methods

get_int(name) click to toggle source

An Integer property from the underlying entity @param [Symbol, String] name The property name @return [Integer, nil]

# File lib/coremidi/entity.rb, line 100
def get_int(name)
  API.get_int(@resource, name)
end
get_name() click to toggle source

Construct a display name for the entity @return [String]

# File lib/coremidi/entity.rb, line 52
def get_name
  "#{@manufacturer} #{@model}"
end
get_string(name) click to toggle source

A CFString property from the underlying entity @param [Symbol, String] name The property name @return [String, nil]

# File lib/coremidi/entity.rb, line 93
def get_string(name)
  API.get_string(@resource, name)
end
number_of_endpoints(type) click to toggle source

The number of endpoints for this entity @param [Symbol] type The endpoint type eg :source, :destination

# File lib/coremidi/entity.rb, line 83
def number_of_endpoints(type)
  case type
    when :source then API.MIDIEntityGetNumberOfSources(@resource)
    when :destination then API.MIDIEntityGetNumberOfDestinations(@resource)
  end
end
populate(options = {}) click to toggle source

Populate the entity properties from the underlying resource @param [Hash] options @option options [Boolean] :include_offline Include offline endpoints in the list

# File lib/coremidi/entity.rb, line 107
def populate(options = {})
  @manufacturer = get_string(:manufacturer)
  @model = get_string(:model)
  @name = get_name
  populate_endpoints(options)
end
populate_endpoints(options = {}) click to toggle source

Populate the endpoints for this entity @param [Hash] options @option options [Boolean] :include_offline Include offline endpoints in the list @return [Integer]

# File lib/coremidi/entity.rb, line 77
def populate_endpoints(options = {})
  @endpoints.keys.map { |type| populate_endpoints_by_type(type, options) }.reduce(&:+)
end
populate_endpoints_by_type(type, options = {}) click to toggle source

Populate endpoints of a specified type for this entity @param [Symbol] type The endpoint type eg :source, :destination @param [Hash] options @option options [Boolean] :include_offline Include offline endpoints in the list @return [Integer]

# File lib/coremidi/entity.rb, line 61
def populate_endpoints_by_type(type, options = {})
  endpoint_class = Endpoint.get_class(type)
  num_endpoints = number_of_endpoints(type)
  (0..num_endpoints).each do |i|
    endpoint = endpoint_class.new(i, self)
    if endpoint.online? || options[:include_offline]
      @endpoints[type] << endpoint
    end
  end
  @endpoints[type].size
end