Module: MIDICommunicationsMacOS::Endpoint

Extended by:
Forwardable
Included in:
Destination, Source
Defined in:
lib/midi-communications-macos/endpoint.rb

Overview

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?



8
9
10
# File 'lib/midi-communications-macos/endpoint.rb', line 8

def enabled
  @enabled
end

#entityObject (readonly)

has the endpoint been initialized?



8
9
10
# File 'lib/midi-communications-macos/endpoint.rb', line 8

def entity
  @entity
end

#idObject

has the endpoint been initialized?



8
9
10
# File 'lib/midi-communications-macos/endpoint.rb', line 8

def id
  @id
end

#resource_idObject (readonly)

has the endpoint been initialized?



8
9
10
# File 'lib/midi-communications-macos/endpoint.rb', line 8

def resource_id
  @resource_id
end

#typeObject (readonly)

has the endpoint been initialized?



8
9
10
# File 'lib/midi-communications-macos/endpoint.rb', line 8

def type
  @type
end

Class Method Details

.allArray<Destination, Source>

All endpoints of both types

Returns:



80
81
82
# File 'lib/midi-communications-macos/endpoint.rb', line 80

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

.all_by_typeHash

A Hash of :source and :destination endpoints

Returns:

  • (Hash)


71
72
73
74
75
76
# File 'lib/midi-communications-macos/endpoint.rb', line 71

def self.all_by_type
  {
    source: sources,
    destination: destinations
  }
end

.destinationsArray<Destination>

All destination endpoints

Returns:



65
66
67
# File 'lib/midi-communications-macos/endpoint.rb', line 65

def self.destinations
  Device.all.map { |d| d.endpoints[:destination] }.flatten
end

.first(type) ⇒ Destination, Source

Select the first endpoint of the specified type

Returns:



47
48
49
# File 'lib/midi-communications-macos/endpoint.rb', line 47

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



87
88
89
90
91
92
# File 'lib/midi-communications-macos/endpoint.rb', line 87

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:



53
54
55
# File 'lib/midi-communications-macos/endpoint.rb', line 53

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

.sourcesArray<Source>

All source endpoints

Returns:



59
60
61
# File 'lib/midi-communications-macos/endpoint.rb', line 59

def self.sources
  Device.all.map { |d| d.endpoints[:source] }.flatten
end

Instance Method Details

#initialize(resource_id, entity) ⇒ Object

Parameters:

  • resource_id (Integer)
  • entity (Entity)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/midi-communications-macos/endpoint.rb', line 20

def initialize(resource_id, entity)
  @entity = entity
  @resource_id = resource_id
  @type = get_type
  @enabled = false

  @name = nil

  @threads_sync_semaphore = Mutex.new
  @threads_waiting = []
end

#online?Boolean

Is this endpoint online?

Returns:

  • (Boolean)


34
35
36
# File 'lib/midi-communications-macos/endpoint.rb', line 34

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