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