Browse Source

moved recycle output to input file and got rid of unused global variables

Jonathan Higgins 6 months ago
parent
commit
fffd426814

+ 2 - 6
Global/Global.gd

@@ -1,8 +1,4 @@
 extends Node
 extends Node
 
 
-var infile = "no_file"
-var infile_stereo = false
-var outfile = "no_file"
-var trim_infile = false
-var infile_start = 0
-var infile_stop = 1
+var outfile = "no_file" #bad name for the output directory
+var cdpoutput = "no_file" #output from running thread used for recycling output files

+ 9 - 19
scenes/Nodes/audioplayer.gd

@@ -21,12 +21,11 @@ func _ready():
 	file_dialog.connect("file_selected", Callable(self, "_on_file_selected"))
 	file_dialog.connect("file_selected", Callable(self, "_on_file_selected"))
 	audio_player.connect("finished", Callable(self, "_on_audio_finished"))
 	audio_player.connect("finished", Callable(self, "_on_audio_finished"))
 	
 	
-	if get_meta("loadenable") == true:
-		$RecycleButton.hide()
-		$LoadButton.show()
-	else:
+	if get_meta("loadenable") == false:
+		$PlayButton.position.x = $LoadButton.position.x
+		$PlayButton.size.x = $Panel.size.x
 		$LoadButton.hide()
 		$LoadButton.hide()
-		$RecycleButton.show()
+		$RecycleButton.hide()
 	
 	
 	$WavError.hide()
 	$WavError.hide()
 	
 	
@@ -59,10 +58,6 @@ func _on_load_button_button_down() -> void:
 
 
 func _on_file_selected(path: String):
 func _on_file_selected(path: String):
 	audio_player.stream = AudioStreamWAV.load_from_file(path)
 	audio_player.stream = AudioStreamWAV.load_from_file(path)
-	Global.infile_stereo = audio_player.stream.stereo
-	#if audio_player.stream.stereo == true:
-		##audio_player.stream = null
-		##$WavError.show()
 	voice_preview_generator.generate_preview(audio_player.stream)
 	voice_preview_generator.generate_preview(audio_player.stream)
 	set_meta("inputfile", path)
 	set_meta("inputfile", path)
 	reset_playback()
 	reset_playback()
@@ -88,16 +83,11 @@ func play_outfile(path: String):
 	reset_playback()
 	reset_playback()
 
 
 	
 	
-func recycle_outfile(path: String):
-	audio_player.stream = AudioStreamWAV.load_from_file(path)
-	Global.infile_stereo = audio_player.stream.stereo
-	#if audio_player.stream.stereo == true:
-		##audio_player.stream = null
-		##$WavError.show()
-	voice_preview_generator.generate_preview(audio_player.stream)
-	Global.infile = path
-	print("Infile set: " + Global.infile)
-	reset_playback()
+func recycle_outfile():
+	print("recycle pressed")
+	print(Global.cdpoutput)
+	if Global.cdpoutput != "no_file":
+		_on_file_selected(Global.cdpoutput)
 
 
 
 
 func _on_play_button_button_down() -> void:
 func _on_play_button_button_down() -> void:

+ 7 - 6
scenes/Nodes/audioplayer.tscn

@@ -36,24 +36,25 @@ use_native_dialog = true
 [node name="LoadButton" type="Button" parent="."]
 [node name="LoadButton" type="Button" parent="."]
 layout_mode = 0
 layout_mode = 0
 offset_top = 104.0
 offset_top = 104.0
-offset_right = 196.0
+offset_right = 128.0
 offset_bottom = 147.0
 offset_bottom = 147.0
 text = "Load File"
 text = "Load File"
 
 
 [node name="RecycleButton" type="Button" parent="." groups=["outputnode"]]
 [node name="RecycleButton" type="Button" parent="." groups=["outputnode"]]
 layout_mode = 0
 layout_mode = 0
+offset_left = 272.0
 offset_top = 104.0
 offset_top = 104.0
-offset_right = 196.0
+offset_right = 400.0
 offset_bottom = 147.0
 offset_bottom = 147.0
 tooltip_text = "Copies your output file back to your input for further processing."
 tooltip_text = "Copies your output file back to your input for further processing."
-text = "Recycle File"
+text = "Reuse Output"
 metadata/outputfunction = "recycle"
 metadata/outputfunction = "recycle"
 
 
 [node name="PlayButton" type="Button" parent="."]
 [node name="PlayButton" type="Button" parent="."]
 layout_mode = 0
 layout_mode = 0
