audio_switch 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/audio_switch +4 -3
- data/lib/audio_switch.rb +10 -0
- data/lib/audio_switch/model.rb +7 -1
- data/lib/audio_switch/pactl.rb +10 -3
- data/lib/audio_switch/ui.rb +13 -1
- data/lib/audio_switch/version.rb +1 -1
- metadata +25 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e12eb2e9ceb73f7771435e76da09d68020e74f35d31bc61915a6e9d7f7ca87bd
|
4
|
+
data.tar.gz: 43cb348f9dae56a5e4f19beabfe58a1b3cf79af680c7059c0c59b0b19c5faf4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7603a6c6191c08d7ebd6edae406b125ac6a3950ee49ab80aeaabd053844cc6c5031f67340e10ff7d3edaadc2b19fdb29fc8eea1cca939f3b82254c00b04b0dc1
|
7
|
+
data.tar.gz: b3b9973abce4f4e3432484a74ef5f76d2b7c86f36fca180a4a0327328cf757ba342f96aa765a60ff0b0eee0047594246c0001090d9b9f7348c2899e511f1e19a
|
data/bin/audio_switch
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require_relative '../lib/audio_switch'
|
3
3
|
|
4
4
|
begin
|
5
|
-
puts "audio_switch version #{AudioSwitch::VERSION}"
|
6
5
|
AudioSwitch::App.start
|
7
6
|
rescue Interrupt
|
8
|
-
|
7
|
+
AudioSwitch::LOG.info('exit')
|
8
|
+
rescue StandardError => e
|
9
|
+
AudioSwitch::LOG.error('uncaught') { e }
|
9
10
|
end
|
data/lib/audio_switch.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
|
+
require 'logger'
|
1
2
|
require_relative 'audio_switch/pactl.rb'
|
2
3
|
require_relative 'audio_switch/model.rb'
|
3
4
|
require_relative 'audio_switch/ui.rb'
|
4
5
|
require_relative 'audio_switch/version.rb'
|
5
6
|
|
6
7
|
module AudioSwitch
|
8
|
+
LOG = Logger.new("#{Dir.home}/.audio_switch/audio_switch.log", 'daily')
|
9
|
+
LOG.level = Logger::INFO
|
10
|
+
|
7
11
|
module App
|
8
12
|
def self.start
|
13
|
+
AudioSwitch::LOG.info("starting audio_switch #{AudioSwitch::VERSION}")
|
9
14
|
pactl = AudioSwitch::Pactl.new
|
10
15
|
model = AudioSwitch::Model.new(pactl)
|
11
16
|
ui = AudioSwitch::UI.new(model)
|
12
17
|
ui.start
|
13
18
|
end
|
19
|
+
|
20
|
+
def self.quit
|
21
|
+
AudioSwitch::LOG.info('quitting audio_switch')
|
22
|
+
exit
|
23
|
+
end
|
14
24
|
end
|
15
25
|
end
|
data/lib/audio_switch/model.rb
CHANGED
@@ -14,6 +14,7 @@ module AudioSwitch
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def select_sink(sink_id)
|
17
|
+
AudioSwitch::LOG.info "selecting sink '#{sink_id}'"
|
17
18
|
@pactl.default_sink = sink_id
|
18
19
|
@pactl.inputs.each do |input|
|
19
20
|
@pactl.move_input(input[:id], sink_id)
|
@@ -27,10 +28,12 @@ module AudioSwitch
|
|
27
28
|
def rtp_on?
|
28
29
|
return false unless @pactl.sinks.any? { |sink| sink[:name] == RTP }
|
29
30
|
return false unless @pactl.modules.any? { |mod| mod[:name] == MODULE_RTP_SEND }
|
31
|
+
|
30
32
|
true
|
31
33
|
end
|
32
34
|
|
33
35
|
def rtp_on
|
36
|
+
AudioSwitch::LOG.info 'turning RTP on'
|
34
37
|
# prevent positive feedback loop
|
35
38
|
mute_sources
|
36
39
|
# see https://cgit.freedesktop.org/pulseaudio/paprefs/tree/src/paprefs.cc
|
@@ -51,17 +54,20 @@ module AudioSwitch
|
|
51
54
|
end
|
52
55
|
|
53
56
|
def rtp_off
|
57
|
+
AudioSwitch::LOG.info 'turning RTP off'
|
54
58
|
@pactl.unload_module(MODULE_RTP_SEND)
|
55
59
|
@pactl.unload_module(MODULE_NULL_SINK)
|
56
60
|
end
|
57
61
|
|
58
62
|
def mute_sources
|
63
|
+
AudioSwitch::LOG.info 'muting all sources'
|
59
64
|
sources.each do |source|
|
60
65
|
@pactl.mute_source(source[:id])
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
64
69
|
def unmute_sources
|
70
|
+
AudioSwitch::LOG.info 'unmuting all sources'
|
65
71
|
sources.each do |source|
|
66
72
|
@pactl.unmute_source(source[:id])
|
67
73
|
end
|
@@ -74,7 +80,7 @@ module AudioSwitch
|
|
74
80
|
private
|
75
81
|
|
76
82
|
def sources
|
77
|
-
@pactl.sources.
|
83
|
+
@pactl.sources.reject { |source| source[:name] == 'rtp.monitor' }
|
78
84
|
end
|
79
85
|
|
80
86
|
def handle(event, block)
|
data/lib/audio_switch/pactl.rb
CHANGED
@@ -3,10 +3,12 @@ require 'pty'
|
|
3
3
|
module AudioSwitch
|
4
4
|
class Pactl
|
5
5
|
def move_input(input_id, sink_id)
|
6
|
+
AudioSwitch::LOG.info "moving sink input '#{input_id}' to sink '#{sink_id}'"
|
6
7
|
`pactl move-sink-input #{input_id} #{sink_id}`
|
7
8
|
end
|
8
9
|
|
9
10
|
def default_sink=(sink_id)
|
11
|
+
AudioSwitch::LOG.info "setting default sink to '#{sink_id}'"
|
10
12
|
# pactl doesn't have this command
|
11
13
|
`pacmd set-default-sink #{sink_id}`
|
12
14
|
end
|
@@ -29,31 +31,36 @@ module AudioSwitch
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def load_module(mod, options = {})
|
34
|
+
AudioSwitch::LOG.info "loading module '#{mod}' with options '#{options}'"
|
32
35
|
`pactl load-module #{mod} #{ModuleOptions.new(options)}`
|
33
36
|
end
|
34
37
|
|
35
38
|
def unload_module(mod)
|
39
|
+
AudioSwitch::LOG.info "unloading module '#{mod}'"
|
36
40
|
`pactl unload-module #{mod}`
|
37
41
|
end
|
38
42
|
|
39
43
|
def subscribe(command = 'pactl subscribe')
|
40
44
|
Thread.start do
|
45
|
+
AudioSwitch::LOG.info "starting '#{command}'"
|
41
46
|
@pactl_sub = PTY.spawn(command)[0]
|
42
47
|
begin
|
43
48
|
@pactl_sub.each do |line|
|
44
49
|
yield(Out.new(line).parse_event)
|
45
50
|
end
|
46
|
-
rescue Errno::EIO, IOError
|
47
|
-
|
51
|
+
rescue Errno::EIO, IOError => e
|
52
|
+
AudioSwitch::LOG.error("reading '#{command}' output") { e }
|
48
53
|
end
|
49
54
|
end
|
50
55
|
end
|
51
56
|
|
52
57
|
def mute_source(source_id)
|
58
|
+
AudioSwitch::LOG.info "muting source '#{source_id}'"
|
53
59
|
`pactl set-source-mute #{source_id} true`
|
54
60
|
end
|
55
61
|
|
56
62
|
def unmute_source(source_id)
|
63
|
+
AudioSwitch::LOG.info "unmuting source '#{source_id}'"
|
57
64
|
`pactl set-source-mute #{source_id} false`
|
58
65
|
end
|
59
66
|
|
@@ -116,7 +123,7 @@ module AudioSwitch
|
|
116
123
|
field = fields[field_id]
|
117
124
|
next unless line =~ Regexp.new(field[:marker])
|
118
125
|
|
119
|
-
object = {} if field_id
|
126
|
+
object = {} if field_id.zero?
|
120
127
|
update(object, line, field)
|
121
128
|
|
122
129
|
field_id += 1
|
data/lib/audio_switch/ui.rb
CHANGED
@@ -33,10 +33,14 @@ module AudioSwitch
|
|
33
33
|
|
34
34
|
def draw(sinks)
|
35
35
|
clear
|
36
|
-
sinks
|
36
|
+
sinks
|
37
|
+
.sort_by { |sink| sink[:description] }
|
38
|
+
.each { |sink| add new_item(sink) }
|
37
39
|
add new_separator
|
38
40
|
add new_rtp_toggle
|
39
41
|
add new_mute_toggle
|
42
|
+
add new_separator
|
43
|
+
add new_quit_item
|
40
44
|
end
|
41
45
|
|
42
46
|
def add(item)
|
@@ -81,6 +85,14 @@ module AudioSwitch
|
|
81
85
|
toggle
|
82
86
|
end
|
83
87
|
|
88
|
+
def new_quit_item
|
89
|
+
item = Gtk::MenuItem.new('Quit')
|
90
|
+
item.signal_connect('activate') do
|
91
|
+
AudioSwitch::App.quit
|
92
|
+
end
|
93
|
+
item
|
94
|
+
end
|
95
|
+
|
84
96
|
def new_separator
|
85
97
|
Gtk::SeparatorMenuItem.new
|
86
98
|
end
|
data/lib/audio_switch/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: audio_switch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatolii Saienko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gtk2
|
@@ -67,47 +67,61 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '11.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.5'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '3.5'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
84
|
+
name: rspec-wait
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.0.9
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.0.9
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rubocop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
103
|
+
version: 0.75.1
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
110
|
+
version: 0.75.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: solargraph
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: Ubuntu applet that lets you switch audio sinks, toggle RTP sender and
|
112
126
|
inputs. Depends on PulseAudio and libappindicator-dev.
|
113
127
|
email:
|