=================================================================== RCS file: /cvs/mp3/bin/mixer.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- mp3/bin/mixer.pl 2011/06/14 18:04:58 1.4 +++ mp3/bin/mixer.pl 2011/06/14 18:05:23 1.5 @@ -1,5 +1,5 @@ #!/usr/bin/perl -Tw -# $AFresh1$ +# $AFresh1: mixer.pl,v 1.4 2011/06/14 17:04:58 andrew Exp $ ######################################################################## # Mixer.pl *** Changes volume on the MP3 player # @@ -18,63 +18,35 @@ my $paused_file = '/var/www/mp3/playlist/paused'; my @Vols = ( - 7, - 15, - 23, - 31, - 39, - 47, - 55, - 63, - 71, - 79, - 87, - 95, - 103, - 111, - 119, - 127, - 135, - 143, - 151, - 159, - 167, - 175, - 183, - 191, - 199, - 207, - 215, - 223, - 231, - 239, - 247, - 255, - ); + 7, 15, 23, 31, 39, 47, 55, 63, 71, 79, 87, 95, + 103, 111, 119, 127, 135, 143, 151, 159, 167, 175, 183, 191, + 199, 207, 215, 223, 231, 239, 247, 255, +); - my $Cur_Vol = `$mixerctl outputs.master`; + #»print "Cur_Vol $Cur_Vol
\n"; $Cur_Vol =~ /outputs.master=(\d+),(\d+)/i; -$Cur_Vol = ($1 + $2) / 2; +$Cur_Vol = ( $1 + $2 ) / 2; my $pause_action = 'pause'; -if (-e $paused_file) { +if ( -e $paused_file ) { $pause_action = 'play'; } print "Content-Type: text/html\n\n"; print "\n\n\t "; -my ($prefix, $action) = split /\&/, $ENV{'QUERY_STRING'}; +my ( $prefix, $action ) = split /\&/, $ENV{'QUERY_STRING'}; $prefix ||= ''; if ($action) { $prefix =~ s/%(..)/pack("c",hex($1))/ge if $prefix; $action =~ s/%(..)/pack("c",hex($1))/ge; - print ""; + print ""; - if ($action eq 'pause') { $pause_action = Pause($pause_action) } - elsif ($action =~ /^(\d+)$/) { $Cur_Vol = Set_Vol($Cur_Vol, $1); } + if ( $action eq 'pause' ) { $pause_action = Pause($pause_action) } + elsif ( $action =~ /^(\d+)$/ ) { $Cur_Vol = Set_Vol( $Cur_Vol, $1 ); } } @@ -101,44 +73,46 @@ unless ($prefix) { -my @nav; -push @nav, "$pause_action\n"; -push @nav, " - Volume: "; + my @nav; + push @nav, + "$pause_action\n"; + push @nav, " - Volume: "; -foreach my $vol (@Vols) { - my ($char, $class) = ($vol, 'up'); + foreach my $vol (@Vols) { + my ( $char, $class ) = ( $vol, 'up' ); - if ($vol > $Cur_Vol) { ($char, $class) = ('}', 'up'); } - elsif ($vol < $Cur_Vol) { ($char, $class) = (']', 'down'); } + if ( $vol > $Cur_Vol ) { ( $char, $class ) = ( '}', 'up' ); } + elsif ( $vol < $Cur_Vol ) { ( $char, $class ) = ( ']', 'down' ); } - push @nav, "$char\n"; + push @nav, + "$char\n"; + } + print join " ", @nav; + + #print "
\n"; } -print join " ", @nav; -#print "
\n"; -} print "\n\n\n"; +sub Set_Vol { + my ( $old, $new ) = @_; - -sub Set_Vol -{ - my ($old, $new) = @_; - - my $Set_Vol; - foreach my $vol ($old < $new ? $old..$new : reverse $new..$old) { - $Set_Vol = `$mixerctl -w outputs.master=$vol,$vol`; - } - return $new; + my $Set_Vol; + foreach my $vol ( $old < $new ? $old .. $new : reverse $new .. $old ) { + $Set_Vol = `$mixerctl -w outputs.master=$vol,$vol`; + } + return $new; } sub Pause { my ($action) = @_; - if ($action eq 'play') { + if ( $action eq 'play' ) { unlink $paused_file; return 'pause'; } @@ -150,41 +124,38 @@ } } - - ######################################################################## # *** EncodeURL: %encodes the parameters of the URL sub EncodeURL { - my $strURL = shift || ''; - $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg; - return $strURL; + my $strURL = shift || ''; + $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg; + return $strURL; } ######################################################################### # My name sub MyName { - my @filename = (split /\//, $0); - pop @filename; + my @filename = ( split /\//, $0 ); + pop @filename; } - ####################################################################### # Bail: this subrouting dies and displays the error to the browser. -# gotten from the example in the O'Reilly +# gotten from the example in the O'Reilly # _Learning_Perl_on_Win32_Systems_ -sub bail { - my $error = shift; - print "\n\nUnexpected Error: $error
\n"; - print "In " . __FILE__ . "\n"; - die; - exit; +sub bail { + my $error = shift; + print "\n\nUnexpected Error: $error
\n"; + print "In " . __FILE__ . "\n"; + die; + exit; } -sub Print_Nav -{ - open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!"; - while () { - s/%PREFIX%/$prefix/g; - print; - } - close FILE; + +sub Print_Nav { + open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!"; + while () { + s/%PREFIX%/$prefix/g; + print; + } + close FILE; }