module CoreMIDI::Endpoint
A source or destination of a 16-channel MIDI stream
Attributes
Public Class Methods
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
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
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
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 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
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
@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
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
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
Is this endpoint online? @return [Boolean]
# File lib/coremidi/endpoint.rb, line 31 def online? @entity.online? && connect? end
Protected Instance Methods
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
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