Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

autodetect sound card for pulseaudio

  • Loading branch information...
commit 569b12b804f7b80c36cd40998f308f08741bf693 1 parent df70812
@msoap authored
View
4 helpers/mojolicious-radio-box.ini.sample
@@ -10,3 +10,7 @@ listen_address = http://*:8080
# settings for hypnotoad server
hypnotoad_workers = 3
hypnotoad_accept_interval = 0.3
+
+# PulseAudio settings
+# if sound-card dont autodetect, uncomment this and set your soundcard id
+# pa-default-sink = 0
View
10 mojolicious-radio-box.pl
@@ -49,6 +49,12 @@ sub init {
$OPTIONS{is_linux} = 1 if $^O eq 'linux';
$OPTIONS{is_pulseaudio} = 1 if $OPTIONS{is_linux} && `pacmd --version` =~ m/^pacmd\s+\d+/;
$OPTIONS{is_alsa} = 1 if $OPTIONS{is_linux} && `amixer --version` =~ m/^amixer\s+version\s+\d+/;
+
+ # get default sound card for pulseaudio
+ if ($OPTIONS{is_pulseaudio} && ! defined $OPTIONS{"pa-default-sink"}) {
+ $OPTIONS{"pa-default-sink"} = `pacmd dump | grep set-default-sink | awk '{print $2}'`;
+ $OPTIONS{"pa-default-sink"} = "0" unless defined $OPTIONS{"pa-default-sink"} && length($OPTIONS{"pa-default-sink"}) > 0;
+ }
}
# ------------------------------------------------------------------------------
@@ -143,7 +149,7 @@ sub cmus_get_info {
if ($OPTIONS{is_mac}) {
$info->{volume} = int(`osascript -e "output volume of (get volume settings)"`);
} elsif ($OPTIONS{is_pulseaudio}) {
- my ($pa_info) = grep {/set-sink-volume/} `pacmd dump`;
+ my ($pa_info) = grep {/set-sink-volume/ && /\Q$OPTIONS{"pa-default-sink"}\E/} `pacmd dump`;
$pa_info =~ /\s+ ([0-9a-fx]+) \s* $/xi;
if (defined $1 && hex($1) >= 0) {
$info->{volume} = int(sprintf("%0.0f", hex($1) / 65536 * 100));
@@ -297,7 +303,7 @@ sub cmus_set_volume {
if ($OPTIONS{is_mac}) {
system("osascript", "-e", "set volume output volume $volume");
} elsif ($OPTIONS{is_pulseaudio}) {
- system("pactl", "set-sink-volume", "0", "${volume}%");
+ system("pactl", "set-sink-volume", $OPTIONS{"pa-default-sink"}, "${volume}%");
} elsif ($OPTIONS{is_alsa}) {
system("amixer", "-q", "set", "Master", "${volume}%");
}
View
4 src/cmus-client.pm
@@ -41,7 +41,7 @@ sub cmus_get_info {
if ($OPTIONS{is_mac}) {
$info->{volume} = int(`osascript -e "output volume of (get volume settings)"`);
} elsif ($OPTIONS{is_pulseaudio}) {
- my ($pa_info) = grep {/set-sink-volume/} `pacmd dump`;
+ my ($pa_info) = grep {/set-sink-volume/ && /\Q$OPTIONS{"pa-default-sink"}\E/} `pacmd dump`;
$pa_info =~ /\s+ ([0-9a-fx]+) \s* $/xi;
if (defined $1 && hex($1) >= 0) {
$info->{volume} = int(sprintf("%0.0f", hex($1) / 65536 * 100));
@@ -195,7 +195,7 @@ sub cmus_set_volume {
if ($OPTIONS{is_mac}) {
system("osascript", "-e", "set volume output volume $volume");
} elsif ($OPTIONS{is_pulseaudio}) {
- system("pactl", "set-sink-volume", "0", "${volume}%");
+ system("pactl", "set-sink-volume", $OPTIONS{"pa-default-sink"}, "${volume}%");
} elsif ($OPTIONS{is_alsa}) {
system("amixer", "-q", "set", "Master", "${volume}%");
}
View
6 src/util.pm
@@ -17,6 +17,12 @@ sub init {
$OPTIONS{is_linux} = 1 if $^O eq 'linux';
$OPTIONS{is_pulseaudio} = 1 if $OPTIONS{is_linux} && `pacmd --version` =~ m/^pacmd\s+\d+/;
$OPTIONS{is_alsa} = 1 if $OPTIONS{is_linux} && `amixer --version` =~ m/^amixer\s+version\s+\d+/;
+
+ # get default sound card for pulseaudio
+ if ($OPTIONS{is_pulseaudio} && ! defined $OPTIONS{"pa-default-sink"}) {
+ $OPTIONS{"pa-default-sink"} = `pacmd dump | grep set-default-sink | awk '{print $2}'`;
+ $OPTIONS{"pa-default-sink"} = "0" unless defined $OPTIONS{"pa-default-sink"} && length($OPTIONS{"pa-default-sink"}) > 0;
+ }
}
# ------------------------------------------------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.