Преглед изворни кода

Set the volume when starting/stopping -- riffs should be louder than normal system sounds

Zachary Kotlarek пре 13 година
родитељ
комит
32c568e3b5
2 измењених фајлова са 35 додато и 4 уклоњено
  1. 10 2
      dmx/Audio.pm
  2. 25 2
      dmx/rifftrax.pl

+ 10 - 2
dmx/Audio.pm

@@ -35,6 +35,14 @@ sub runApplescript($) {
 	return $retval;
 }
 
+sub setVolume($) {
+	my ($vol) = @_;
+	if ($DEBUG) {
+		print STDERR 'Audio::setVolume(): ' . $vol . "\n";
+	}
+	runApplescript('set volume output volume ' . $vol);
+}
+
 sub addLoad($$) {
 	my ($name, $path) = @_;
 	if ($DEBUG) {
@@ -170,7 +178,7 @@ sub position($$) {
 	# Set or get the audio position
 	if ($new) {
 		runApplescript('tell application "QuickTime Player" to set current time of document ' . $FILES{$name}->{'name'} . ' to ' . $new);
-	} else {		
+	} else {
 		return runApplescript('tell application "QuickTime Player" to get current time of document ' . $FILES{$name}->{'name'});
 	}
 }
@@ -188,7 +196,7 @@ sub rate($$) {
 	if ($new) {
 		runApplescript('tell application "QuickTime Player" to set rate of document ' . $FILES{$name}->{'name'} . ' to ' . $new);
 	} else {
-		return runApplescript('tell application "QuickTime Player" to get rate of document ' . $FILES{$name}->{'name'});		
+		return runApplescript('tell application "QuickTime Player" to get rate of document ' . $FILES{$name}->{'name'});
 	}
 }
 

+ 25 - 2
dmx/rifftrax.pl

@@ -18,6 +18,8 @@ my $CONFIG_PATH    = $MEDIA_PATH . '/DMX/RiffTrax';
 my $RIFF_PATH      = $MEDIA_PATH . '/iTunes/iTunes Music/RiffTrax';
 my $ACTION_DELAY   = 0.1;
 my $JUMP_THRESHOLD = 5;
+my $VOLUME_RIFF    = 65;
+my $VOLUME_STD     = 40;
 
 # Prototypes
 sub playRiff();
@@ -112,10 +114,21 @@ while (1) {
 			if ($DEBUG) {
 				print STDERR "RIFF complete\n";
 			}
+
+			# Increase the delay while nothing is happening
 			$delay = $DELAY;
+
+			# Reset the volume when we unload -- normal system sounds should be quieter than riffs
+			Audio::setVolume($VOLUME_STD);
+
+			# Close the audio file
 			Audio::drop('RIFF');
+
+			# Cleanup
 			$riff  = 0;
 			$nudge = 0;
+
+			# Warm fuzzies
 			DMX::say('RiffTrax complete');
 		}
 
@@ -124,11 +137,21 @@ while (1) {
 			if ($DEBUG) {
 				print STDERR 'Matched RIFF: ' . $title . ' => ' . $RIFFS{$title}->{'file'} . "\n";
 			}
-			$riff  = $title;
+			$riff = $title;
+
+			# Warm fuzzies
+			DMX::say('RiffTrax initiated');
+
+			# Reduce the delay while playing so we sync faster
 			$delay = 1;
+
+			# Set volume when we load -- riffs should be louder than normal system sounds
+			Audio::setVolume($VOLUME_RIFF);
+
+			# Load and start the audio file
 			Audio::addLoad('RIFF', $RIFFS{$riff}->{'path'});
+			playRiff();
 			setRiffRate($RIFFS{$riff}->{'rate'});
-			DMX::say('RiffTrax initiated');
 		}
 	}