Преглед на файлове

Unload in the AUDIO layer rather than QT. Wait for both loads and unloads to register.

Zachary Kotlarek преди 13 години
родител
ревизия
2c08230cf8
променени са 2 файла, в които са добавени 30 реда и са изтрити 10 реда
  1. 27 8
      dmx/Audio.pm
  2. 3 2
      dmx/qt_player.pl

+ 27 - 8
dmx/Audio.pm

@@ -71,12 +71,26 @@ sub runApplescript($) {
 	return $retval;
 }
 
+# Is the named document loaded?
+sub loaded($) {
+	my ($name) = @_;
+	parseList();
+	return exists($FILES{$name});
+}
+
 # Load a document
 sub load($$) {
 	my ($name, $path) = @_;
+
+	# Unload as needed
+	if (loaded($name)) {
+		unload($name);
+	}
+
+	# Request load
 	sendCmd('LOAD', $name, $path);
 
-	# Wait for the file to load
+	# Wait for the load to register
 	my $count = 0;
 	while (!loaded($name)) {
 		Time::HiRes::sleep($WAIT_DELAY);
@@ -87,20 +101,25 @@ sub load($$) {
 	}
 }
 
-# Is the named document loaded?
-sub loaded($) {
-	my ($name) = @_;
-	parseList();
-	return exists($FILES{$name});
-}
-
 # Unload the named document
 sub unload($) {
 	my ($name) = @_;
 	if ($DEBUG) {
 		print STDERR 'Audio::loadAudio(): ' . $name . "\n";
 	}
+
+	# Request unload
 	sendCmd('UNLOAD', $name);
+
+	# Wait for the unload to register
+	my $count = 0;
+	while (loaded($name)) {
+		Time::HiRes::sleep($WAIT_DELAY);
+		$count++;
+		if ($count > $MAX_WAIT) {
+			die('Unable to close file: ' . $name . "\n");
+		}
+	}
 }
 
 # Play the named document, waiting for completion

+ 3 - 2
dmx/qt_player.pl

@@ -142,9 +142,10 @@ sub load($$) {
 		return;
 	}
 
-	# Reload as needed
+	# Ignore duplicate loads
 	if (exists($FILES{$name})) {
-		unload($name);
+		warn('Ignoring load request for existing file: ' . $name . "\n");
+		return;
 	}
 
 	# Find out how many files are already open