[BACK]Return to mixer.pl CVS log [TXT][DIR] Up to [local] / mp3 / bin

Diff for /mp3/bin/mixer.pl between version 1.4 and 1.5

version 1.4, 2011/06/14 18:04:58 version 1.5, 2011/06/14 18:05:23
Line 1 
Line 1 
 #!/usr/bin/perl -Tw  #!/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  # Mixer.pl *** Changes volume on the MP3 player
 #  #
Line 18 
Line 18 
 my $paused_file = '/var/www/mp3/playlist/paused';  my $paused_file = '/var/www/mp3/playlist/paused';
   
 my @Vols = (  my @Vols = (
               7,      7,   15,  23,  31,  39,  47,  55,  63,  71,  79,  87,  95,
              15,      103, 111, 119, 127, 135, 143, 151, 159, 167, 175, 183, 191,
              23,      199, 207, 215, 223, 231, 239, 247, 255,
              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`;  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;
 $Cur_Vol = ($1 + $2) / 2;  $Cur_Vol = ( $1 + $2 ) / 2;
   
 my $pause_action = 'pause';  my $pause_action = 'pause';
 if (-e $paused_file) {  if ( -e $paused_file ) {
     $pause_action = 'play';      $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 ($prefix, $action) = split /\&/, $ENV{'QUERY_STRING'};  my ( $prefix, $action ) = split /\&/, $ENV{'QUERY_STRING'};
 $prefix ||= '';  $prefix ||= '';
 if ($action) {  if ($action) {
     $prefix =~ s/%(..)/pack("c",hex($1))/ge if $prefix;      $prefix =~ s/%(..)/pack("c",hex($1))/ge if $prefix;
     $action =~ s/%(..)/pack("c",hex($1))/ge;      $action =~ s/%(..)/pack("c",hex($1))/ge;
   
         print "<meta HTTP-EQUIV=Refresh CONTENT=\"1; URL=mixer.pl?" . EncodeURL($prefix) . "\">";      print "<meta HTTP-EQUIV=Refresh CONTENT=\"1; URL=mixer.pl?"
           . EncodeURL($prefix) . "\">";
   
     if ($action eq 'pause') { $pause_action = Pause($pause_action) }      if ( $action eq 'pause' ) { $pause_action = Pause($pause_action) }
     elsif ($action =~ /^(\d+)$/)  { $Cur_Vol = Set_Vol($Cur_Vol, $1); }      elsif ( $action =~ /^(\d+)$/ ) { $Cur_Vol = Set_Vol( $Cur_Vol, $1 ); }
   
 }  }
   
Line 101 
Line 73 
   
 unless ($prefix) {  unless ($prefix) {
   
 my @nav;      my @nav;
 push @nav, "<B><A HREF='$me?" . EncodeURL($prefix) . '&'      push @nav,
      . "pause' class='pause'>$pause_action</A></B>\n";            "<B><A HREF='$me?"
 push @nav, " - Volume: ";          . EncodeURL($prefix) . '&'
           . "pause' class='pause'>$pause_action</A></B>\n";
       push @nav, " - Volume: ";
   
 foreach my $vol (@Vols) {      foreach my $vol (@Vols) {
     my ($char, $class) = ($vol, 'up');          my ( $char, $class ) = ( $vol, 'up' );
   
         if ($vol > $Cur_Vol) { ($char, $class) = ('}', 'up'); }          if    ( $vol > $Cur_Vol ) { ( $char, $class ) = ( '}', 'up' ); }
     elsif ($vol < $Cur_Vol) { ($char, $class) = (']', 'down'); }          elsif ( $vol < $Cur_Vol ) { ( $char, $class ) = ( ']', 'down' ); }
   
     push @nav, "<B><A HREF='$me?" . EncodeURL($prefix) . '&'          push @nav,
         . "$vol' class='$class'>$char</A></B>\n";                "<B><A HREF='$me?"
               . EncodeURL($prefix) . '&'
               . "$vol' class='$class'>$char</A></B>\n";
   
       }
       print join " ", @nav;
   
       #print "<br>\n";
 }  }
 print join " ", @nav;  
 #print "<br>\n";  
 }  
   
 print "</body>\n</head>\n</html>\n";  print "</body>\n</head>\n</html>\n";
   
   sub Set_Vol {
       my ( $old, $new ) = @_;
   
       my $Set_Vol;
 sub Set_Vol      foreach my $vol ( $old < $new ? $old .. $new : reverse $new .. $old ) {
 {          $Set_Vol = `$mixerctl -w outputs.master=$vol,$vol`;
     my ($old, $new) = @_;      }
       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 {  sub Pause {
     my ($action) = @_;      my ($action) = @_;
   
     if ($action eq 'play') {      if ( $action eq 'play' ) {
         unlink $paused_file;          unlink $paused_file;
         return 'pause';          return 'pause';
     }      }
Line 150 
Line 124 
     }      }
 }  }
   
   
   
 ########################################################################  ########################################################################
 # *** 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;
 }  }
   
 #########################################################################  #########################################################################
 # My name  # My name
 sub MyName {  sub MyName {
         my @filename = (split /\//, $0);      my @filename = ( split /\//, $0 );
         pop @filename;      pop @filename;
 }  }
   
   
 #######################################################################  #######################################################################
 # Bail: this subrouting dies and displays the error to the browser.  # 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_  # _Learning_Perl_on_Win32_Systems_
 sub bail {  sub bail {
         my $error = shift;      my $error = shift;
         print "\n\nUnexpected Error: <b>$error</b><br>\n";      print "\n\nUnexpected Error: <b>$error</b><br>\n";
         print "In " . __FILE__ . "\n";      print "In " . __FILE__ . "\n";
         die;      die;
         exit;      exit;
 }  }
 sub Print_Nav  
 {  sub Print_Nav {
         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;          s/%PREFIX%/$prefix/g;
                 print;          print;
         }      }
         close FILE;      close FILE;
 }  }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>