Class: MusaLCEServer::MIDIDevices
- Inherits:
-
Object
- Object
- MusaLCEServer::MIDIDevices
- Includes:
- Enumerable
- Defined in:
- lib/midi-devices.rb
Overview
Manages available MIDI output devices.
Provides enumeration and lookup of MIDI devices, automatically synchronizing with the system's available devices.
Instance Method Summary collapse
-
#[](name) ⇒ MIDIDevice?
Retrieves a device by exact name.
-
#each {|MIDIDevice| ... } ⇒ Enumerator
Iterates over all MIDI devices.
-
#find(name) ⇒ MIDIDevice?
Finds a device by name suffix.
-
#initialize(sequencer) ⇒ MIDIDevices
constructor
Creates a new MIDI devices manager.
-
#sync ⇒ void
Synchronizes the device list with system MIDI devices.
Constructor Details
#initialize(sequencer) ⇒ MIDIDevices
Creates a new MIDI devices manager.
22 23 24 25 26 27 |
# File 'lib/midi-devices.rb', line 22 def initialize(sequencer) @sequencer = sequencer @low_level_devices = {} sync end |
Instance Method Details
#[](name) ⇒ MIDIDevice?
Retrieves a device by exact name.
55 56 57 |
# File 'lib/midi-devices.rb', line 55 def [](name) @low_level_devices[name] end |
#each {|MIDIDevice| ... } ⇒ Enumerator
Iterates over all MIDI devices.
77 78 79 80 81 82 83 |
# File 'lib/midi-devices.rb', line 77 def each(&block) if block_given? @low_level_devices.values.each(&block) else @low_level_devices.values.each end end |
#find(name) ⇒ MIDIDevice?
Finds a device by name suffix.
Useful when device names include prefixes that vary by system.
68 69 70 71 |
# File 'lib/midi-devices.rb', line 68 def find(name) full_name = @low_level_devices.keys.find { |_| _.end_with?(name) } @low_level_devices[full_name] end |
#sync ⇒ void
This method returns an undefined value.
Synchronizes the device list with system MIDI devices.
Adds newly connected devices and removes disconnected ones.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/midi-devices.rb', line 34 def sync names = @low_level_devices.keys MIDICommunications::Output.all.each do |low_level_device| next if @low_level_devices.key?(low_level_device.name) @low_level_devices[low_level_device.name] = MIDIDevice.new(@sequencer, low_level_device) names.delete low_level_device.name end # remove disconnected devices # names.each do |name| @low_level_devices.delete name end end |