|
@@ -15,15 +15,15 @@ use Audio;
|
|
|
# Config
|
|
# Config
|
|
|
my $RIFF_PATH = `~/bin/video/mediaPath` . '/iTunes/iTunes Music/RiffTrax';
|
|
my $RIFF_PATH = `~/bin/video/mediaPath` . '/iTunes/iTunes Music/RiffTrax';
|
|
|
my %RIFFS = (
|
|
my %RIFFS = (
|
|
|
- 'Harry Potter 1' => {
|
|
|
|
|
|
|
+ '82481' => {
|
|
|
'file' => 'Harry Potter/Harry Potter 1_ The Sorcerer\'s Stone.mp3',
|
|
'file' => 'Harry Potter/Harry Potter 1_ The Sorcerer\'s Stone.mp3',
|
|
|
- 'part' => '82481',
|
|
|
|
|
'offset' => 100,
|
|
'offset' => 100,
|
|
|
|
|
+ 'rate' => 1.0,
|
|
|
},
|
|
},
|
|
|
- 'Harry Potter 2' => {
|
|
|
|
|
|
|
+ '82469' => {
|
|
|
'file' => 'Harry Potter/Harry Potter 2_ The Chamber of Secrets.mp3',
|
|
'file' => 'Harry Potter/Harry Potter 2_ The Chamber of Secrets.mp3',
|
|
|
- 'part' => '82469',
|
|
|
|
|
'offset' => 100,
|
|
'offset' => 100,
|
|
|
|
|
+ 'rate' => 1.0,
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -34,9 +34,6 @@ my $STATE_SOCK = $OUTPUT_FILE . '.socket';
|
|
|
my $PULL_TIMEOUT = 60;
|
|
my $PULL_TIMEOUT = 60;
|
|
|
my $DELAY = $PULL_TIMEOUT / 2;
|
|
my $DELAY = $PULL_TIMEOUT / 2;
|
|
|
|
|
|
|
|
-# Prototypes
|
|
|
|
|
-sub runApplescript($);
|
|
|
|
|
-
|
|
|
|
|
# Debug
|
|
# Debug
|
|
|
my $DEBUG = 0;
|
|
my $DEBUG = 0;
|
|
|
if ($ENV{'DEBUG'}) {
|
|
if ($ENV{'DEBUG'}) {
|
|
@@ -48,39 +45,38 @@ DMX::stateSocket($STATE_SOCK);
|
|
|
DMX::stateSubscribe($STATE_SOCK);
|
|
DMX::stateSubscribe($STATE_SOCK);
|
|
|
|
|
|
|
|
# State
|
|
# State
|
|
|
-my $RIFF = undef();
|
|
|
|
|
|
|
+my $newState = 'OFF';
|
|
|
|
|
+my $riff = 0;
|
|
|
|
|
+my $riffLast = $riff;
|
|
|
|
|
+my $url = '';
|
|
|
|
|
+my $urlLast = $url;
|
|
|
my %exists = ();
|
|
my %exists = ();
|
|
|
my $pullLast = time();
|
|
my $pullLast = time();
|
|
|
|
|
|
|
|
-# Validate our riff files at launch
|
|
|
|
|
-foreach my $riff (keys(%RIFFS)) {
|
|
|
|
|
- if ($RIFFS{$riff}{'file'} =~ /^\//) {
|
|
|
|
|
- $RIFFS{$riff}{'path'} = $RIFFS{$riff}{'file'};
|
|
|
|
|
|
|
+# Validate the path for all our riff files at launch
|
|
|
|
|
+foreach my $id (keys(%RIFFS)) {
|
|
|
|
|
+
|
|
|
|
|
+ # Store the ID internally
|
|
|
|
|
+ $RIFFS{$id}{'id'} = $id;
|
|
|
|
|
+
|
|
|
|
|
+ # Construct an absolute path
|
|
|
|
|
+ if ($RIFFS{$id}{'file'} =~ /^\//) {
|
|
|
|
|
+ $RIFFS{$id}{'path'} = $RIFFS{$riff}{'file'};
|
|
|
} else {
|
|
} else {
|
|
|
- $RIFFS{$riff}{'path'} = $RIFF_PATH . '/' . $RIFFS{$riff}{'file'};
|
|
|
|
|
|
|
+ $RIFFS{$id}{'path'} = $RIFF_PATH . '/' . $RIFFS{$id}{'file'};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!-r $RIFFS{$riff}{'path'}) {
|
|
|
|
|
- die('Invalid riff file: ' . $riff . ' => ' . $RIFFS{$riff}{'path'} . "\n");
|
|
|
|
|
|
|
+ # Ensure the path is valid
|
|
|
|
|
+ if (!-r $RIFFS{$id}{'path'}) {
|
|
|
|
|
+ die('Invalid riff file: ' . $id . ' => ' . $RIFFS{$id}{'path'} . "\n");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# Loop forever
|
|
# Loop forever
|
|
|
while (1) {
|
|
while (1) {
|
|
|
|
|
|
|
|
- # If the color profile has changed, save the state to disk
|
|
|
|
|
- #if ($colorLast ne $color) {
|
|
|
|
|
- # if ($DEBUG) {
|
|
|
|
|
- # print STDERR 'New color profile: ' . $colorLast . ' => ' . $color . "\n";
|
|
|
|
|
- # }
|
|
|
|
|
- # my ($fh, $tmp) = tempfile($OUTPUT_FILE . '.XXXXXXXX', 'UNLINK' => 0);
|
|
|
|
|
- # print $fh $color . "\n";
|
|
|
|
|
- # close($fh);
|
|
|
|
|
- # rename($tmp, $OUTPUT_FILE);
|
|
|
|
|
- #}
|
|
|
|
|
-
|
|
|
|
|
- # State is calculated; use newState to gather data
|
|
|
|
|
- my $newState = $state;
|
|
|
|
|
|
|
+ # Save the last RIFF
|
|
|
|
|
+ $riffLast = $riff;
|
|
|
|
|
|
|
|
# Wait for state updates
|
|
# Wait for state updates
|
|
|
my $cmdState = DMX::readState($DELAY, \%exists, undef(), undef());
|
|
my $cmdState = DMX::readState($DELAY, \%exists, undef(), undef());
|
|
@@ -94,15 +90,53 @@ while (1) {
|
|
|
die('No update on state socket in past ' . $PULL_TIMEOUT . " seconds. Exiting...\n");
|
|
die('No update on state socket in past ' . $PULL_TIMEOUT . " seconds. Exiting...\n");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- # Launch riffs when the underlying media is active
|
|
|
|
|
- if (!$RIFF && $cmdState eq 'PLAY') {
|
|
|
|
|
- my %tmp = ();
|
|
|
|
|
- $tmp{'url'} = $exists{'PLAYING_URL'};
|
|
|
|
|
- $RIFF = \%tmp;
|
|
|
|
|
|
|
+ # Save the last URL, so we can find changes
|
|
|
|
|
+ # Do not delete the last URL if no new one is provided
|
|
|
|
|
+ if ($exists{'PLAYING_URL'}) {
|
|
|
|
|
+ $urlLast = $url;
|
|
|
|
|
+ $url = $exists{'PLAYING_URL'};
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ # Update our state when the PLAYING_URL changes
|
|
|
|
|
+ if ($url ne $urlLast) {
|
|
|
|
|
+
|
|
|
|
|
+ # If a RIFF was active, clear it
|
|
|
|
|
+ if ($riff) {
|
|
|
|
|
+ if ($DEBUG) {
|
|
|
|
|
+ print STDERR "RIFF cleared\n";
|
|
|
|
|
+ }
|
|
|
|
|
+ $riff = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ # Activate a new RIFF, if applicable
|
|
|
|
|
+ if ($url =~ /\/library\/parts\/(\d+)\//) {
|
|
|
|
|
+ if (exists($RIFFS{$1})) {
|
|
|
|
|
+ if ($DEBUG) {
|
|
|
|
|
+ print STDERR 'Matched RIFF: ' . $1 . ' => ' . $RIFFS{$riff}{'path'};
|
|
|
|
|
+ }
|
|
|
|
|
+ $riff = $1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- # Close riffs when the underlying media stops
|
|
|
|
|
- if ($RIFF && $exists{'PLAYING_URL'} ne $RIFF->{'url'}) {
|
|
|
|
|
- $RIFF = undef();
|
|
|
|
|
|
|
+ # If the RIFF has changed, save the state to disk
|
|
|
|
|
+ if ($riff ne $riffLast) {
|
|
|
|
|
+ my $new = '<none>';
|
|
|
|
|
+ if ($riff) {
|
|
|
|
|
+ $new = $RIFFS{$riff}{'id'};
|
|
|
|
|
+ }
|
|
|
|
|
+ my $old = $new;
|
|
|
|
|
+ if ($riffLast) {
|
|
|
|
|
+ $old = $RIFFS{$riffLast}{'id'};
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($DEBUG) {
|
|
|
|
|
+ print STDERR 'New RIFF: ' . $old . ' => ' . $new . "\n";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ my ($fh, $tmp) = tempfile($OUTPUT_FILE . '.XXXXXXXX', 'UNLINK' => 0);
|
|
|
|
|
+ print $fh $new . "\n";
|
|
|
|
|
+ close($fh);
|
|
|
|
|
+ rename($tmp, $OUTPUT_FILE);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|