-offset_left = 204.0
+offset_left = 136.0
 offset_top = 104.0
 offset_top = 104.0
-offset_right = 400.0
+offset_right = 264.0
 offset_bottom = 147.0
 offset_bottom = 147.0
 text = "Play"
 text = "Play"
 
 
@@ -112,7 +113,7 @@ flat = true
 [node name="Timer" type="Timer" parent="."]
 [node name="Timer" type="Timer" parent="."]
 
 
 [connection signal="button_down" from="LoadButton" to="." method="_on_load_button_button_down"]
 [connection signal="button_down" from="LoadButton" to="." method="_on_load_button_button_down"]
-[connection signal="button_down" from="RecycleButton" to="." method="_on_recycle_button_button_down"]
+[connection signal="button_down" from="RecycleButton" to="." method="recycle_outfile"]
 [connection signal="button_down" from="PlayButton" to="." method="_on_play_button_button_down"]
 [connection signal="button_down" from="PlayButton" to="." method="_on_play_button_button_down"]
 [connection signal="button_down" from="WavError/CloseButton" to="." method="_on_close_button_button_down"]
 [connection signal="button_down" from="WavError/CloseButton" to="." method="_on_close_button_button_down"]
 [connection signal="button_down" from="Button" to="." method="_on_button_button_down"]
 [connection signal="button_down" from="Button" to="." method="_on_button_button_down"]

+ 9 - 12
scenes/main/scripts/control.gd

@@ -6,11 +6,9 @@ var effect_position = Vector2(40,40) #tracks mouse position for node placement o
 var cdpprogs_location #stores the cdp programs location from user prefs for easy access
 var cdpprogs_location #stores the cdp programs location from user prefs for easy access
 var delete_intermediate_outputs # tracks state of delete intermediate outputs toggle
 var delete_intermediate_outputs # tracks state of delete intermediate outputs toggle
 @onready var console_output: RichTextLabel = $Console/ConsoleOutput
 @onready var console_output: RichTextLabel = $Console/ConsoleOutput
-var final_output_dir
 var undo_redo := UndoRedo.new() 
 var undo_redo := UndoRedo.new() 
 var output_audio_player #tracks the node that is the current output player for linking
 var output_audio_player #tracks the node that is the current output player for linking
 var input_audio_player #tracks node that is the current input player for linking
 var input_audio_player #tracks node that is the current input player for linking
-var outfile = "no file" #tracks dir of output file from cdp process
 var currentfile = "none" #tracks dir of currently loaded file for saving
 var currentfile = "none" #tracks dir of currently loaded file for saving
 var changesmade = false #tracks if user has made changes to the currently loaded save file
 var changesmade = false #tracks if user has made changes to the currently loaded save file
 var savestate # tracks what the user is trying to do when savechangespopup is called
 var savestate # tracks what the user is trying to do when savechangespopup is called
@@ -124,7 +122,6 @@ func new_patch():
 	graph_edit._register_node_movement() #link nodes for tracking position changes for changes tracking
 	graph_edit._register_node_movement() #link nodes for tracking position changes for changes tracking
 	
 	
 	changesmade = false #so it stops trying to save unchanged empty files
 	changesmade = false #so it stops trying to save unchanged empty files
-	Global.infile = "no_file" #resets input to stop processes running with old files
 	get_window().title = "SoundThread"
 	get_window().title = "SoundThread"
 	link_output()
 	link_output()
 	
 	
@@ -137,8 +134,8 @@ func link_output():
 			control.button_pressed = true
 			control.button_pressed = true
 		elif control.get_meta("outputfunction") == "runprocess": #link runprocess button
 		elif control.get_meta("outputfunction") == "runprocess": #link runprocess button
 			control.button_down.connect(_run_process)
 			control.button_down.connect(_run_process)
-		elif control.get_meta("outputfunction") == "recycle": #link recycle button
-			control.button_down.connect(_recycle_outfile)
+		#elif control.get_meta("outputfunction") == "recycle": #link recycle button
+			#control.button_down.connect(_recycle_outfile)
 		elif control.get_meta("outputfunction") == "audioplayer": #link output audio player
 		elif control.get_meta("outputfunction") == "audioplayer": #link output audio player
 			output_audio_player = control
 			output_audio_player = control
 		elif control.get_meta("outputfunction") == "filename":
 		elif control.get_meta("outputfunction") == "filename":
