Browse Source

updated breakpoint file logic to support processes with output durations and to scale values logarithmically when appropriate

Jonathan Higgins 6 months ago
parent
commit
a230486dc3

+ 1 - 1
dev_tools/helpers/sort_json.py

@@ -13,7 +13,7 @@ CATEGORY_ORDER = ["time", "pvoc", "utility"]
 
 # Define desired parameter field order
 FIELD_ORDER = [
-    "paramname", "paramdescription", "automatable", "time",
+    "paramname", "paramdescription", "automatable", "outputduration", "time",
     "min", "max", "flag", "minrange", "maxrange", "step",
     "value", "exponential", "uitype"
 ]

+ 5 - 0
scenes/Nodes/node_logic.gd

@@ -32,6 +32,7 @@ func _on_slider_value_changed(value: float, changed_slider: HSlider) -> void:
 	#checks if the slider moved has min or max meta data
 	var is_min = changed_slider.get_meta("min")
 	var is_max = changed_slider.get_meta("max")
+	var is_outputduration = changed_slider.get_meta("outputduration")
 	
 	#if not exits function
 	if not is_min and not is_max:
@@ -52,6 +53,10 @@ func _on_slider_value_changed(value: float, changed_slider: HSlider) -> void:
 			var min_value: float = other_slider.value
 			if changed_slider.value < min_value + min_gap:
 				changed_slider.value = min_value + min_gap
+				
+	#set output duration meta if this is the output duration slider
+	if is_outputduration:
+		set_meta("outputduration", value)
 
 func _open_help():
 	open_help.emit(self.get_meta("command"), self.title)

File diff suppressed because it is too large
+ 126 - 0
scenes/main/process_help.json


+ 5 - 0
scenes/main/scripts/graph_edit.gd

@@ -137,6 +137,7 @@ func _make_node(command: String, skip_undo_redo := false) -> GraphNode:
 						#get slider properties
 						var brk = param_data.get("automatable", false)
 						var time = param_data.get("time", false)
+						var outputduration = param_data.get("outputduration", false)
 						var min = param_data.get("min", false)
 						var max = param_data.get("max", false)
 						var flag = param_data.get("flag", "")
@@ -168,6 +169,10 @@ func _make_node(command: String, skip_undo_redo := false) -> GraphNode:
 						hslider.value = value
 						hslider.exp_edit = exponential
 						
+						#add output duration meta to main if true
+						if outputduration:
+							graphnode.set_meta("outputduration", value)
+						
 						graphnode.add_child(slider)
 			
 			

+ 61 - 28
scenes/main/scripts/run_thread.gd

@@ -539,17 +539,19 @@ func run_thread_with_branches():
 
 
 func is_stereo(file: String) -> bool:
-	var output = await run_command(control_script.cdpprogs_location + "/sfprops", ["-c", file])
-	output = int(output.strip_edges()) #convert output from cmd to clean int
-	if output == 1:
-		return false
-	elif output == 2:
-		return true
-	elif output == 1026: #ignore pvoc .ana files
-		return false
-	else:
-		log_console("[color=#9c2828]Error: Only mono and stereo files are supported[/color]", true)
-		return false
+	if file != "none":
+		var output = await run_command(control_script.cdpprogs_location + "/sfprops", ["-c", file])
+		output = int(output.strip_edges()) #convert output from cmd to clean int
+		if output == 1:
+			return false
+		elif output == 2:
+			return true
+		elif output == 1026: #ignore pvoc .ana files
+			return false
+		else:
+			log_console("[color=#9c2828]Error: Only mono and stereo files are supported[/color]", true)
+			return false
+	return true
 		
 func get_samplerate(file: String) -> int:
 	var output = await run_command(control_script.cdpprogs_location + "/sfprops", ["-r", file])
@@ -642,9 +644,10 @@ func _get_slider_values_ordered(node: Node) -> Array:
 			var brk_data = []
 			var min_slider = child.min_value
 			var max_slider = child.max_value
+			var exp = child.exp_edit
 			if child.has_meta("brk_data"):
 				brk_data = child.get_meta("brk_data")
-			results.append([flag, child.value, time, brk_data, min_slider, max_slider])
+			results.append([flag, child.value, time, brk_data, min_slider, max_slider, exp])
 		elif child.get_child_count() > 0:
 			var nested := _get_slider_values_ordered(child)
 			results.append_array(nested)
