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

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

1.1       andrew      1: #!/usr/bin/perl -Tw
1.2     ! andrew      2: # $RedRiver$
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:
                     64: my $New_Vol = "$Cur_Vol_Left&$Cur_Vol_Right";
                     65: if ($ENV{'QUERY_STRING'}) {
                     66:        print "<meta HTTP-EQUIV=Refresh CONTENT=\"1; URL=mixer.pl\">";
                     67:        $New_Vol = $ENV{'QUERY_STRING'};
                     68: }
                     69:
                     70: print <<EOL;
                     71:
                     72: <style type="text/css" media="screen">
                     73: <!--
                     74: a.down:link { color: red; text-decoration: none; }
                     75: a.down:visited { color: red; text-decoration: none; }
                     76: a.down:hover { color: red; text-decoration: none; }
                     77: a.down:active { color: red; text-decoration: none; }
                     78: a.up:link { color: blue; text-decoration: none; }
                     79: a.up:visited { color: blue; text-decoration: none; }
                     80: a.up:hover { color: blue; text-decoration: none; }
                     81: a.up:active { color: blue; text-decoration: none; }
                     82: -->
                     83: </style>
                     84:
                     85: EOL
                     86:
                     87: print "<title>Volume Mixer</title></head>\n<body>\n\n";
                     88:
                     89: Print_Nav();
                     90:
                     91: print "Volume - ";
                     92:
                     93:
                     94: #»print "New_Vol $New_Vol<BR>\n";
                     95: $New_Vol =~ /(\d+)&(\d+)/;
                     96: my $New_Vol_Left = $1;
                     97: my $New_Vol_Right = $2;
                     98:
                     99: my @nav;
                    100: foreach my $vol (@Vols) {
                    101:        if ($$vol[0] == $New_Vol_Left) {
                    102:                push @nav, "<B><A HREF='$me?$$vol[0]&$$vol[1]' class=up>$$vol[0]</A></B>\n";
                    103:        } elsif ($$vol[0] < $New_Vol_Left) {
                    104:                push @nav, "<A HREF='$me?$$vol[0]&$$vol[1]' class=up>}</A>\n";
                    105:        } elsif ($$vol[0] > $New_Vol_Left) {
                    106:                push @nav, "<A HREF='$me?$$vol[0]&$$vol[1]' class=down>]</A>\n";
                    107:        }
                    108:        #print "$vol - $$vol[0] - $$vol[1]<br>\n";
                    109: }
                    110: print join " ", @nav;
                    111: #print "<br>\n";
                    112:
                    113: Set_Vol($Cur_Vol_Left, $Cur_Vol_Right, $New_Vol_Left, $New_Vol_Right);
                    114:
                    115: print "</body>\n</head>\n</html>\n";
                    116:
                    117:
                    118:
                    119: sub Set_Vol
                    120: {
                    121:        my $old_vol_right = shift;
                    122:        my $old_vol_left = shift;
                    123:        my $new_vol_left = shift;
                    124:        my $new_vol_right = shift;
                    125:
                    126:        my $old_vol;
                    127:        my $new_vol;
                    128:        if (($old_vol_left + $old_vol_right) > ($new_vol_left + $new_vol_right)) {
                    129:                $old_vol = $old_vol_left > $old_vol_right ? $old_vol_left : $old_vol_right;
                    130:                $new_vol = $new_vol_left < $new_vol_right ? $new_vol_left : $new_vol_right;
                    131:        } else {
                    132:                $old_vol = $old_vol_left < $old_vol_right ? $old_vol_left : $old_vol_right;
                    133:                $new_vol = $new_vol_left > $new_vol_right ? $new_vol_left : $new_vol_right;
                    134:        }
                    135:
                    136:        #»print "Old: $old_vol - New: $new_vol<br>\n";
                    137:
                    138:        my $Set_Vol;
                    139:
                    140:        foreach my $vol ($old_vol < $new_vol ? $old_vol..$new_vol : reverse $new_vol..$old_vol) {
                    141:                #»print "$vol<br>\n";
                    142:                $Set_Vol = `$mixerctl -w outputs.master=$vol,$vol`;
                    143:                #»print $Set_Vol . "<br>\n";
                    144:        }
                    145:        return $Set_Vol;
                    146: }
                    147:
                    148:
                    149:
                    150: ########################################################################
                    151: # *** EncodeURL: %encodes the parameters of the URL
                    152: sub EncodeURL {
                    153:        my $strURL = shift;
                    154:        $strURL =~ s/(\W)/sprintf("%%%x", ord($1))/eg;
                    155:        return $strURL;
                    156: }
                    157:
                    158: #########################################################################
                    159: # My name
                    160: sub MyName {
                    161:        my @filename = (split /\//, $0);
                    162:        pop @filename;
                    163: }
                    164:
                    165:
                    166: #######################################################################
                    167: # Bail: this subrouting dies and displays the error to the browser.
                    168: # gotten from the example in the O'Reilly
                    169: # _Learning_Perl_on_Win32_Systems_
                    170: sub bail {
                    171:        my $error = shift;
                    172:        print "\n\nUnexpected Error: <b>$error</b><br>\n";
                    173:        print "In " . __FILE__ . "\n";
                    174:        die;
                    175:        exit;
                    176: }
                    177: sub Print_Nav
                    178: {
                    179:        open FILE, 'nav.inc' or die "\n\ncouldn't open FILE nav.inc: $!";
                    180:        while (<FILE>) {
                    181:                print;
                    182:        }
                    183:        close FILE;
                    184: }

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