Module: MIDICommunicationsMacOS::Endpoint

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

Overview

A source or destination of a 16-channel MIDI stream.

This module provides shared functionality for both Source (input) and Destination (output) endpoints. Each endpoint represents a single point of MIDI communication within an Entity.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enabledBoolean (readonly) Also known as: enabled?

Returns whether the endpoint has been initialized.

Returns:

  • (Boolean)

    whether the endpoint has been initialized



24
25
26
# File 'lib/midi-communications-macos/endpoint.rb', line 24

def enabled
  @enabled
end

#entityEntity (readonly)

Returns the parent entity.

Returns:

  • (Entity)

    the parent entity



24
25
26
27
28
# File 'lib/midi-communications-macos/endpoint.rb', line 24

attr_reader :enabled,
:entity,
:id,
:resource_id,
:type

#idInteger

Returns unique local numeric ID of the endpoint.

Returns:

  • (Integer)

    unique local numeric ID of the endpoint



24
25
26
27
28
# File 'lib/midi-communications-macos/endpoint.rb', line 24

attr_reader :enabled,
:entity,
:id,
:resource_id,
:type

#resource_idInteger (readonly)

Returns Core MIDI resource identifier.

Returns:

  • (Integer)

    Core MIDI resource identifier



24
25
26
27
28
# File 'lib/midi-communications-macos/endpoint.rb', line 24

attr_reader :enabled,
:entity,
:id,
:resource_id,
:type

#typeObject (readonly)



24
25
26
27
28
# File 'lib/midi-communications-macos/endpoint.rb', line 24

attr_reader :enabled,
:entity,
:id,
:resource_id,
:type

Class Method Details

.allArray<Destination, Source>

All endpoints of both types

Returns:



106
107
108
# File 'lib/midi-communications-macos/endpoint.rb', line 106

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

.all_by_typeHash

A Hash of :source and :destination endpoints

Returns:

  • (Hash)


97
98
99
100
101
102
# File 'lib/midi-communications-macos/endpoint.rb', line 97

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

.destinationsArray<Destination>

All destination endpoints

Returns:



91
92
93
# File 'lib/midi-communications-macos/endpoint.rb', line 91

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:



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

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



113
114
115
116
117
118
# File 'lib/midi-communications-macos/endpoint.rb', line 113

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:



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

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

.sourcesArray<Source>

All source endpoints

Returns:



85
86
87
# File 'lib/midi-communications-macos/endpoint.rb', line 85

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

Instance Method Details

#display_nameString

Returns formatted display name (delegated to entity).

Returns:

  • (String)

    formatted display name (delegated to entity)



38
# File 'lib/midi-communications-macos/endpoint.rb', line 38

def_delegators :entity, :manufacturer, :model, :name, :display_name

#initialize(resource_id, entity) ⇒ Object

Parameters:

  • resource_id (Integer)
  • entity (Entity)


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/midi-communications-macos/endpoint.rb', line 46

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

#manufacturerString

Returns device manufacturer name (delegated to entity).

Returns:

  • (String)

    device manufacturer name (delegated to entity)



38
# File 'lib/midi-communications-macos/endpoint.rb', line 38

def_delegators :entity, :manufacturer, :model, :name, :display_name

#modelString

Returns device model name (delegated to entity).

Returns:

  • (String)

    device model name (delegated to entity)



38
# File 'lib/midi-communications-macos/endpoint.rb', line 38

def_delegators :entity, :manufacturer, :model, :name, :display_name

#nameString

Returns endpoint name (delegated to entity).

Returns:

  • (String)

    endpoint name (delegated to entity)



38
# File 'lib/midi-communications-macos/endpoint.rb', line 38

def_delegators :entity, :manufacturer, :model, :name, :display_name

#online?Boolean

Is this endpoint online?

Returns:

  • (Boolean)


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

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