@@ -150,10 +147,10 @@ func link_output():
 		elif control.get_meta("outputfunction") == "openfolder":
 		elif control.get_meta("outputfunction") == "openfolder":
 			control.button_down.connect(_open_output_folder)
 			control.button_down.connect(_open_output_folder)
 
 
-	for control in get_tree().get_nodes_in_group("inputnode"):
-		if control.get_meta("inputfunction") == "audioplayer": #link input for recycle function
-			print("input player found")
-			input_audio_player = control
+	#for control in get_tree().get_nodes_in_group("inputnode"):
+		#if control.get_meta("inputfunction") == "audioplayer": #link input for recycle function
+			#print("input player found")
+			#input_audio_player = control
 
 
 func check_user_preferences():
 func check_user_preferences():
 	var interface_settings = ConfigHandler.load_interface_settings()
 	var interface_settings = ConfigHandler.load_interface_settings()
@@ -468,9 +465,9 @@ func _on_help_button_index_pressed(index: int) -> void:
 		12:
 		12:
 			OS.shell_open("https://github.com/j-p-higgins/SoundThread/issues")
 			OS.shell_open("https://github.com/j-p-higgins/SoundThread/issues")
 
 
-func _recycle_outfile():
-	if outfile != "no file":
-		input_audio_player.recycle_outfile(outfile)
+#func _recycle_outfile():
+	#if outfile != "no file":
+		#input_audio_player.recycle_outfile(outfile)
 
 
 
 
 
 

+ 16 - 11
scenes/main/scripts/run_thread.gd

@@ -11,6 +11,7 @@ var process_successful #tracks if the last run process was successful
 var process_info = {} #tracks the data of the currently running process
 var process_info = {} #tracks the data of the currently running process
 var process_running := false #tracks if a process is currently running
 var process_running := false #tracks if a process is currently running
 var process_cancelled = false #checks if the currently running process has been cancelled
 var process_cancelled = false #checks if the currently running process has been cancelled
+var final_output_dir
 
 
 # Called when the node enters the scene tree for the first time.
 # Called when the node enters the scene tree for the first time.
 func _ready() -> void:
 func _ready() -> void:
@@ -67,6 +68,7 @@ func run_thread_with_branches():
 		await get_tree().process_frame  # Let UI update
 		await get_tree().process_frame  # Let UI update
 		
 		
 	# Step 1: Gather nodes from the GraphEdit
 	# Step 1: Gather nodes from the GraphEdit
+	var trimcount = 0 # used for tracking the number of trims on input files for progress bar
 	for child in graph_edit.get_children():
 	for child in graph_edit.get_children():
 		if child is GraphNode:
 		if child is GraphNode:
 			var includenode = true
 			var includenode = true
@@ -110,12 +112,12 @@ func run_thread_with_branches():
 				graph[name] = []
 				graph[name] = []
 				reverse_graph[name] = []
 				reverse_graph[name] = []
 				indegree[name] = 0  # Start with zero incoming edges
 				indegree[name] = 0  # Start with zero incoming edges
+				if child.get_meta("command") == "inputfile" and child.get_node("AudioPlayer").get_meta("trimfile"):
+					trimcount += 1
 	#do calculations for progress bar
 	#do calculations for progress bar
 	var progress_step
 	var progress_step
-	if Global.trim_infile == true:
-		progress_step = 100 / (graph.size() + 4)
-	else:
-		progress_step = 100 / (graph.size() + 3)
+	progress_step = 100 / (graph.size() + 3 + trimcount)
+
 	
 	
 
 
 	# Step 2: Build graph relationships from connections
 	# Step 2: Build graph relationships from connections
@@ -458,7 +460,7 @@ func run_thread_with_branches():
 	# If multiple outputs go to the outputfile node, merge them
 	# If multiple outputs go to the outputfile node, merge them
 	if final_outputs.size() > 1:
 	if final_outputs.size() > 1:
 		var runmerge = await merge_many_files(process_count, final_outputs)
 		var runmerge = await merge_many_files(process_count, final_outputs)
-		control_script.final_output_dir = runmerge[0]
+		final_output_dir = runmerge[0]
 		var converted_files = runmerge[1]
 		var converted_files = runmerge[1]
 		
 		
 		if control_script.delete_intermediate_outputs:
 		if control_script.delete_intermediate_outputs:
@@ -469,7 +471,7 @@ func run_thread_with_branches():
 	# Only one output, no merge needed
 	# Only one output, no merge needed
 	elif final_outputs.size() == 1:
 	elif final_outputs.size() == 1:
 		var single_output = final_outputs[0]
 		var single_output = final_outputs[0]
