Class: MIDICommunicationsMacOS::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/midi-communications-macos/entity.rb

Overview

A logical grouping of MIDI endpoints within a device.

A MIDI entity can have any number of MIDI endpoints, each of which is a source or destination of a 16-channel MIDI stream. By grouping a device's endpoints into entities, the system has enough information for applications to make reasonable default assumptions about bidirectional communication.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, include_offline: false) ⇒ Entity

Returns a new instance of Entity.

Parameters:

  • resource (FFI::Pointer)

    A pointer to the underlying entity

  • include_offline (Boolean) (defaults to: false)

    Include offline endpoints in the list



32
33
34
35
36
37
38
39
# File 'lib/midi-communications-macos/entity.rb', line 32

def initialize(resource, include_offline: false)
  @endpoints = {
    source: [],
    destination: []
  }
  @resource = resource
  populate(include_offline: include_offline)
end

Instance Attribute Details

#endpointsHash{Symbol => Array<Endpoint>} (readonly)

Returns endpoints grouped by :source and :destination.

Returns:

  • (Hash{Symbol => Array<Endpoint>})

    endpoints grouped by :source and :destination



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

def endpoints
  @endpoints
end

#manufacturerString (readonly)

Returns device manufacturer name.

Returns:

  • (String)

    device manufacturer name



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

attr_reader :endpoints,
:manufacturer,
:model,
:name,
:resource

#modelString (readonly)

Returns device model name.

Returns:

  • (String)

    device model name



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

attr_reader :endpoints,
:manufacturer,
:model,
:name,
:resource

#nameString (readonly)

Returns entity name.

Returns:

  • (String)

    entity name



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

attr_reader :endpoints,
:manufacturer,
:model,
:name,
:resource

#resourceObject (readonly)



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

attr_reader :endpoints,
:manufacturer,
:model,
:name,
:resource

Instance Method Details

#display_nameString

Construct a display name for the entity

Returns:

  • (String)


61
62
63
# File 'lib/midi-communications-macos/entity.rb', line 61

def display_name
  "#{@manufacturer} #{@model} (#{@name})"
end

#online?Boolean

Is the entity online?

Returns:

  • (Boolean)


55
56
57
# File 'lib/midi-communications-macos/entity.rb', line 55

def online?
  get_int(:offline).zero?
end

#populate_endpoint_ids(starting_id) ⇒ Integer

Assign all of this Entity's endpoints an consecutive local id

Parameters:

  • starting_id (Integer)

Returns:

  • (Integer)


44
45
46
47
48
49
50
51
# File 'lib/midi-communications-macos/entity.rb', line 44

def populate_endpoint_ids(starting_id)
  counter = 0
  @endpoints.values.flatten.each do |endpoint|
    endpoint.id = counter + starting_id
    counter += 1
  end
  counter
end