@@ -687,6 +690,7 @@ func make_process(node: Node, process_count: int, current_infile: String, slider
 		var brk_data = entry[3]
 		var min_slider = entry[4]
 		var max_slider = entry[5]
+		var exp = entry[6]
 		if brk_data.size() > 0: #if breakpoint data is present on slider
 			#Sort all points by time
 			var sorted_brk_data = []
@@ -696,24 +700,41 @@ func make_process(node: Node, process_count: int, current_infile: String, slider
 			var calculated_brk = []
 			
 			#get length of input file in seconds
-			var infile_length = await run_command(control_script.cdpprogs_location + "/sfprops", ["-d", current_infile])
-			infile_length = float(infile_length.strip_edges())
+			var infile_length = 1 #set infile length to dummy value just incase it does get used where it shouldn't to avoid crashes
+			if current_infile != "none":
+				infile_length = await run_command(control_script.cdpprogs_location + "/sfprops", ["-d", current_infile])
+				infile_length = float(infile_length.strip_edges())
 			
 			#scale values from automation window to the right length for file and correct slider values
-			#need to check how time is handled in all files that accept it, zigzag is x = outfile position, y = infile position
-			#if time == true:
-				#for point in sorted_brk_data:
-					#var new_x = infile_length * (point.x / 700) #time
-					#var new_y = infile_length * (remap(point.y, 255, 0, min_slider, max_slider) / 100) #slider value scaled as a percentage of infile time
-					#calculated_brk.append(Vector2(new_x, new_y))
-			#else:
-			for i in range(sorted_brk_data.size()):
-				var point = sorted_brk_data[i]
-				var new_x = infile_length * (point.x / 700) #time
-				if i == sorted_brk_data.size() - 1: #check if this is last automation point
-					new_x = infile_length + 0.1  # force last point's x to infile_length + 100ms to make sure the file is defo over
-				var new_y = remap(point.y, 255, 0, min_slider, max_slider) #slider value
-				calculated_brk.append(Vector2(new_x, new_y))
+			#if node has an output duration then breakpoint files should be x = outputduration y= slider value else x=input duration, y=value
+			if node.has_meta("outputduration"):
+				for i in range(sorted_brk_data.size()):
+					var point = sorted_brk_data[i]
+					var new_x = float(node.get_meta("outputduration")) * (point.x / 700) #output time
+					if i == sorted_brk_data.size() - 1: #check if this is last automation point
+						new_x = float(node.get_meta("outputduration")) + 0.1  # force last point's x to infile_length + 100ms to make sure the file is defo over
+					var new_y
+					#check if slider is exponential and scale automation
+					if exp:
+						new_y = remap_y_to_log_scale(point.y, 0.0, 255.0, min_slider, max_slider)
+					else:
+						new_y = remap(point.y, 255, 0, min_slider, max_slider) #slider value
+					if time: #check if this is a time slider and convert to percentage of input file
+						new_y = infile_length * (new_y / 100)
+					calculated_brk.append(Vector2(new_x, new_y))
+			else:
+				for i in range(sorted_brk_data.size()):
+					var point = sorted_brk_data[i]
+					var new_x = infile_length * (point.x / 700) #time
+					if i == sorted_brk_data.size() - 1: #check if this is last automation point
+						new_x = infile_length + 0.1  # force last point's x to infile_length + 100ms to make sure the file is defo over
+					var new_y
+					#check if slider is exponential and scale automation
+					if exp:
+						new_y = remap_y_to_log_scale(point.y, 0.0, 255.0, min_slider, max_slider)
+					else:
+						new_y = remap(point.y, 255, 0, min_slider, max_slider) #slider value
+					calculated_brk.append(Vector2(new_x, new_y))
 				
 			#make text file
 			var brk_file_path = output_file.get_basename() + "_" + str(slider_count) + ".txt"
@@ -721,6 +742,8 @@ func make_process(node: Node, process_count: int, current_infile: String, slider
 			
 			#append text file in place of value
 			#line += ("\"%s\" " % brk_file_path)
+			if flag.begins_with("-"):
+				brk_file_path = flag + brk_file_path
 			args.append(brk_file_path)
 			
 			cleanup.append(brk_file_path)
@@ -736,6 +759,16 @@ func make_process(node: Node, process_count: int, current_infile: String, slider
 	return [command, output_file, cleanup, args]
 	#return [line.strip_edges(), output_file, cleanup]
 
+func remap_y_to_log_scale(y: float, min_y: float, max_y: float, min_val: float, max_val: float) -> float:
+	var t = clamp((y - min_y) / (max_y - min_y), 0.0, 1.0)
+	# Since y goes top-down (0 = top, 255 = bottom), we invert t
+	t = 1.0 - t
+	var log_min = log(min_val) / log(10)
+	var log_max = log(max_val) / log(10)
+	var log_val = lerp(log_min, log_max, t)
+	return pow(10.0, log_val)
+
+
 func sort_points(a, b):
 	return a.x < b.x
 	

Some files were not shown because too many files changed in this diff