Class: JSound::Midi::DeviceList
- Inherits:
-
Object
- Object
- JSound::Midi::DeviceList
- Defined in:
- lib/jsound/midi/device_list.rb
Overview
A collection of MIDI Devices that provides various methods to lookup (and optionally auto-open) specific devices
Instance Attribute Summary collapse
-
#devices ⇒ Object
readonly
The devices within this collection.
Instance Method Summary collapse
-
#/(regexp) ⇒ Device
Find and open the first device with a description matching the argument.
-
#[](criteria) ⇒ Object
Acts like Array#[] for Numeric and Range arguments.
- #each ⇒ Object
-
#find(criteria) ⇒ Device
Find the first Device matching the criteria.
-
#find_all(criteria) ⇒ Array
Find all Devices matching the criteria.
-
#initialize(list = []) ⇒ DeviceList
constructor
A new instance of DeviceList.
-
#open(device) ⇒ Device
Find the first device matching the argument and open it.
-
#open_first ⇒ Device
open the first device in this list.
-
#open_last ⇒ Device
open and return the last device in this list.
-
#output=(output) ⇒ Object
(also: #>>)
Connect the output to all devices in this device list.
- #to_s ⇒ Object
Constructor Details
#initialize(list = []) ⇒ DeviceList
Returns a new instance of DeviceList.
13 14 15 |
# File 'lib/jsound/midi/device_list.rb', line 13 def initialize(list=[]) @devices = list end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object (private)
Pass method calls through to the underlying Array. If Array doesn’t understand the method, call #open with a case-insensitive regexp match against description, treating underscore as a wildcard.
158 159 160 161 162 163 164 165 166 |
# File 'lib/jsound/midi/device_list.rb', line 158 def method_missing(sym, *args, &block) if @devices.respond_to? sym @devices.send(sym, *args, &block) elsif args.length == 0 and block.nil? self.open /#{sym.to_s.sub '_','.*'}/i else super end end |
Instance Attribute Details
#devices ⇒ Object (readonly)
The devices within this collection.
11 12 13 |
# File 'lib/jsound/midi/device_list.rb', line 11 def devices @devices end |
Instance Method Details
#/(regexp) ⇒ Device
Find and open the first device with a description matching the argument.
87 88 89 90 |
# File 'lib/jsound/midi/device_list.rb', line 87 def /(regexp) regexp = Regexp.new(regexp.to_s, Regexp::IGNORECASE) if not regexp.kind_of? Regexp open regexp end |
#[](criteria) ⇒ Object
Acts like Array#[] for Numeric and Range arguments. Otherwise acts like #find_all.
55 56 57 58 59 60 61 |
# File 'lib/jsound/midi/device_list.rb', line 55 def [](criteria) if criteria.kind_of? Fixnum or criteria.kind_of? Range @devices[criteria] else find_all(criteria) end end |
#each ⇒ Object
17 18 19 20 21 |
# File 'lib/jsound/midi/device_list.rb', line 17 def each for device in devices yield device end end |
#find(criteria) ⇒ Device
I/O devices need to be opened before they can be used (see JSound::Midi::Device#open)
Find the first JSound::Midi::Device matching the criteria
35 36 37 |
# File 'lib/jsound/midi/device_list.rb', line 35 def find(criteria) search :find, criteria end |
#find_all(criteria) ⇒ Array
I/O devices need to be opened before they can be used (see JSound::Midi::Device#open)
Find all JSound::Midi::Devices matching the criteria
47 48 49 |
# File 'lib/jsound/midi/device_list.rb', line 47 def find_all(criteria) search :find_all, criteria end |
#open(device) ⇒ Device
Find the first device matching the argument and open it.
71 72 73 74 75 76 77 78 79 |
# File 'lib/jsound/midi/device_list.rb', line 71 def open(device) device = find device unless device.is_a? Device if device device.open else raise "Device note found: #{device}" end device end |
#open_first ⇒ Device
open the first device in this list
98 99 100 |
# File 'lib/jsound/midi/device_list.rb', line 98 def open_first open @devices.first end |
#open_last ⇒ Device
open and return the last device in this list
108 109 110 |
# File 'lib/jsound/midi/device_list.rb', line 108 def open_last open @devices.first end |
#output=(output) ⇒ Object Also known as: >>
Connect the output to all devices in this device list
113 114 115 116 117 |
# File 'lib/jsound/midi/device_list.rb', line 113 def output= output for device in devices device.output = output end end |
#to_s ⇒ Object
120 121 122 |
# File 'lib/jsound/midi/device_list.rb', line 120 def to_s @devices.join("\n") end |