Class: MIDICommunicationsMacOS::Entity

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

Overview

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 an application to make reasonable default assumptions about how to communicate in a bi-directional manner with each entity, as is necessary in MIDI librarian applications.

developer.apple.com/library/ios/documentation/CoreMidi/Reference/MIDIServices_Reference/Reference/reference.html

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



18
19
20
21
22
23
24
25
# File 'lib/midi-communications-macos/entity.rb', line 18

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

Instance Attribute Details

#endpointsObject (readonly)

Returns the value of attribute endpoints.



10
11
12
# File 'lib/midi-communications-macos/entity.rb', line 10

def endpoints
  @endpoints
end

#manufacturerObject (readonly)

Returns the value of attribute manufacturer.



10
11
12
# File 'lib/midi-communications-macos/entity.rb', line 10

def manufacturer
  @manufacturer
end

#modelObject (readonly)

Returns the value of attribute model.



10
11
12
# File 'lib/midi-communications-macos/entity.rb', line 10

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/midi-communications-macos/entity.rb', line 10

def name
  @name
end

#resourceObject (readonly)

Returns the value of attribute resource.



10
11
12
# File 'lib/midi-communications-macos/entity.rb', line 10

def resource
  @resource
end

Instance Method Details

#display_nameString

Construct a display name for the entity

Returns:

  • (String)


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

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

#online?Boolean

Is the entity online?

Returns:

  • (Boolean)


41
42
43
# File 'lib/midi-communications-macos/entity.rb', line 41

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)


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

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