Module: CoreMIDI::Endpoint

Extended by:
Forwardable
Included in:
Destination, Source
Defined in:
lib/coremidi/endpoint.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enabledObject (readonly) Also known as: enabled?

has the endpoint been initialized?



7
8
9
# File 'lib/coremidi/endpoint.rb', line 7

def enabled
  @enabled
end

#entityObject (readonly)

has the endpoint been initialized?



7
8
9
# File 'lib/coremidi/endpoint.rb', line 7

def entity
  @entity
end

#idObject

has the endpoint been initialized?



7
8
9
# File 'lib/coremidi/endpoint.rb', line 7

def id
  @id
end

#resource_idObject (readonly)

has the endpoint been initialized?



7
8
9
# File 'lib/coremidi/endpoint.rb', line 7

def resource_id
  @resource_id
end

#typeObject (readonly)

has the endpoint been initialized?



7
8
9
# File 'lib/coremidi/endpoint.rb', line 7

def type
  @type
end

Class Method Details

.allArray<Destination, Source>

All endpoints of both types

Returns:



60
61
62
# File 'lib/coremidi/endpoint.rb', line 60

def self.all
  Device.all.map(&:endpoints).flatten
end

.all_by_typeHash

A Hash of :source and :destination endpoints

Returns:

  • (Hash)


51
52
53
54
55
56
# File 'lib/coremidi/endpoint.rb', line 51

def self.all_by_type
  {
    :source => Device.all.map { |d| d.endpoints[:source] }.flatten,
    :destination => Device.all.map { |d| d.endpoints[:destination] }.flatten
  }
end

.first(type) ⇒ Destination, Source

Select the first endpoint of the specified type

Returns:



39
40
41
# File 'lib/coremidi/endpoint.rb', line 39

def self.first(type)
  all_by_type[type].first
end

.get_class(type) ⇒ Class

Get the class for the given endpoint type name

Parameters:

  • type (Symbol)

    The endpoint type eg :source, :destination

Returns:

  • (Class)

    eg Source, Destination



67
68
69
70
71
72
# File 'lib/coremidi/endpoint.rb', line 67

def self.get_class(type)
  case type
  when :source then Source
  when :destination then Destination
  end  
end

.last(type) ⇒ Destination, Source

Select the last endpoint of the specified type

Returns:



45
46
47
# File 'lib/coremidi/endpoint.rb', line 45

def self.last(type)
  all_by_type[type].last
end

Instance Method Details

#initialize(resource_id, entity, options = {}, &block) ⇒ Object



17
18
19
20
21
22
# File 'lib/coremidi/endpoint.rb', line 17

def initialize(resource_id, entity, options = {}, &block)
  @entity = entity
  @resource_id = resource_id
  @type = self.class.name.split('::').last.downcase.to_sym
  @enabled = false
end

#online?Boolean

Is this endpoint online?

Returns:

  • (Boolean)


26
27
28
# File 'lib/coremidi/endpoint.rb', line 26

def online?
  @entity.online? && connect?
end