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.
-
#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.
- #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.
144 145 146 147 148 149 150 151 152 |
# File 'lib/jsound/midi/device_list.rb', line 144 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.
81 82 83 84 |
# File 'lib/jsound/midi/device_list.rb', line 81 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.
49 50 51 52 53 54 55 |
# File 'lib/jsound/midi/device_list.rb', line 49 def [](criteria) if criteria.kind_of? Fixnum or criteria.kind_of? Range @devices[criteria] else find_all(criteria) 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
29 30 31 |
# File 'lib/jsound/midi/device_list.rb', line 29 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
41 42 43 |
# File 'lib/jsound/midi/device_list.rb', line 41 def find_all(criteria) search :find_all, criteria end |
#open(device) ⇒ Device
Find the first device matching the argument and open it.
65 66 67 68 69 70 71 72 73 |
# File 'lib/jsound/midi/device_list.rb', line 65 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
92 93 94 |
# File 'lib/jsound/midi/device_list.rb', line 92 def open_first open @devices.first end |
#open_last ⇒ Device
open and return the last device in this list
102 103 104 |
# File 'lib/jsound/midi/device_list.rb', line 102 def open_last open @devices.first end |
#to_s ⇒ Object
106 107 108 |
# File 'lib/jsound/midi/device_list.rb', line 106 def to_s @devices.join("\n") end |