Class: CoreMIDI::Device
- Inherits:
-
Object
- Object
- CoreMIDI::Device
- Defined in:
- lib/coremidi/device.rb
Overview
A MIDI device may have multiple logically distinct sub-components. For example, one device may encompass a MIDI synthesizer and a pair of MIDI ports, both addressable via a USB port. Each such element of a device is called a MIDI entity.
Instance Attribute Summary collapse
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.all(options = {}) ⇒ Array<Device>
All cached devices.
-
.populated? ⇒ Boolean
Has the device list been populated?.
-
.refresh ⇒ Array<Device>
Refresh the Device cache.
Instance Method Summary collapse
-
#endpoints ⇒ Array<Endpoint>
Endpoints for this device.
-
#initialize(id, device_pointer, options = {}) ⇒ Device
constructor
A new instance of Device.
-
#populate_endpoint_ids(last_id) ⇒ Integer
Assign all of this Device’s endpoints an consecutive local id.
Constructor Details
#initialize(id, device_pointer, options = {}) ⇒ Device
Returns a new instance of Device.
18 19 20 21 22 23 |
# File 'lib/coremidi/device.rb', line 18 def initialize(id, device_pointer, = {}) @id = id @resource = device_pointer @entities = [] populate() end |
Instance Attribute Details
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
10 11 12 |
# File 'lib/coremidi/device.rb', line 10 def entities @entities end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/coremidi/device.rb', line 10 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/coremidi/device.rb', line 10 def name @name end |
Class Method Details
.all(options = {}) ⇒ Array<Device>
All cached devices
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/coremidi/device.rb', line 50 def self.all( = {}) use_cache = [:cache] || true include_offline = [:include_offline] || false if !populated? || !use_cache @devices = [] counter = 0 until (device_pointer = API.MIDIGetDevice(counter)).null? device = new(counter, device_pointer, include_offline: include_offline) @devices << device counter += 1 end populate_endpoint_ids end @devices end |
.populated? ⇒ Boolean
Has the device list been populated?
74 75 76 |
# File 'lib/coremidi/device.rb', line 74 def self.populated? !@devices.nil? && !@devices.empty? end |
.refresh ⇒ Array<Device>
Refresh the Device cache. This is needed if, for example a USB MIDI device is plugged in while the program is running
68 69 70 71 |
# File 'lib/coremidi/device.rb', line 68 def self.refresh @devices.clear @devices end |
Instance Method Details
#endpoints ⇒ Array<Endpoint>
Endpoints for this device
27 28 29 30 31 32 33 34 |
# File 'lib/coremidi/device.rb', line 27 def endpoints endpoints = { source: [], destination: [] } endpoints.each_key do |key| endpoint_group = entities.map { |entity| entity.endpoints[key] }.flatten endpoints[key] += endpoint_group end endpoints end |
#populate_endpoint_ids(last_id) ⇒ Integer
Assign all of this Device’s endpoints an consecutive local id
39 40 41 42 43 |
# File 'lib/coremidi/device.rb', line 39 def populate_endpoint_ids(last_id) id = 0 entities.each { |entity| id += entity.populate_endpoint_ids(id + last_id) } id end |