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

Annotation of mp3/bin/mixer.pl, Revision 1.3

1.1       andrew      1: #!/usr/bin/perl -Tw
1.3     ! andrew      2: # $RedRiver: mixer.pl,v 1.2 2006/08/12 00:14:53 andrew Exp $
1.1       andrew      3: ########################################################################
                      4: # Mixer.pl *** Changes volume on the MP3 player
                      5: #
                      6: # 10/11/2002 4:26PM
                      7: # Written by andrew fresh <andrew@mad-techies.org>
                      8: ########################################################################
                      9: use strict;
                     10: use diagnostics;
                     11:
                     12: my $mixerctl = '/usr/bin/mixerctl';
                     13:
                     14: my $me = MyName();
                     15:
                     16: delete $ENV{PATH} if exists $ENV{PATH};
                     17:
                     18:
                     19: my @Vols = (
                     20:             [  7,   7],
                     21:             [ 15,  15],
                     22:             [ 23,  23],
                     23:             [ 31,  31],
                     24:             [ 39,  39],
                     25:             [ 47,  47],
                     26:             [ 55,  55],
                     27:             [ 63,  63],
                     28:             [ 71,  71],
                     29:             [ 79,  79],
                     30:             [ 87,  87],
                     31:             [ 95,  95],
                     32:             [103, 103],
                     33:             [111, 111],
                     34:             [119, 119],
                     35:             [127, 127],
                     36:             [135, 135],
                     37:             [143, 143],
                     38:             [151, 151],
                     39:             [159, 159],
                     40:             [167, 167],
                     41:             [175, 175],
                     42:             [183, 183],
                     43:             [191, 191],
                     44:             [199, 199],
                     45:             [207, 207],
                     46:             [215, 215],
                     47:             [223, 223],
                     48:             [231, 231],
                     49:             [239, 239],
                     50:             [247, 247],
                     51:             [255, 255],
                     52:            );
                     53:
                     54:
                     55: my $Cur_Vol = `$mixerctl outputs.master`;
                     56: #»print "Cur_Vol $Cur_Vol<BR>\n";
                     57: $Cur_Vol =~ /outputs.master=(\d+),(\d+)/i;
                     58: my $Cur_Vol_Left = $1;
                     59: my $Cur_Vol_Right = $2;
                     60:
                     61: print "Content-Type: text/html\n\n";
                     62: print "<html>\n<head>\n\t<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'> ";
                     63:
1.3     ! andrew     64: my ($prefix, $New_Vol_Left, $New_Vol_Right) = split /\&/, $ENV{'QUERY_STRING'};
        !            65: if ($New_Vol_Left || $New_Vol_Right) {
        !            66:         $New_Vol_Left  =~ s/%(..)/pack("c",hex($1))/ge;
        !            67:         $New_Vol_Right =~ s/%(..)/pack("c",hex($1))/ge;
        !            68:        print "<meta HTTP-EQUIV=Refresh CONTENT=\"1; URL=mixer.pl?" . EncodeURL($prefix) . "\">";
        !            69: }
        !            70:
        !            71: $New_Vol_Left  ||= $Cur_Vol_Left;
        !            72: $New_Vol_Right ||= $Cur_Vol_Right;
        !            73:
        !            74: if ($New_Vol_Left =~ /(\d+)/)  { $New_Vol_Left  = $1; }
        !            75: if ($New_Vol_Right =~ /(\d+)/) { $New_Vol_Right = $1; }
        !            76:
        !            77: if ($prefix) {
        !            78:         $prefix =~ s/%(..)/pack("c",hex($1))/ge;
        !            79: } else {
        !            80:         $prefix ='';
1.1       andrew     81: }
                     82:
                     83: print <<EOL;
                     84:
                     85: <style type="text/css" media="screen">
                     86: <!--
                     87: a.down:link { color: red; text-decoration: none; }
                     88: a.down:visited { color: red; text-decoration: none; }
                     89: a.down:hover { color: red; text-decoration: none; }
                     90: a.down:active { color: red; text-decoration: none; }
                     91: a.up:link { color: blue; text-decoration: none; }
                     92: a.up:visited { color: blue; text-decoration: none; }
                     93: a.up:hover { color: blue; text-decoration: none; }
                     94: a.up:active { color: blue; text-decoration: none; }
                     95: -->
                     96: </style>
                     97:
                     98: EOL
                     99:
                    100: print "<title>Volume Mixer</title></head>\n<body>\n\n";
                    101:
                    102: Print_Nav();
                    103:
1.3     ! andrew    104: unless ($prefix) {
1.1       andrew    105: print "Volume - ";
                    106:
1.3     ! andrew    107: #print "New_Vol $New_Vol_Left:$New_Vol_Right<BR>\n";
1.1       andrew    108:
                    109: my @nav;
                    110: foreach my $vol (@Vols) {
                    111:        if ($$vol[0] == $New_Vol_Left) {
1.3     ! andrew    112:                push @nav, "<B><A HREF='$me?" . EncodeURL($prefix) . '&' . "$$vol[0]&$$vol[1]' class=up>$$vol[0]</A></B>\n";
1.1       andrew    113:        } elsif ($$vol[0] < $New_Vol_Left) {
1.3     ! andrew    114:                push @nav, "<A HREF='$me?" . EncodeURL($prefix) . '&' . "$$vol[0]&$$vol[1]' class=up>}</A>\n";
1.1       andrew    115:        } elsif ($$vol[0] > $New_Vol_Left) {
1.3     ! andrew    116:                push @nav, "<A HREF='$me?" . EncodeURL($prefix) . '&' . "$$vol[0]&$$vol[1]' class=down>]</A>\n";
1.1       andrew    117:        }
                    118:        #print "$vol - $$vol[0] - $$vol[1]<br>\n";
                    119: }
                    120: print join " ", @nav;
                    121: #print "<br>\n";
                    122:
                    123: Set_Vol($Cur_Vol_Left, $Cur_Vol_Right, $New_Vol_Left, $New_Vol_Right);
1.3     ! andrew    124: }
1.1       andrew    125:
                    126: print "</body>\n</head>\n</html>\n";
                    127:
                    128:
                    129:
                    130: sub Set_Vol
                    131: {
                    132:        my $old_vol_right = shift;
                    133:        my $old_vol_left = shift;
                    134:        my $new_vol_left = shift;
                    135:        my $new_vol_right = shift;
                    136:
                    137:        my $old_vol;
                    138:        my $new_vol;
                    139:        if (($old_vol_left + $old_vol_right) > ($new_vol_left + $new_vol_right)) {
                    140:                $old_vol = $old_vol_left > $old_vol_right ? $old_vol_left : $old_vol_right;
                    141:                $new_vol = $new_vol_left < $new_vol_right ? $new_vol_left : $new_vol_right;
                    142:        } else {
                    143:                $old_vol = $old_vol_left < $old_vol_right ? $old_vol_left : $old_vol_right;
                    144:                $new_vol = $new_vol_left > $new_vol_right ? $new_vol_left : $new_vol_right;
                    145:        }
                    146:
1.3     ! andrew    147:        #print "Old: $old_vol - New: $new_vol<br>\n";
1.1       andrew    148:
                    149:        my $Set_Vol;
                    150:
                    151:        foreach my $vol ($old_vol < $new_vol ? $old_vol..$new_vol : reverse $new_vol..$old_vol) {
1.3     ! andrew    152:                #print "$vol<br>\n";
1.1       andrew    153:                $Set_Vol = `$mixerctl -w outputs.master=$vol,$vol`;
1.3     ! andrew    154:                #print $Set_Vol . "<br>\n";
1.1       andrew    155:        }
                    156:        return $Set_Vol;
                    157: }
                    158:
                    159:
                    160:
                    161: ########################################################################
                    162: # *** EncodeURL: %encodes the parameters of the URL
                    163: sub EncodeURL {
                    164:        my $strURL = shift;
                    165:        $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg;
                    166:        return $strURL;
                    167: }
                    168:
                    169: #########################################################################
                    170: # My name
                    171: sub MyName {
                    172:        my @filename = (split /\//, $0);
                    173:        pop @filename;
                    174: }
                    175:
                    176:
                    177: #######################################################################
                    178: # Bail: this subrouting dies and displays the error to the browser.
                    179: # gotten from the example in the O'Reilly
                    180: # _Learning_Perl_on_Win32_Systems_
                    181: sub bail {
                    182:        my $error = shift;
                    183:        print "\n\nUnexpected Error: <b>$error</b><br>\n";
                    184:        print "In " . __FILE__ . "\n";
                    185:        die;
                    186:        exit;
                    187: }
                    188: sub Print_Nav
                    189: {
                    190:        open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!";
                    191:        while (<FILE>) {
1.3     ! andrew    192:                s/%PREFIX%/$prefix/g;
1.1       andrew    193:                print;
                    194:        }
                    195:        close FILE;
                    196: }

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