-		control_script.final_output_dir = single_output
+		final_output_dir = single_output
 		intermediate_files.erase(single_output)
 		intermediate_files.erase(single_output)
 	progress_bar.value += progress_step
 	progress_bar.value += progress_step
 	# CLEANUP: Delete intermediate files after processing and rename final output
 	# CLEANUP: Delete intermediate files after processing and rename final output
@@ -497,16 +499,16 @@ func run_thread_with_branches():
 		await get_tree().process_frame
 		await get_tree().process_frame
 		
 		
 	var final_filename = "%s.wav" % Global.outfile
 	var final_filename = "%s.wav" % Global.outfile
-	var final_output_dir_fixed_path = control_script.final_output_dir
+	var final_output_dir_fixed_path = final_output_dir
 	if is_windows:
 	if is_windows:
 		final_output_dir_fixed_path = final_output_dir_fixed_path.replace("/", "\\")
 		final_output_dir_fixed_path = final_output_dir_fixed_path.replace("/", "\\")
 		await run_command(rename_cmd, [final_output_dir_fixed_path, final_filename.get_file()])
 		await run_command(rename_cmd, [final_output_dir_fixed_path, final_filename.get_file()])
 	else:
 	else:
 		await run_command(rename_cmd, [final_output_dir_fixed_path, "%s.wav" % Global.outfile])
 		await run_command(rename_cmd, [final_output_dir_fixed_path, "%s.wav" % Global.outfile])
-	control_script.final_output_dir = Global.outfile + ".wav"
+	final_output_dir = Global.outfile + ".wav"
 	
 	
-	control_script.output_audio_player.play_outfile(control_script.final_output_dir)
-	control_script.outfile = control_script.final_output_dir
+	control_script.output_audio_player.play_outfile(final_output_dir)
+	Global.cdpoutput = final_output_dir
 	progress_bar.value = 100.0
 	progress_bar.value = 100.0
 	var interface_settings = ConfigHandler.load_interface_settings() #checks if close console is enabled and closes console on a success
 	var interface_settings = ConfigHandler.load_interface_settings() #checks if close console is enabled and closes console on a success
 	progress_window.hide()
 	progress_window.hide()
@@ -548,8 +550,9 @@ func merge_many_files(process_count: int, input_files: Array) -> Array:
 	
 	
 	#Check if all sample rates are the same
 	#Check if all sample rates are the same
 	if sample_rates.all(func(v): return v == sample_rates[0]):
 	if sample_rates.all(func(v): return v == sample_rates[0]):
-		print("sample rates are the same")
+		pass
 	else:
 	else:
+		log_console("Different sample rates found, upsampling files to match highest current sample rate before mixing.", true)
 		#if not find the highest sample rate
 		#if not find the highest sample rate
 		var highest_sample_rate = sample_rates.max()
 		var highest_sample_rate = sample_rates.max()
 		var index = 0
 		var index = 0
@@ -578,6 +581,7 @@ func merge_many_files(process_count: int, input_files: Array) -> Array:
 
 
 	# STEP 2: Convert mono to stereo if there is a mix
 	# STEP 2: Convert mono to stereo if there is a mix
 	if mono_files.size() > 0 and stereo_files.size() > 0:
 	if mono_files.size() > 0 and stereo_files.size() > 0:
+		log_console("Mix of mono and stereo files found, interleaving mono files to stereo before mixing.", true)
 		for mono_file in mono_files:
 		for mono_file in mono_files:
 			var stereo_file = "%s_stereo.wav" % mono_file.get_basename()
 			var stereo_file = "%s_stereo.wav" % mono_file.get_basename()
 			await run_command(control_script.cdpprogs_location + "/submix", ["interleave", mono_file, mono_file, stereo_file])
 			await run_command(control_script.cdpprogs_location + "/submix", ["interleave", mono_file, mono_file, stereo_file])
@@ -593,6 +597,7 @@ func merge_many_files(process_count: int, input_files: Array) -> Array:
 		inputs_to_merge = input_files.duplicate()
 		inputs_to_merge = input_files.duplicate()
 
 
 	# STEP 3: Merge all input files (converted or original)
 	# STEP 3: Merge all input files (converted or original)
+	log_console("Mixing files to combined input.", true)
 	var quoted_inputs := []
 	var quoted_inputs := []
 	for f in inputs_to_merge:
 	for f in inputs_to_merge:
 		quoted_inputs.append(f)
 		quoted_inputs.append(f)