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