Class: CoreMIDI::Device
- Inherits:
-
Object
- Object
- CoreMIDI::Device
- Defined in:
- lib/coremidi/device.rb
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.
13 14 15 16 17 18 |
# File 'lib/coremidi/device.rb', line 13 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.
5 6 7 |
# File 'lib/coremidi/device.rb', line 5 def entities @entities end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/coremidi/device.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/coremidi/device.rb', line 5 def name @name end |
Class Method Details
.all(options = {}) ⇒ Array<Device>
All cached devices
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/coremidi/device.rb', line 45 def self.all( = {}) use_cache = [:cache] || true include_offline = [:include_offline] || false if !populated? || !use_cache @devices = [] counter = 0 while !(device_pointer = Map.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?
69 70 71 |
# File 'lib/coremidi/device.rb', line 69 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
63 64 65 66 |
# File 'lib/coremidi/device.rb', line 63 def self.refresh @devices.clear @devices end |
Instance Method Details
#endpoints ⇒ Array<Endpoint>
Endpoints for this device
22 23 24 25 26 27 28 29 |
# File 'lib/coremidi/device.rb', line 22 def endpoints endpoints = { :source => [], :destination => [] } endpoints.keys.each 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
34 35 36 37 38 |
# File 'lib/coremidi/device.rb', line 34 def populate_endpoint_ids(last_id) id = 0 entities.each { |entity| id += entity.populate_endpoint_ids(id + last_id) } id end |