version 1.1, 2006/03/02 23:20:47 |
version 1.4, 2011/06/14 18:04:58 |
|
|
#!/usr/bin/perl -Tw |
#!/usr/bin/perl -Tw |
|
# $AFresh1$ |
######################################################################## |
######################################################################## |
# Mixer.pl *** Changes volume on the MP3 player |
# Mixer.pl *** Changes volume on the MP3 player |
# |
# |
|
|
# Written by andrew fresh <andrew@mad-techies.org> |
# Written by andrew fresh <andrew@mad-techies.org> |
######################################################################## |
######################################################################## |
use strict; |
use strict; |
use diagnostics; |
use warnings; |
|
|
my $mixerctl = '/usr/bin/mixerctl'; |
my $mixerctl = '/usr/bin/mixerctl'; |
|
|
|
|
|
|
delete $ENV{PATH} if exists $ENV{PATH}; |
delete $ENV{PATH} if exists $ENV{PATH}; |
|
|
|
my $paused_file = '/var/www/mp3/playlist/paused'; |
|
|
my @Vols = ( |
my @Vols = ( |
[ 7, 7], |
7, |
[ 15, 15], |
15, |
[ 23, 23], |
23, |
[ 31, 31], |
31, |
[ 39, 39], |
39, |
[ 47, 47], |
47, |
[ 55, 55], |
55, |
[ 63, 63], |
63, |
[ 71, 71], |
71, |
[ 79, 79], |
79, |
[ 87, 87], |
87, |
[ 95, 95], |
95, |
[103, 103], |
103, |
[111, 111], |
111, |
[119, 119], |
119, |
[127, 127], |
127, |
[135, 135], |
135, |
[143, 143], |
143, |
[151, 151], |
151, |
[159, 159], |
159, |
[167, 167], |
167, |
[175, 175], |
175, |
[183, 183], |
183, |
[191, 191], |
191, |
[199, 199], |
199, |
[207, 207], |
207, |
[215, 215], |
215, |
[223, 223], |
223, |
[231, 231], |
231, |
[239, 239], |
239, |
[247, 247], |
247, |
[255, 255], |
255, |
); |
); |
|
|
|
|
my $Cur_Vol = `$mixerctl outputs.master`; |
my $Cur_Vol = `$mixerctl outputs.master`; |
#»print "Cur_Vol $Cur_Vol<BR>\n"; |
#»print "Cur_Vol $Cur_Vol<BR>\n"; |
$Cur_Vol =~ /outputs.master=(\d+),(\d+)/i; |
$Cur_Vol =~ /outputs.master=(\d+),(\d+)/i; |
my $Cur_Vol_Left = $1; |
$Cur_Vol = ($1 + $2) / 2; |
my $Cur_Vol_Right = $2; |
|
|
|
|
my $pause_action = 'pause'; |
|
if (-e $paused_file) { |
|
$pause_action = 'play'; |
|
} |
print "Content-Type: text/html\n\n"; |
print "Content-Type: text/html\n\n"; |
print "<html>\n<head>\n\t<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'> "; |
print "<html>\n<head>\n\t<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'> "; |
|
|
my $New_Vol = "$Cur_Vol_Left&$Cur_Vol_Right"; |
my ($prefix, $action) = split /\&/, $ENV{'QUERY_STRING'}; |
if ($ENV{'QUERY_STRING'}) { |
$prefix ||= ''; |
print "<meta HTTP-EQUIV=Refresh CONTENT=\"1; URL=mixer.pl\">"; |
if ($action) { |
$New_Vol = $ENV{'QUERY_STRING'}; |
$prefix =~ s/%(..)/pack("c",hex($1))/ge if $prefix; |
|
$action =~ s/%(..)/pack("c",hex($1))/ge; |
|
|
|
print "<meta HTTP-EQUIV=Refresh CONTENT=\"1; URL=mixer.pl?" . EncodeURL($prefix) . "\">"; |
|
|
|
if ($action eq 'pause') { $pause_action = Pause($pause_action) } |
|
elsif ($action =~ /^(\d+)$/) { $Cur_Vol = Set_Vol($Cur_Vol, $1); } |
|
|
} |
} |
|
|
print <<EOL; |
print <<EOL; |
|
|
|
|
Print_Nav(); |
Print_Nav(); |
|
|
print "Volume - "; |
unless ($prefix) { |
|
|
|
|
#»print "New_Vol $New_Vol<BR>\n"; |
|
$New_Vol =~ /(\d+)&(\d+)/; |
|
my $New_Vol_Left = $1; |
|
my $New_Vol_Right = $2; |
|
|
|
my @nav; |
my @nav; |
|
push @nav, "<B><A HREF='$me?" . EncodeURL($prefix) . '&' |
|
. "pause' class='pause'>$pause_action</A></B>\n"; |
|
push @nav, " - Volume: "; |
|
|
foreach my $vol (@Vols) { |
foreach my $vol (@Vols) { |
if ($$vol[0] == $New_Vol_Left) { |
my ($char, $class) = ($vol, 'up'); |
push @nav, "<B><A HREF='$me?$$vol[0]&$$vol[1]' class=up>$$vol[0]</A></B>\n"; |
|
} elsif ($$vol[0] < $New_Vol_Left) { |
if ($vol > $Cur_Vol) { ($char, $class) = ('}', 'up'); } |
push @nav, "<A HREF='$me?$$vol[0]&$$vol[1]' class=up>}</A>\n"; |
elsif ($vol < $Cur_Vol) { ($char, $class) = (']', 'down'); } |
} elsif ($$vol[0] > $New_Vol_Left) { |
|
push @nav, "<A HREF='$me?$$vol[0]&$$vol[1]' class=down>]</A>\n"; |
push @nav, "<B><A HREF='$me?" . EncodeURL($prefix) . '&' |
} |
. "$vol' class='$class'>$char</A></B>\n"; |
#print "$vol - $$vol[0] - $$vol[1]<br>\n"; |
|
} |
} |
print join " ", @nav; |
print join " ", @nav; |
#print "<br>\n"; |
#print "<br>\n"; |
|
} |
|
|
Set_Vol($Cur_Vol_Left, $Cur_Vol_Right, $New_Vol_Left, $New_Vol_Right); |
|
|
|
print "</body>\n</head>\n</html>\n"; |
print "</body>\n</head>\n</html>\n"; |
|
|
|
|
|
|
sub Set_Vol |
sub Set_Vol |
{ |
{ |
my $old_vol_right = shift; |
my ($old, $new) = @_; |
my $old_vol_left = shift; |
|
my $new_vol_left = shift; |
|
my $new_vol_right = shift; |
|
|
|
my $old_vol; |
|
my $new_vol; |
|
if (($old_vol_left + $old_vol_right) > ($new_vol_left + $new_vol_right)) { |
|
$old_vol = $old_vol_left > $old_vol_right ? $old_vol_left : $old_vol_right; |
|
$new_vol = $new_vol_left < $new_vol_right ? $new_vol_left : $new_vol_right; |
|
} else { |
|
$old_vol = $old_vol_left < $old_vol_right ? $old_vol_left : $old_vol_right; |
|
$new_vol = $new_vol_left > $new_vol_right ? $new_vol_left : $new_vol_right; |
|
} |
|
|
|
#»print "Old: $old_vol - New: $new_vol<br>\n"; |
|
|
|
my $Set_Vol; |
my $Set_Vol; |
|
foreach my $vol ($old < $new ? $old..$new : reverse $new..$old) { |
foreach my $vol ($old_vol < $new_vol ? $old_vol..$new_vol : reverse $new_vol..$old_vol) { |
|
#»print "$vol<br>\n"; |
|
$Set_Vol = `$mixerctl -w outputs.master=$vol,$vol`; |
$Set_Vol = `$mixerctl -w outputs.master=$vol,$vol`; |
#»print $Set_Vol . "<br>\n"; |
|
} |
} |
return $Set_Vol; |
return $new; |
} |
} |
|
|
|
sub Pause { |
|
my ($action) = @_; |
|
|
|
if ($action eq 'play') { |
|
unlink $paused_file; |
|
return 'pause'; |
|
} |
|
else { |
|
open my $fh, '>', $paused_file or die; |
|
print $fh time; |
|
close $fh; |
|
return 'play'; |
|
} |
|
} |
|
|
|
|
|
|
######################################################################## |
######################################################################## |
# *** EncodeURL: %encodes the parameters of the URL |
# *** EncodeURL: %encodes the parameters of the URL |
sub EncodeURL { |
sub EncodeURL { |
my $strURL = shift; |
my $strURL = shift || ''; |
$strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg; |
$strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg; |
return $strURL; |
return $strURL; |
} |
} |
|
|
{ |
{ |
open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!"; |
open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!"; |
while (<FILE>) { |
while (<FILE>) { |
|
s/%PREFIX%/$prefix/g; |
print; |
print; |
} |
} |
close FILE; |
close FILE; |