Sha256: d64eb9e4e1cf1de604960a7bd30123c9b5de9783f9f1ec59e8dd07ae62edad97

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require 'alsa/command'
require 'alsa/aconnect/version'
require 'alsa/aconnect/error'
require 'alsa/aconnect/cmd'
require 'alsa/aconnect/parser'
require 'alsa/aconnect/port'
require 'alsa/aconnect/client'

module ALSA
  module Aconnect
    module_function

    def input_clients
      out = Cmd.run('-i', '-l')
      Parser.parse_clients(out).map { |text| Client.new(text, :input) }
    end

    def input_ports
      input_clients.map(&:ports).flatten
    end

    def output_clients
      out = Cmd.run('-o', '-l')
      Parser.parse_clients(out).map { |text| Client.new(text, :output) }
    end

    def output_ports
      output_clients.map(&:ports).flatten
    end

    def connect(input, output)
      input = "#{input.client.id}:#{input.id}" if input.is_a?(Port)
      output = "#{output.client.id}:#{output.id}" if output.is_a?(Port)

      Cmd.run('-d', input, output)
    end

    def disconnect(input, output)
      input = "#{input.client.id}:#{input.id}" if input.is_a?(Port)
      output = "#{output.client.id}:#{output.id}" if output.is_a?(Port)

      Cmd.run(input, output)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alsa_aconnect-0.1.1 lib/alsa/aconnect.rb