Class: MIDIDevices

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/midi-devices.rb

Instance Method Summary collapse

Constructor Details

#initialize(sequencer) ⇒ MIDIDevices

Returns a new instance of MIDIDevices.



8
9
10
11
12
13
# File 'lib/midi-devices.rb', line 8

def initialize(sequencer)
  @sequencer = sequencer
  @low_level_devices = {}

  sync
end

Instance Method Details

#[](name) ⇒ Object



32
33
34
# File 'lib/midi-devices.rb', line 32

def [](name)
  @low_level_devices[name]
end

#each(&block) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/midi-devices.rb', line 41

def each(&block)
  if block_given?
    @low_level_devices.values.each(&block)
  else
    @low_level_devices.values.each
  end
end

#find(name) ⇒ Object



36
37
38
39
# File 'lib/midi-devices.rb', line 36

def find(name)
  full_name = @low_level_devices.keys.find { |_| _.end_with?(name) }
  @low_level_devices[full_name]
end

#syncObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/midi-devices.rb', line 15

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