#Wakeup2 by Dale Swanson June 14, 2012 #Gradual volume ramp up script for Foobar2000. Used as my alarm. #Tested on Foobar2000 v1.1 #uses NirCmd to unmute and max system volume, if you don't have it installed you'll just have to do that manually #http://www.nirsoft.net/utils/nircmd.html #This second version is different in that you set the time you want it to take to generally wake you up below #!/usr/bin/perl use strict; use warnings; use Cwd; my $rate = 1.03; #change in wait between each step, 1.03 = 103% my $wakeupstep = 70; #step on which wakeup typically occurs (foobar's volume ranges 0-100) my $wakeuptime = 25; #time in minutes a wakeup should take (from 0 volume to step listed above). my $debug=0; #debug mode, set to 1 to get lots of output, and supress actual foobar messing withs my $foo = "C:\\Program Files\\foobar2000\\"; #file path of foobar2000 my $choice=0; #user's choice to stay in loop and correct time or exit my $pause; #time in seconds between volume up steps my $sleep; #time in seconds to sleep for my $endtime; #wakeup time my $time; #current time my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); my $x; my $wakeuptimesec; #conversion of the above wakeuptime from minutes to seconds my $tempwakeuptime; #a temp variable to clean up some math below while ($choice == 0) {#main loop, will run until user gives us a 0 or 1 for slow or fast wakeup, also gets time in hours to delay ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); #current time $time = sprintf("%4d-%02d-%02d %02d:%02d:%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec); print "\nIt is currently: $time"; print "\nEnter number of hours to wait "; $sleep = ; #time in hours to sleep, we will make it seconds later chomp($sleep); #newlines print "\nIn $sleep hours it will be "; $sleep *= 60*60; #convert from hours to seconds ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time+$sleep); #wakeup time $endtime = sprintf("%4d-%02d-%02d %02d:%02d:%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec); print "$endtime"; print "\nEnter 1 to accept or 0 to change time "; $choice = ; chomp($choice); #newlines } system("CLS"); print "Current - $time"; print "Wake up - $endtime"; $sleep -= (60*$wakeuptime); #deduct the wakeup time from sleep time print "\nGoing to sleep for ", $sleep/3600, " hours, followed by a $wakeuptime minute wakeup \n"; #go to sleep if ($sleep<1) {$sleep=0}; sleep ($sleep); #wakeup time if (!$debug) {#all the stuff that messes with foobar and volumes, skip in debug mode print "Wakeup!\n"; chdir "$foo"; #makes our working directory the one with foobar2000 system "foobar2000"; #starts foobar, in case it's not running sleep (10); #wait 10 seconds to give it a chance to actually start before issuing commands system "foobar2000 /stop"; #stop current music system "nircmd mutesysvolume 0"; #unmutes system volume, uses NirCmd system "nircmd setsysvolume 65535"; #maxes system volume, uses NirCmd for ($x=0;$x<110;$x++) {#lower foobar volume, should only need 100 steps, but do 110 for fun system "foobar2000 /command:\"Down\""; print "Step - $x\n"; } system "foobar2000 /play"; #start music, foobar volume is at 0 } $wakeuptimesec = $wakeuptime * 60; $tempwakeuptime = (1-($rate**$wakeupstep))/(1-$rate); #geometric series sum formula #we now know how long a wakeup will take with 1 sec starting interval, we will find the scaler needed for desired length $pause=($wakeuptimesec/$tempwakeuptime); #the begining pause length between steps (print "\nWUTS - $wakeuptimesec, TWUT - $tempwakeuptime \n") if ($debug); for ($x=1;$x<110;$x++) {#step up volume at our rate $pause *= $rate; #gradually increase pause between steps $pause = int($pause*1000)/1000; #round to 3 decimals places, just to keep the display nice (system "foobar2000 /command:\"Up\"") if (!$debug); print "\nStep - $x, Pause - $pause"; sleep($pause + 0.5); #sleep only takes the int, so we add 0.5 so it rounds rather than truncates to int }