module CoreMIDI::Endpoint

A source or destination of a 16-channel MIDI stream

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

Attributes

enabled[R]
enabled?[R]
entity[R]
id[R]
resource_id[R]
type[R]

Public Class Methods

all() click to toggle source

All endpoints of both types @return [Array<Destination, Source>]

# File lib/coremidi/endpoint.rb, line 77
def self.all
  Device.all.map(&:endpoints).flatten
end
all_by_type() click to toggle source

A Hash of :source and :destination endpoints @return [Hash]

# File lib/coremidi/endpoint.rb, line 68
def self.all_by_type
  {
    source: sources,
    destination: destinations
  }
end
destinations() click to toggle source

All destination endpoints @return [Array<Destination>]

# File lib/coremidi/endpoint.rb, line 62
def self.destinations
  Device.all.map { |d| d.endpoints[:destination] }.flatten
end
first(type) click to toggle source

Select the first endpoint of the specified type @return [Destination, Source]

# File lib/coremidi/endpoint.rb, line 44
def self.first(type)
  all_by_type[type].first
end
get_class(type) click to toggle source

Get the class for the given endpoint type name @param [Symbol] type The endpoint type eg :source, :destination @return [Class] eg Source, Destination

# File lib/coremidi/endpoint.rb, line 84
def self.get_class(type)
  case type
  when :source then Source
  when :destination then Destination
  end
end
last(type) click to toggle source

Select the last endpoint of the specified type @return [Destination, Source]

# File lib/coremidi/endpoint.rb, line 50
def self.last(type)
  all_by_type[type].last
end
new(resource_id, entity) click to toggle source

@param [Integer] resource_id @param [Entity] entity

# File lib/coremidi/endpoint.rb, line 22
def initialize(resource_id, entity)
  @entity = entity
  @resource_id = resource_id
  @type = get_type
  @enabled = false
end
sources() click to toggle source

All source endpoints @return [Array<Source>]

# File lib/coremidi/endpoint.rb, line 56
def self.sources
  Device.all.map { |d| d.endpoints[:source] }.flatten
end

Public Instance Methods

id=(id) click to toggle source

Set the id for this endpoint (the id is immutable) @param [Integer] val @return [Integer]

# File lib/coremidi/endpoint.rb, line 38
def id=(id)
  @id ||= id
end
online?() click to toggle source

Is this endpoint online? @return [Boolean]

# File lib/coremidi/endpoint.rb, line 31
def online?
  @entity.online? && connect?
end

Protected Instance Methods

enable_client() click to toggle source

Enables the coremidi MIDI client that will go with this endpoint

# File lib/coremidi/endpoint.rb, line 100
def enable_client
  client = API.create_midi_client(@resource_id, @name)
  @client = client[:resource]
  client[:error]
end
get_type() click to toggle source

Constructs the endpoint type (eg source, destination) for easy consumption

# File lib/coremidi/endpoint.rb, line 94
def get_type
  class_name = self.class.name.split('::').last
  class_name.downcase.to_sym
end