Class: MIDICommunications::Loader Private

Inherits:
Object
  • Object
show all
Defined in:
lib/midi-communications/loader.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Populates MIDI devices using platform-specific adapters.

This class lazily loads and caches MIDI devices from the underlying platform adapter (macOS, Linux, Windows, or JRuby).

Class Method Summary collapse

Class Method Details

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns all MIDI devices, optionally filtered by direction.

Lazily loads and caches devices from the platform adapter on first call.

Parameters:

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

    filter options

Options Hash (options):

  • :direction (Symbol)

    Return only :input or :output devices

Returns:



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/midi-communications/loader.rb', line 25

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

.use(loader) ⇒ Module

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sets the platform-specific loader to use.

Parameters:

  • loader (Module)

    a loader module with inputs and outputs methods

Returns:

  • (Module)

    the loader



14
15
16
# File 'lib/midi-communications/loader.rb', line 14

def use(loader)
  @loader = loader
end