Browse Source

added ui element to change fft size and implemented it in run thread

Jonathan Higgins 5 months ago
parent
commit
9f6f5557b5
3 changed files with 67 additions and 1 deletions
  1. 46 0
      scenes/main/control.tscn
  2. 15 0
      scenes/main/scripts/control.gd
  3. 6 1
      scenes/main/scripts/run_thread.gd

+ 46 - 0
scenes/main/control.tscn

@@ -573,6 +573,51 @@ offset_right = 592.0
 offset_bottom = 100.0
 text = "Stop Running Thread"
 
+[node name="Label" type="Label" parent="."]
+layout_mode = 0
+offset_left = 348.0
+offset_top = 48.0
+offset_right = 420.0
+offset_bottom = 67.0
+text = "FFT Size:"
+
+[node name="FFTSize" type="OptionButton" parent="."]
+layout_mode = 0
+offset_left = 425.0
+offset_top = 45.0
+offset_right = 504.0
+offset_bottom = 72.0
+tooltip_text = "Adjusts the number of analysis points used by the frequency domain processes in this thread. More points give better frequency resolution but worse time resolution."
+item_count = 14
+popup/item_0/text = "2"
+popup/item_0/id = 0
+popup/item_1/text = "4"
+popup/item_1/id = 1
+popup/item_2/text = "8"
+popup/item_2/id = 2
+popup/item_3/text = "16"
+popup/item_3/id = 3
+popup/item_4/text = "32"
+popup/item_4/id = 4
+popup/item_5/text = "64"
+popup/item_5/id = 5
+popup/item_6/text = "128"
+popup/item_6/id = 6
+popup/item_7/text = "256"
+popup/item_7/id = 7
+popup/item_8/text = "512"
+popup/item_8/id = 8
+popup/item_9/text = "1024"
+popup/item_9/id = 9
+popup/item_10/text = "2048"
+popup/item_10/id = 10
+popup/item_11/text = "4096"
+popup/item_11/id = 11
+popup/item_12/text = "8192"
+popup/item_12/id = 12
+popup/item_13/text = "16380"
+popup/item_13/id = 13
+
 [connection signal="connection_request" from="GraphEdit" to="GraphEdit" method="_on_connection_request"]
 [connection signal="copy_nodes_request" from="GraphEdit" to="GraphEdit" method="_on_copy_nodes_request"]
 [connection signal="delete_nodes_request" from="GraphEdit" to="GraphEdit" method="_on_graph_edit_delete_nodes_request"]
@@ -616,3 +661,4 @@ text = "Stop Running Thread"
 [connection signal="close_requested" from="CheckForUpdates/UpdatePopup" to="CheckForUpdates" method="_on_update_popup_close_requested"]
 [connection signal="button_down" from="CheckForUpdates/UpdatePopup/OpenAudioSettings" to="CheckForUpdates" method="_on_open_audio_settings_button_down"]
 [connection signal="button_down" from="ProgressWindow/KillProcess2" to="." method="_on_kill_process_button_down"]
+[connection signal="item_selected" from="FFTSize" to="." method="_on_fft_size_item_selected"]

+ 15 - 0
scenes/main/scripts/control.gd

@@ -53,6 +53,8 @@ func _ready() -> void:
 	$LoadDialog.file_mode = FileDialog.FILE_MODE_OPEN_FILE
 	$LoadDialog.filters = ["*.thd"]
 	
+	
+	
 	get_tree().set_auto_accept_quit(false) #disable closing the app with the x and instead handle it internally
 	
 	
@@ -170,6 +172,10 @@ func new_patch():
 	get_window().title = "SoundThread"
 	link_output()
 	
+	#set fft size to default
+	$FFTSize.select(9)
+	_on_fft_size_item_selected(9)
+	
 	
 func link_output():
 	#links various buttons and function in the input nodes - this is called after they are created so that it still works on new and loading files
@@ -856,3 +862,12 @@ func on_files_dropped(files):
 				new_input_node.position_offset = position_plus_offset
 				new_input_node.get_node("AudioPlayer")._on_file_selected(file)
 				position_plus_offset.y = position_plus_offset.y + 250
+
+
+func _on_fft_size_item_selected(index: int) -> void:
+	var fft_size
+	if index == 13:
+		fft_size = 16380
+	else:
+		fft_size = 1 << (index + 1)
+	run_thread.fft_size = fft_size

+ 6 - 1
scenes/main/scripts/run_thread.gd

@@ -12,6 +12,7 @@ var process_info = {} #tracks the data of the currently running process
 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 final_output_dir
+var fft_size = 1024 #tracks the fft size for the thread set in the main window
 
 # Called when the node enters the scene tree for the first time.
 func _ready() -> void:
@@ -982,6 +983,9 @@ func match_pvoc_channels(dict: Dictionary) -> void:
 			
 func _get_slider_values_ordered(node: Node) -> Array:
 	var results := []
+	if node.has_meta("command") and node.get_meta("command") == "pvoc_anal_1":
+		results.append(["slider", "-c", fft_size, false, [], 2, 32768, false])
+		return results
 	for child in node.get_children():
 		if child is Range:
 			var flag = child.get_meta("flag") if child.has_meta("flag") else ""
@@ -1058,6 +1062,7 @@ func make_process(node: Node, process_count: int, current_infile: Array, slider_
 		command = "%s/%s" %[control_script.cdpprogs_location, "morph"]
 		args = ["glide", window1_outfile, window2_outfile, output_file, duration]
 	else:
+		# Normal node process as usual 
 		# Get the command name from metadata
 		var command_name = str(node.get_meta("command"))
 		if command_name.find("_") != -1:
@@ -1072,7 +1077,7 @@ func make_process(node: Node, process_count: int, current_infile: Array, slider_
 			for file in current_infile:
 				args.append(file)
 		args.append(output_file)
-
+		
 		
 
 		# Append parameter values from the sliders, include flags if present