Class: UniMIDI::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/unimidi/loader.rb

Overview

Populate UniMIDI devices using the underlying device objects from the platform-specific gems

Class Method Summary collapse

Class Method Details

.devices(options = {}) ⇒ Array<Input>, Array<Output>

Get all MIDI devices

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :direction (Symbol)

    Return only a particular direction of device eg :input, :output

Returns:



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unimidi/loader.rb', line 17

def devices(options = {})
  if @devices.nil?
    inputs = @loader.inputs.map { |device| ::UniMIDI::Input.new(device) }
    outputs = @loader.outputs.map { |device| ::UniMIDI::Output.new(device) }
    @devices = {
      input: inputs,
      output: outputs
    }
  end
  options[:direction].nil? ? @devices.values.flatten : @devices[options[:direction]]
end

.use(loader) ⇒ Object

Use the given platform-specific adapter to load devices

Parameters:

  • loader (UniMIDI::Adapter::Loader)


9
10
11
# File 'lib/unimidi/loader.rb', line 9

def use(loader)
  @loader = loader
end