pulseaudio 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/pulseaudio.rb +120 -0
- data/spec/pulseaudio_spec.rb +12 -0
- data/spec/spec_helper.rb +12 -0
- metadata +135 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "wref"
|
6
|
+
|
7
|
+
# Add dependencies to develop your gem here.
|
8
|
+
# Include everything needed to run rake, tests, features, etc.
|
9
|
+
group :development do
|
10
|
+
gem "rspec", "~> 2.8.0"
|
11
|
+
gem "rdoc", "~> 3.12"
|
12
|
+
gem "bundler", ">= 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.8.3"
|
14
|
+
gem "rcov", ">= 0"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.8.3)
|
7
|
+
bundler (~> 1.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rdoc
|
11
|
+
json (1.7.3)
|
12
|
+
rake (0.9.2.2)
|
13
|
+
rcov (0.9.11)
|
14
|
+
rdoc (3.12)
|
15
|
+
json (~> 1.4)
|
16
|
+
rspec (2.8.0)
|
17
|
+
rspec-core (~> 2.8.0)
|
18
|
+
rspec-expectations (~> 2.8.0)
|
19
|
+
rspec-mocks (~> 2.8.0)
|
20
|
+
rspec-core (2.8.0)
|
21
|
+
rspec-expectations (2.8.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.8.0)
|
24
|
+
wref (0.0.2)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
bundler (>= 1.0.0)
|
31
|
+
jeweler (~> 1.8.3)
|
32
|
+
rcov
|
33
|
+
rdoc (~> 3.12)
|
34
|
+
rspec (~> 2.8.0)
|
35
|
+
wref
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Kasper Johansen
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= pulseaudio
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to pulseaudio
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Kasper Johansen. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "pulseaudio"
|
18
|
+
gem.homepage = "http://github.com/kaspernj/pulseaudio"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby-library for controlling PulseAudio.}
|
21
|
+
gem.description = %Q{Ruby-library for controlling PulseAudio via 'pactl'.}
|
22
|
+
gem.email = "k@spernj.org"
|
23
|
+
gem.authors = ["Kasper Johansen"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "pulseaudio #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/pulseaudio.rb
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
#A framework for controlling various elements of PulseAudio in Ruby.
|
2
|
+
class PulseAudio
|
3
|
+
#Class for controlling sinks. The sinks on the sytem can be gotten by running the list-method.
|
4
|
+
#===Examples
|
5
|
+
# sinks = PulseAudio::Sink.list
|
6
|
+
# sinks.each do |sink|
|
7
|
+
# sink.vol_decr if sink.active?
|
8
|
+
# end
|
9
|
+
class Sink
|
10
|
+
#The arguments-hash. Contains various data for the sink.
|
11
|
+
attr_reader :args
|
12
|
+
|
13
|
+
require "wref"
|
14
|
+
@@sinks = Wref_map.new
|
15
|
+
|
16
|
+
#Returns a list of sinks on the system. It also reloads information for all sinks if the information has been changed.
|
17
|
+
#===Examples
|
18
|
+
# sinks = PulseAudio::Sink.list
|
19
|
+
# sinks.each do |sink|
|
20
|
+
# sink.vol_decr if sink.active?
|
21
|
+
# end
|
22
|
+
def self.list
|
23
|
+
list = %x[pactl list sinks]
|
24
|
+
sinks = [] unless block_given?
|
25
|
+
|
26
|
+
list.scan(/(\n|^)Sink #(\d+)\s+([\s\S]+?)Formats:\s+(.+?)\n/) do |match|
|
27
|
+
props = {}
|
28
|
+
match[2].scan(/(\t|^)([A-z]+?): (.+?)\n/) do |match_prop|
|
29
|
+
props[match_prop[1].downcase] = match_prop[2]
|
30
|
+
end
|
31
|
+
|
32
|
+
sink_id = match[1].to_i
|
33
|
+
args = {:sink_id => sink_id, :props => props}
|
34
|
+
|
35
|
+
sink = @@sinks.get!(sink_id)
|
36
|
+
if !sink
|
37
|
+
sink = PulseAudio::Sink.new
|
38
|
+
@@sinks[sink_id] = sink
|
39
|
+
end
|
40
|
+
|
41
|
+
sink.update(args)
|
42
|
+
|
43
|
+
if block_given?
|
44
|
+
yield(sink)
|
45
|
+
else
|
46
|
+
sinks << sink
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
return sinks if !block_given?
|
51
|
+
end
|
52
|
+
|
53
|
+
def update(args)
|
54
|
+
@args = args
|
55
|
+
end
|
56
|
+
|
57
|
+
#Returns the ID of the sink.
|
58
|
+
#===Examples
|
59
|
+
# sink.sink_id #=> 2
|
60
|
+
def sink_id
|
61
|
+
return @args[:sink_id].to_i
|
62
|
+
end
|
63
|
+
|
64
|
+
#Returns true if the sink is active. Otherwise false.
|
65
|
+
#===Examples
|
66
|
+
# sink.active? #=> true
|
67
|
+
def active?
|
68
|
+
return true if @args[:props]["state"].to_s.downcase == "running"
|
69
|
+
return false
|
70
|
+
end
|
71
|
+
|
72
|
+
#Returns true if the sink is muted. Otherwise false.
|
73
|
+
#===Examples
|
74
|
+
# sink.muted? #=> false
|
75
|
+
def muted?
|
76
|
+
return true if @args[:props]["mute"] == "yes"
|
77
|
+
return false
|
78
|
+
end
|
79
|
+
|
80
|
+
#Toggles the mute-functionality of the sink. If it is muted: unmutes. If it isnt muted: mutes.
|
81
|
+
#===Examples
|
82
|
+
# sink.mute_toggle #=> nil
|
83
|
+
def mute_toggle
|
84
|
+
self.mute = !self.muted?
|
85
|
+
return nil
|
86
|
+
end
|
87
|
+
|
88
|
+
#Sets the mute to something specific.
|
89
|
+
#===Examples
|
90
|
+
# sink.mute = true #=> nil
|
91
|
+
def mute=(val)
|
92
|
+
if val
|
93
|
+
%x[pactl set-sink-mute #{self.sink_id} 1]
|
94
|
+
else
|
95
|
+
%x[pactl set-sink-mute #{self.sink_id} 0]
|
96
|
+
end
|
97
|
+
|
98
|
+
PulseAudio::Sink.list #reload info.
|
99
|
+
return nil
|
100
|
+
end
|
101
|
+
|
102
|
+
#Increases the volume of the sink by 5%.
|
103
|
+
#===Examples
|
104
|
+
# sink.vol_incr if sink.active? #=> nil
|
105
|
+
def vol_incr
|
106
|
+
%x[pactl set-sink-volume #{self.sink_id} -- +5%]
|
107
|
+
PulseAudio::Sink.list #reload info.
|
108
|
+
return nil
|
109
|
+
end
|
110
|
+
|
111
|
+
#Decreases the volume of the sink by 5%.
|
112
|
+
#===Examples
|
113
|
+
# sink.vol_decr if sink.active? #=> nil
|
114
|
+
def vol_decr
|
115
|
+
%x[pactl set-sink-volume #{self.sink_id} -- -5%]
|
116
|
+
PulseAudio::Sink.list #reload info.
|
117
|
+
return nil
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Pulseaudio" do
|
4
|
+
it "should spawn sinks and manipulate them" do
|
5
|
+
PulseAudio::Sink.list do |sink|
|
6
|
+
sink.vol_decr
|
7
|
+
sink.vol_incr
|
8
|
+
sink.mute_toggle
|
9
|
+
sink.mute_toggle
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'pulseaudio'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pulseaudio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kasper Johansen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-05-21 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: wref
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.8.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: rdoc
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "3.12"
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: bundler
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.0.0
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: jeweler
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.8.3
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rcov
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
82
|
+
description: Ruby-library for controlling PulseAudio via 'pactl'.
|
83
|
+
email: k@spernj.org
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files:
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.rdoc
|
91
|
+
files:
|
92
|
+
- .document
|
93
|
+
- .rspec
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.rdoc
|
98
|
+
- Rakefile
|
99
|
+
- VERSION
|
100
|
+
- lib/pulseaudio.rb
|
101
|
+
- spec/pulseaudio_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
has_rdoc: true
|
104
|
+
homepage: http://github.com/kaspernj/pulseaudio
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
hash: 345928334092253722
|
118
|
+
segments:
|
119
|
+
- 0
|
120
|
+
version: "0"
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: "0"
|
127
|
+
requirements: []
|
128
|
+
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 1.6.2
|
131
|
+
signing_key:
|
132
|
+
specification_version: 3
|
133
|
+
summary: Ruby-library for controlling PulseAudio.
|
134
|
+
test_files: []
|
135
|
+
|