alsa_aconnect 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bbda87360719787e571cf9353b4995913867eee0facce07e063ea7426f8ac6b4
4
+ data.tar.gz: 6afdfb621461830454c5add031d0b93cc017de2b217ad1fc2c087c11be02fa4a
5
+ SHA512:
6
+ metadata.gz: e3190c071728896f50d88b28b72d2d00254bcd79b0966dfdaa9f928f76f53307042c9bffd7a76d8ea85ded1921b0aafc485a102f5bcbd0e6e3668093d4b7dde7
7
+ data.tar.gz: de6ee0d7f7859dca2eac0bc0745a4dabbdda2366dbef6d6c8792716b3f68ab7e5b10b00a8378b717ed3a90f76a05cd19b02e7e15fd18622d1f6ac46388ad9f27
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.rakeTasks
10
+
11
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,78 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ TargetRubyVersion: 2.3
4
+ Exclude:
5
+ - vendor/**/*
6
+ - tmp/**/*
7
+ - docs/**/*
8
+
9
+ Lint/RaiseException:
10
+ Enabled: true
11
+
12
+ Lint/StructNewOverride:
13
+ Enabled: true
14
+
15
+ Layout/LineLength:
16
+ Max: 180
17
+
18
+ Style/SymbolArray:
19
+ EnforcedStyle: brackets
20
+
21
+ Style/Lambda:
22
+ EnforcedStyle: literal
23
+
24
+ Naming/MethodParameterName:
25
+ AllowedNames:
26
+ - id
27
+
28
+ Style/HashEachMethods:
29
+ Enabled: true
30
+
31
+ Style/HashTransformKeys:
32
+ Enabled: true
33
+
34
+ Style/HashTransformValues:
35
+ Enabled: true
36
+
37
+ Style/Documentation:
38
+ Enabled: false
39
+
40
+ Metrics/PerceivedComplexity:
41
+ Enabled: false
42
+
43
+ Metrics/MethodLength:
44
+ Enabled: false
45
+
46
+ Metrics/AbcSize:
47
+ Enabled: false
48
+
49
+ Metrics/ModuleLength:
50
+ Enabled: false
51
+
52
+ Metrics/BlockLength:
53
+ Enabled: false
54
+
55
+ Metrics/ClassLength:
56
+ Enabled: false
57
+
58
+ Metrics/CyclomaticComplexity:
59
+ Enabled: false
60
+
61
+ Layout/MultilineOperationIndentation:
62
+ Enabled: false
63
+
64
+ Layout/FirstHashElementIndentation:
65
+ Enabled: false
66
+
67
+ Layout/FirstArrayElementIndentation:
68
+ Enabled: false
69
+
70
+ Layout/FirstArgumentIndentation:
71
+ Enabled: false
72
+
73
+ Layout/ClosingParenthesisIndentation:
74
+ Enabled: false
75
+
76
+ Layout/ArgumentAlignment:
77
+ Enabled: false
78
+
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.3.8
6
+ before_install: gem install bundler -v 2.1.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # ALSA Aconnect Changelog
2
+
3
+ ## 0.1.0 (2020-01-10)
4
+ * initial version
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at senid231@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in alsa_aconnect.gemspec
6
+ gemspec
7
+
8
+ gem 'minitest', '~> 5.0'
9
+ gem 'rake', '~> 12.0'
10
+
11
+ gem 'rubocop', '~> 0.81.0', require: false
12
+ gem 'yard', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Denis Talakevich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # ALSA aconnect
2
+
3
+ Control ALSA aconnect util through ruby with zero dependency.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'alsa_aconnect'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install alsa_aconnect
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'alsa/aconnect'
25
+
26
+ def print_client(client)
27
+ puts "#{client.id} => #{client.name} [type=#{client.type},card=#{client.card},pid=#{client.pid}]"
28
+ client.ports.each do |port|
29
+ if port.connected_to_type
30
+ connected = "connected to #{port.connected_to_type} #{port.connected_to_client_id}:#{port.connected_to_port_id}"
31
+ else
32
+ connected = 'not connected'
33
+ end
34
+ puts " #{port.id} => #{port.name} (#{connected})"
35
+ end
36
+ puts ''
37
+ end
38
+
39
+ input_clients = ALSA::Aconnect.input_clients
40
+ puts "Inputs:"
41
+ input_clients.map { |client| print_client(client) }
42
+
43
+ output_clients = ALSA::Aconnect.output_clients
44
+ puts "Outputs:"
45
+ output_clients.map { |client| print_client(client) }
46
+
47
+ input = input_clients.detect { |c| c.name = 'My Input' }.ports.detect { port.name == 'My Input Port' }
48
+ output = input_clients.detect { |c| c.name = 'My Output' }.ports.detect { port.name == 'My Output Port' }
49
+ ALSA::Aconnect.connect(input, output)
50
+
51
+ ALSA::Aconnect.disconnect(input, output)
52
+
53
+ ALSA::Aconnect.connect("#{input.client.id}:#{input.id}", "#{output.client.id}:#{output.id}")
54
+ ALSA::Aconnect.disconnect("#{input.client.id}:#{input.id}", "#{output.client.id}:#{output.id}")
55
+ ```
56
+
57
+ See more in https://github.com/senid231/alsa_aconnect/blob/master/examples/
58
+
59
+ ## Development
60
+
61
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+
63
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+
65
+ ## Contributing
66
+
67
+ Bug reports and pull requests are welcome on GitHub at https://github.com/senid231/alsa_aconnect. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/senid231/alsa_aconnect/blob/master/CODE_OF_CONDUCT.md).
68
+
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
73
+
74
+ ## Code of Conduct
75
+
76
+ Everyone interacting in the ALSA aconnect project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/senid231/alsa_aconnect/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+ require 'rubocop/rake_task'
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'test'
9
+ t.libs << 'lib'
10
+ t.test_files = FileList['test/**/*_test.rb']
11
+ end
12
+
13
+ RuboCop::RakeTask.new(:rubocop)
14
+
15
+ task default: [:rubocop, :test]
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/alsa/aconnect/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'alsa_aconnect'
7
+ spec.version = ALSA::Aconnect::VERSION
8
+ spec.authors = ['Denis Talakevich']
9
+ spec.email = ['senid231@gmail.com']
10
+
11
+ spec.summary = 'Control ALSA aconnect util through ruby with zero dependency'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/senid231/alsa_aconnect'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = spec.homepage
19
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.require_paths = ['lib']
27
+ end
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'alsa/aconnect'
6
+
7
+ require 'irb'
8
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'bundler/inline'
5
+ require 'bundler'
6
+ rescue LoadError => e
7
+ warn 'Bundler version 1.10 or later is required. Please update your Bundler'
8
+ raise e
9
+ end
10
+
11
+ gemfile(true, ui: Bundler::UI::Silent.new) do
12
+ source 'https://rubygems.org'
13
+
14
+ gem 'alsa_aconnect', path: File.join(__dir__, '..'), require: false
15
+ end
16
+
17
+ require 'alsa/aconnect'
18
+
19
+ KB_NAME = 'USB Midi Cable'
20
+ SERVER_NAME = 'FLUID Synth'
21
+
22
+ input_clients = ALSA::Aconnect.input_clients
23
+ output_clients = ALSA::Aconnect.output_clients
24
+
25
+ midi_kb = input_clients.detect { |c| c.name.include?(KB_NAME) }&.ports&.first
26
+ fluidsynth = output_clients.detect { |c| c.name.include?(SERVER_NAME) }&.ports&.first
27
+
28
+ if midi_kb.nil?
29
+ puts "#{KB_NAME} not connected. Skipping."
30
+ exit 0
31
+ end
32
+
33
+ if fluidsynth.nil?
34
+ warn "#{SERVER_NAME} not started."
35
+ exit 1
36
+ end
37
+
38
+ if midi_kb.connected_to_client_id == fluidsynth.client.id && midi_kb.connected_to_port_id == fluidsynth.id
39
+ puts "#{KB_NAME} already connected to #{SERVER_NAME}. Skipping."
40
+ exit 0
41
+ end
42
+
43
+ begin
44
+ puts "Connecting #{KB_NAME} to #{SERVER_NAME}..."
45
+ ALSA::Aconnect.connect(midi_kb, fluidsynth)
46
+ puts 'Connected.'
47
+ exit 0
48
+ rescue ALSA::Aconnect::Error => e
49
+ warn e.message
50
+ exit e.code
51
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'alsa/command'
4
+ require 'alsa/aconnect/version'
5
+ require 'alsa/aconnect/error'
6
+ require 'alsa/aconnect/cmd'
7
+ require 'alsa/aconnect/parser'
8
+ require 'alsa/aconnect/port'
9
+ require 'alsa/aconnect/client'
10
+
11
+ module ALSA
12
+ module Aconnect
13
+ module_function
14
+
15
+ def input_clients
16
+ out = Cmd.run('-i', '-l')
17
+ Parser.parse_clients(out).map { |text| Client.new(text, :input) }
18
+ end
19
+
20
+ def input_ports
21
+ input_clients.map(&:ports).flatten
22
+ end
23
+
24
+ def output_clients
25
+ out = Cmd.run('-o', '-l')
26
+ Parser.parse_clients(out).map { |text| Client.new(text, :output) }
27
+ end
28
+
29
+ def output_ports
30
+ output_clients.map(&:ports).flatten
31
+ end
32
+
33
+ def connect(input, output)
34
+ input = "#{input.client_id}:#{input.id}" if input.is_a?(Port)
35
+ output = "#{output.client_id}:#{output.id}" if output.is_a?(Port)
36
+
37
+ Cmd.run('-d', input, output)
38
+ end
39
+
40
+ def disconnect(input, output)
41
+ input = "#{input.client_id}:#{input.id}" if input.is_a?(Port)
42
+ output = "#{output.client_id}:#{output.id}" if output.is_a?(Port)
43
+
44
+ Cmd.run(input, output)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ALSA
4
+ module Aconnect
5
+ class Client
6
+ DIRECTIONS = [:input, :output].freeze
7
+
8
+ attr_reader :id, :name, :type, :card, :pid, :ports, :direction
9
+
10
+ def initialize(text, direction)
11
+ raise ArgumentError, "invalid direction #{direction.inspect}" unless DIRECTIONS.include?(direction)
12
+
13
+ @direction = direction
14
+
15
+ data = Parser.parse_client(text)
16
+ @id = data[:id]
17
+ @name = data[:name]
18
+ @type = data[:type]
19
+ @card = data[:card]
20
+ @pid = data[:pid]
21
+ @ports = data[:ports].map do |port_text|
22
+ Port.new(port_text, self)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ALSA
4
+ module Aconnect
5
+ class Cmd
6
+ EXEC = 'aconnect'
7
+
8
+ def self.run(*arguments)
9
+ new(EXEC, arguments).run
10
+ end
11
+
12
+ def initialize(exec, *arguments)
13
+ @exec = exec
14
+ @arguments = arguments
15
+ end
16
+
17
+ def run
18
+ status, out, err = Command.run(@exec, *@arguments)
19
+ raise Error.new(status.exitstatus, err.join("\n")) if status != 0 || !err.empty?
20
+
21
+ out.join("\n")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ALSA
4
+ module Aconnect
5
+ class Error < StandardError
6
+ attr_reader :code, :msg
7
+
8
+ def initialize(code, msg)
9
+ @code = code
10
+ @msg = msg
11
+ super("Exited with status #{code}: #{msg}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ALSA
4
+ module Aconnect
5
+ module Parser
6
+ module_function
7
+
8
+ def parse_clients(output)
9
+ output
10
+ .split('client ')
11
+ .reject(&:empty?)
12
+ .map { |l| "client #{l.strip}" }
13
+ end
14
+
15
+ def parse_client(output)
16
+ client_line, *port_lines = output.split("\n")
17
+
18
+ ports = []
19
+ port_lines.reject(&:empty?).each do |line|
20
+ line = line.strip
21
+ if line =~ /\A\d+/
22
+ ports.push(line)
23
+ else
24
+ ports[-1] = "#{ports[-1]} #{line}"
25
+ end
26
+ end
27
+
28
+ matched = client_line.match(/\Aclient (\d+): '(.+)' \[(.+)\]\z/)
29
+ id = matched[1].to_i
30
+ name = matched[2].strip
31
+ tags = matched[3].split(',').map { |l| l.split('=') }.to_h
32
+ {
33
+ id: id,
34
+ name: name,
35
+ type: tags['type'],
36
+ card: tags['card'],
37
+ pid: tags['pid'],
38
+ ports: ports
39
+ }
40
+ end
41
+
42
+ def parse_port(output)
43
+ matched = output.match(/\A(\d) '(.+)'/)
44
+ id = matched[1].to_i
45
+ name = matched[2].strip
46
+ connected_to_type = nil
47
+ connected_to_client_id = nil
48
+ connected_to_port_id = nil
49
+
50
+ matched_from = output.match(/Connected From: (\d):(\d)\z/)
51
+ if matched_from
52
+ connected_to_type = :input
53
+ connected_to_client_id = matched_from[1]
54
+ connected_to_port_id = matched_from[2]
55
+ end
56
+
57
+ matched_from = output.match(/Connected To: (\d):(\d)\z/)
58
+ if matched_from
59
+ connected_to_type = :output
60
+ connected_to_client_id = matched_from[1]
61
+ connected_to_port_id = matched_from[2]
62
+ end
63
+
64
+ {
65
+ id: id,
66
+ name: name,
67
+ connected_to_type: connected_to_type,
68
+ connected_to_client_id: connected_to_client_id,
69
+ connected_to_port_id: connected_to_port_id
70
+ }
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ALSA
4
+ module Aconnect
5
+ class Port
6
+ attr_reader :id,
7
+ :name,
8
+ :client,
9
+ :connected_to_type,
10
+ :connected_to_client_id,
11
+ :connected_to_port_id
12
+
13
+ def initialize(text, client)
14
+ @client = client
15
+
16
+ data = Parser.parse_port(text)
17
+ @id = data[:id]
18
+ @name = data[:name]
19
+ @connected_to_type = data[:connected_to_type]
20
+ @connected_to_client_id = data[:connected_to_client_id]
21
+ @connected_to_port_id = data[:connected_to_port_id]
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ALSA
4
+ module Aconnect
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ module ALSA
6
+ # Util class for shell commands execution
7
+ class Command
8
+ def self.run(command, *arguments, **options)
9
+ new(command, arguments, options).run
10
+ end
11
+
12
+ attr_reader :command, :arguments, :env, :out, :err
13
+
14
+ def initialize(command, arguments, env: {}, out: nil, err: nil)
15
+ @command = command
16
+ @arguments = arguments
17
+ @env = env
18
+ @out = out
19
+ @err = err
20
+ @out_buff = []
21
+ @err_buff = []
22
+ end
23
+
24
+ def run
25
+ env_line = env.map { |k, v| "#{k}=#{v}" }.join(' ')
26
+ command_line = ([env_line, command] + arguments).reject(&:empty?).join(' ')
27
+
28
+ code = raw_execute(command_line)
29
+ [code, @out_buff, @err_buff]
30
+ end
31
+
32
+ private
33
+
34
+ def raw_execute(command_line)
35
+ Open3.popen3(command_line) do |_stdin, stdout, stderr, wait_thread|
36
+ Thread.new do
37
+ begin
38
+ until (raw_line = stdout.gets).nil?
39
+ @out_buff.push(raw_line)
40
+ out&.call(raw_line)
41
+ end
42
+ rescue IOError => _e
43
+ # command process was closed and it's ok
44
+ end
45
+ end
46
+ Thread.new do
47
+ begin
48
+ until (raw_line = stderr.gets).nil?
49
+ @err_buff.push(raw_line)
50
+ err&.call(raw_line)
51
+ end
52
+ rescue IOError => _e
53
+ # command process was closed and it's ok
54
+ end
55
+ end
56
+ wait_thread.value
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'alsa/aconnect'
data/man.txt ADDED
@@ -0,0 +1,80 @@
1
+ aconnect(1) General Commands Manual aconnect(1)
2
+
3
+ NAME
4
+ aconnect - ALSA sequencer connection manager
5
+
6
+ SYNOPSIS
7
+ aconnect [-d] [-options] sender receiver
8
+ aconnect -i|-o [-options]
9
+ aconnect -x
10
+
11
+ DESCRIPTION
12
+ aconnect is a utility to connect and disconnect two existing ports on ALSA sequencer system. The ports with the arbitrary subscription permission, such
13
+ as created by aseqview(1), can be connected to any (MIDI) device ports using aconnect. For example, to connect from port 64:0 to 65:0, run as follows:
14
+
15
+ % aconnect 64:0 65:0
16
+
17
+ The connection is one-way, and the whole data to the sender port (64:0) is redirected to the receiver port (65:0). When another port (e.g. 65:1) is at‐
18
+ tached to the same sender port, the data is sent to both receiver ports. For disconnection, use -d option.
19
+
20
+ % aconnect -d 64:0 65:0
21
+
22
+ The address can be given using the client's name.
23
+
24
+ % aconnect External:0 Emu8000:1
25
+
26
+ Then the port 0 of the client matching with the string "External" is connected to the port 1 of the client matching with the "Emu8000".
27
+
28
+ Another function of aconnect is to list the present ports on the given condition. The input ports, which may become sender ports, can be listed with -i
29
+ option.
30
+
31
+ % aconnect -i
32
+ client 0: 'System' [type=kernel]
33
+ 0 'Timer '
34
+ 1 'Announce '
35
+ client 64: 'External MIDI-0' [type=kernel]
36
+ 0 'MIDI 0-0 '
37
+
38
+ Similarly, to see the output ports, use -o flag.
39
+
40
+ You can remove all existing exported connections using -x option. This function is useful for terminating the ALSA drivers, because the modules with se‐
41
+ quencer connections cannot be unloaded unless their connections are removed.
42
+
43
+ OPTIONS
44
+ CONNECTION MANAGEMENT
45
+ -d, --disconnect
46
+ Disconnect the given subscription.
47
+
48
+ -e, --exclusive
49
+ Connect ports with exclusive mode. Both sender and receiver ports can be no longer connected by any other ports.
50
+
51
+ -r, --real queue
52
+ Convert time-stamps of event packets to the current value of the given real-time queue. This is option is, however, not so useful, since the re‐
53
+ ceiver port must use (not necessarily own) the specified queue.
54
+
55
+ -t, --tick queue
56
+ Like -r option, but time-stamps are converted to the current value of the given tick queue.
57
+
58
+ LIST PORTS
59
+ -i, --input
60
+ List existing input (readable) ports. This option is exclusive to -o.
61
+
62
+ -o, --output
63
+ List existing output (writable) ports. This option is exclusive to -i.
64
+
65
+ -l, --list
66
+ List the current connection status. The connected and connecting ports from/to each port are listed together. The suffix flag [ex] means the
67
+ connection is exclusive. The suffix flag [real:#] and [tick:#] mean the connection includes real-time and tick conversion on the listed queue,
68
+ respectively.
69
+
70
+ REMOVE ALL CONNECTIONS
71
+ -x, --removeall
72
+ Remove all exported connections.
73
+
74
+ SEE ALSO
75
+ aseqnet(1), aseqview(1)
76
+
77
+ AUTHOR
78
+ Takashi Iwai <tiwai@suse.de>
79
+
80
+ August 31, 2000 aconnect(1)
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alsa_aconnect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Denis Talakevich
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Control ALSA aconnect util through ruby with zero dependency
14
+ email:
15
+ - senid231@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rubocop.yml"
22
+ - ".travis.yml"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - alsa_aconnect.gemspec
30
+ - bin/console
31
+ - bin/setup
32
+ - examples/midi_keyboard.rb
33
+ - lib/alsa/aconnect.rb
34
+ - lib/alsa/aconnect/client.rb
35
+ - lib/alsa/aconnect/cmd.rb
36
+ - lib/alsa/aconnect/error.rb
37
+ - lib/alsa/aconnect/parser.rb
38
+ - lib/alsa/aconnect/port.rb
39
+ - lib/alsa/aconnect/version.rb
40
+ - lib/alsa/command.rb
41
+ - lib/alsa_aconnect.rb
42
+ - man.txt
43
+ homepage: https://github.com/senid231/alsa_aconnect
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: https://github.com/senid231/alsa_aconnect
48
+ source_code_uri: https://github.com/senid231/alsa_aconnect
49
+ changelog_uri: https://github.com/senid231/alsa_aconnect/blob/master/CHANGELOG.md
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 2.3.0
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubygems_version: 3.1.2
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Control ALSA aconnect util through ruby with zero dependency
69
+ test_files: []