Browse Source

input files/paths containing special characters now create a copy of the file without special characters before processing, also fixed bug with bit-depth file type checks

Jonathan Higgins 2 months ago
parent
commit
b8745063ff
2 changed files with 58 additions and 44 deletions
  1. 27 9
      scenes/main/process_help.json
  2. 31 35
      scenes/main/scripts/run_thread.gd

+ 27 - 9
scenes/main/process_help.json

@@ -7615,14 +7615,14 @@
   },
   "outputfile": {
 	"category": "utility",
-	"description": "The name inputted in File Name will be appended with the current date and time so that you don't need to input a new file name each time.\n\nSoundThread can create a lot of files as each node in the thread can create multiple files. Turning on Delete Intermediate Files will delete everything but the main output file. \n\nClicking and dragging on the sound file viewer will let you select a section of audio to play. Clicking on the sound file viewer while audio is playing will allow you to jump around the file to listen to different sections.\n",
+	"description": "The name inputted in File Name will be appended with the current date and time so that you don't need to input a new file name each time. The output file name and path can only contain the following characters: A-Z a-z 0-9 - _ + and space.\n\nSoundThread can create a lot of files as each node in the thread can create multiple files. Turning on Delete Intermediate Files will delete everything but the main output file. \n\nClicking and dragging on the sound file viewer will let you select a section of audio to play. Clicking on the sound file viewer while audio is playing will allow you to jump around the file to listen to different sections.\n",
 	"inputtype": "[0]",
 	"outputisstereo": false,
 	"outputtype": "",
 	"parameters": {
 	  "param1": {
 		"paramname": "File Name",
-		"paramdescription": "The name for your output file",
+		"paramdescription": "The name for your output file, cannot contain special characters",
 		"automatable": false,
 		"outputduration": false,
 		"uitype": "lineedit",
@@ -7640,7 +7640,7 @@
 	  },
 	  "param3": {
 		"paramname": "Delete Intermediate Files",
-		"paramdescription": "If switched on, deletes all files except the final output file",
+		"paramdescription": "When toggled deletes all files except the final output file",
 		"automatable": false,
 		"outputduration": false,
 		"uitype": "toggle",
@@ -7648,17 +7648,17 @@
 		"fftwindowsize": false
 	  },
 	  "param4": {
-		"paramname": "Open Folder",
-		"paramdescription": "Opens the last used output folder",
+		"paramname": "Reuse Last Output Folder",
+		"paramdescription": "When toggled the last selected folder will be used to save files, persists between sessions",
 		"automatable": false,
 		"outputduration": false,
-		"uitype": "button",
+		"uitype": "toggle",
 		"fftwindowcount": false,
 		"fftwindowsize": false
 	  },
 	  "param5": {
-		"paramname": "Recycle File",
-		"paramdescription": "Loops the output file back to the Input File node for reprocessing",
+		"paramname": "Open Folder",
+		"paramdescription": "Where available opens the last used output folder",
 		"automatable": false,
 		"outputduration": false,
 		"uitype": "button",
@@ -7666,9 +7666,27 @@
 		"fftwindowsize": false
 	  },
 	  "param6": {
+		"paramname": "Autoplay",
+		"paramdescription": "When toggled will autoplay the output when the thread is done running",
+		"outputduration": false,
+		"uitype": "toggle",
+		"fftwindowcount": false,
+		"fftwindowsize": false
+	  },
+	  "param7": {
 		"paramname": "Play/Stop",
-		"paramdescription": "Plays the last output file",
+		"paramdescription": "Starts/Stops playback of the output file",
+		"automatable": false,
 		"outputduration": false,
+		"time": false,
+		"min": false,
+		"max": false,
+		"flag": "",
+		"minrange": "",
+		"maxrange": "",
+		"step": "",
+		"value": "",
+		"exponential": false,
 		"uitype": "button",
 		"fftwindowcount": false,
 		"fftwindowsize": false

+ 31 - 35
scenes/main/scripts/run_thread.gd

@@ -321,6 +321,33 @@ func run_thread_with_branches():
 					loadedfile = node.get_node("AudioPlayer").get_meta("upsampled_file")
 				else:
 					loadedfile = node.get_node("AudioPlayer").get_meta("inputfile")
+					
+				#check if input file has any invalid characters in path/name
+				var check_invalid_characters = Global.check_for_invalid_chars(loadedfile)
+				
+				if check_invalid_characters["contains_invalid_characters"] == true:
+					log_console("Special characters found in input file path/name, creating copy without special characters", true)
+					#get just the output folder by giving the outfile and extension and the running get base dir
+					var output_folder_location = Global.outfile + ".wav"
+					output_folder_location = output_folder_location.get_base_dir()
+					#make a unigue name for this file
+					var input_file_copy_name = Global.outfile.get_basename() + "_input_file_copy_" + str(process_count) + "." + loadedfile.get_extension()
+					if is_windows:
+						loadedfile = loadedfile.replace("/", "\\")
+						output_folder_location = output_folder_location.replace("/", "\\")
+						input_file_copy_name = input_file_copy_name.replace("/", "\\")
+						await run_command("copy", [loadedfile, output_folder_location])
+						await run_command(rename_cmd, [output_folder_location + "\\" + loadedfile.get_file(), input_file_copy_name.get_file()])
+					else:
+						await run_command("cp", [loadedfile, output_folder_location])
+						await run_command(rename_cmd, [output_folder_location + "/" + loadedfile.get_file(), input_file_copy_name])
+					
+					loadedfile = input_file_copy_name
+					
+					if control_script.delete_intermediate_outputs:
+						intermediate_files.append(input_file_copy_name)
+						
+					
 				#get wether trim has been enabled
 				var trimfile = node.get_node("AudioPlayer").get_meta("trimfile")
 				
@@ -900,7 +927,7 @@ func merge_many_files(inlet_id: int, process_count: int, input_files: Array) ->
 	await run_command(control_script.cdpprogs_location + "/submix", command)
 	
 	if process_successful == false:
-		log_console("Failed to to merge files to" + merge_output, true)
+		log_console("Failed to merge files to" + merge_output, true)
 	
 	return [merge_output, converted_files]
 	
@@ -951,7 +978,7 @@ func match_input_file_sample_rates_and_bit_depths(input_nodes: Array) -> Array:
 	input_files = [] #clear input files array for reuse with bitdepths
 	
 	#check if all file types and bit-depths are the same
-	if file_types.all(func(v): return v == sample_rates[0]) and bit_depths.all(func(v): return v == sample_rates[0]):
+	if file_types.all(func(v): return v == file_types[0]) and bit_depths.all(func(v): return v == bit_depths[0]):
 		highest_bit_depth = bit_depths[0]
 		int_float = file_types[0]
 		#convert this to the value cdp uses in copysfx for potential use with synthesis nodes later
@@ -1000,37 +1027,6 @@ func classify_format(file_type: int, bit_depth: int) -> int:
 		_:
 			return -1
 
-#need to remove this function as not needed
-#func match_file_sample_rates(inlet_id: int, process_count: int, input_files: Array) -> Array:
-	#var sample_rates := []
-	#var converted_files := []
-	#
-	##Get all sample rates
-	#for f in input_files:
-		#var samplerate = await get_samplerate(f)
-		#sample_rates.append(samplerate)
-	#
-	##Check if all sample rates are the same
-	#if sample_rates.all(func(v): return v == sample_rates[0]):
-		#pass
-	#else:
-		#log_console("Different sample rates found, upsampling files to match highest current sample rate before processing.", true)
-		##if not find the highest sample rate
-		#var highest_sample_rate = sample_rates.max()
-		#var index = 0
-		##move through all input files and compare match their index to the sample_rate array
-		#for f in input_files:
-			##check if sample rate of current file is less than the highest sample rate
-			#if sample_rates[index] < highest_sample_rate:
-				##up sample it to the highest sample rate if so
-				#var upsample_output = Global.outfile + "_" + str(inlet_id) + "_" + str(process_count) + f.get_file().get_slice(".wav", 0) + "_" + str(highest_sample_rate) + ".wav"
-				#await run_command(control_script.cdpprogs_location + "/housekeep", ["respec", "1", f, upsample_output, str(highest_sample_rate)])
-				##replace the file in the input_file index with the new upsampled file
-				#input_files[index] = upsample_output
-				#converted_files.append(upsample_output)
-				#
-			#index += 1
-	#return [input_files, converted_files]
 	
 func match_file_channels(inlet_id: int, process_count: int, input_files: Array) -> Array:
 	var converted_files := []
@@ -1466,7 +1462,7 @@ func run_command(command: String, args: Array) -> String:
 	console_output.scroll_to_line(console_output.get_line_count() - 1)
 	await get_tree().process_frame
 	
-	if is_windows and (command == "del" or command == "ren"): #checks if the command is a windows system command and runs it through cmd.exe
+	if is_windows and (command == "del" or command == "ren" or command =="copy"): #checks if the command is a windows system command and runs it through cmd.exe
 		args.insert(0, command)
 		args.insert(0, "/C")
 		process_info = OS.execute_with_pipe("cmd.exe", args, false)
@@ -1474,7 +1470,7 @@ func run_command(command: String, args: Array) -> String:
 		process_info = OS.execute_with_pipe(command, args, false)
 	# Check if the process was successfully started
 	if !process_info.has("pid"):
-		log_console("Failed to start process]", true)
+		log_console("Failed to start process", true)
 		return ""
 	
 	process_running = true