Browse Source

updated audio player and added function to express time in file as a percentage

Jonathan Higgins 7 months ago
parent
commit
1795fccd7f
3 changed files with 46 additions and 160 deletions
  1. 17 5
      scenes/Nodes/audioplayer.gd
  2. 16 17
      scenes/Nodes/nodes.tscn
  3. 13 138
      scenes/main/control.gd

+ 17 - 5
scenes/Nodes/audioplayer.gd

@@ -136,7 +136,7 @@ func _process(delta: float) -> void:
 		if $Playhead.position.x >= 399:
 			$Playhead.position.x = 0
 	
-	if audio_player.playing == false and rect_focus == true:
+	if rect_focus == true:
 		if get_local_mouse_position().x > mouse_pos_x:
 			$LoopRegion.size.x = clamp(get_local_mouse_position().x - mouse_pos_x, 0, $Panel.size.x - (mouse_pos_x - $Panel.position.x))
 		else:
@@ -153,10 +153,21 @@ func _process(delta: float) -> void:
 	
 
 func _on_button_button_down() -> void:
-	print("focus entered")
-	mouse_pos_x = get_local_mouse_position().x
-	$LoopRegion.position.x = mouse_pos_x
-	rect_focus = true
+	if audio_player.playing: #if audio is playing allow user to skip around the sound file
+		$Timer.stop()
+		var length = $AudioStreamPlayer.stream.get_length()
+		var pixel_to_time = length / 399
+		$Playhead.position.x = get_local_mouse_position().x
+		if $LoopRegion.size.x == 0 or get_local_mouse_position().x > $LoopRegion.position.x + $LoopRegion.size.x: #loop position is not set or click is after loop position, play to end of file
+			audio_player.seek(pixel_to_time * get_local_mouse_position().x)
+		else: #if click position is before the loop position play from there and stop at the end of the loop position
+			audio_player.seek(pixel_to_time * get_local_mouse_position().x)
+			if $LoopRegion.position.x + $LoopRegion.size.x < 399:
+				$Timer.start(pixel_to_time * ($LoopRegion.position.x + $LoopRegion.size.x - get_local_mouse_position().x))
+	else:
+		mouse_pos_x = get_local_mouse_position().x
+		$LoopRegion.position.x = mouse_pos_x
+		rect_focus = true
 
 
 func _on_button_button_up() -> void:
@@ -175,3 +186,4 @@ func _on_button_button_up() -> void:
 		else:
 			Global.trim_infile = false
 			print(Global.trim_infile)
+	

+ 16 - 17
scenes/Nodes/nodes.tscn

@@ -847,9 +847,9 @@ tooltip_text = "Time in infile at which the drunken walk occurs"
 text = "Location"
 
 [node name="HSlider" parent="extend_drunk_1/VBoxContainer2/HSplitContainer" index="0"]
-max_value = 6.0
 step = 0.01
 value = 0.0
+metadata/time = true
 
 [node name="VBoxContainer3" parent="extend_drunk_1" instance=ExtResource("3_b6nw4")]
 layout_mode = 2
@@ -940,15 +940,15 @@ layout_mode = 2
 
 [node name="VBoxContainer" parent="extend_loop_1" instance=ExtResource("3_b6nw4")]
 layout_mode = 2
-tooltip_text = "Start time (in seconds) in file for looping to begin"
+tooltip_text = "Start time (in percent) in file for looping to begin"
 
 [node name="Label" parent="extend_loop_1/VBoxContainer" index="0"]
 text = "Start"
 
 [node name="HSlider" parent="extend_loop_1/VBoxContainer/HSplitContainer" index="0"]
-max_value = 30.0
 step = 0.01
 value = 0.0
+metadata/time = true
 
 [node name="VBoxContainer2" parent="extend_loop_1" instance=ExtResource("3_b6nw4")]
 layout_mode = 2
@@ -1027,30 +1027,29 @@ layout_mode = 2
 
 [node name="VBoxContainer" parent="extend_scramble_1" instance=ExtResource("3_b6nw4")]
 layout_mode = 2
-tooltip_text = "Minimum chunksize to cut"
+tooltip_text = "Minimum chunksize to cut (as a percentage of the file length)"
 
 [node name="Label" parent="extend_scramble_1/VBoxContainer" index="0"]
 text = "Minimum Chunk Length"
 
 [node name="HSlider" parent="extend_scramble_1/VBoxContainer/HSplitContainer" index="0"]
-min_value = 0.05
-max_value = 30.0
+min_value = 2.0
 step = 0.01
-value = 0.05
+value = 2.0
+metadata/time = true
 
 [node name="VBoxContainer2" parent="extend_scramble_1" instance=ExtResource("3_b6nw4")]
 layout_mode = 2
-tooltip_text = "Maximum chunksize to cut must be greater than minimum"
+tooltip_text = "Maximum chunksize to cut (as a percentage of the file length)"
 
 [node name="Label" parent="extend_scramble_1/VBoxContainer2" index="0"]
 text = "Maximum Chunk Length"
 
 [node name="HSlider" parent="extend_scramble_1/VBoxContainer2/HSplitContainer" index="0"]
-min_value = 0.06
-max_value = 30.0
+min_value = 3.0
 step = 0.01
-value = 1.5
-exp_edit = true
+value = 3.0
+metadata/time = true
 
 [node name="VBoxContainer3" parent="extend_scramble_1" instance=ExtResource("3_b6nw4")]
 layout_mode = 2
@@ -1266,9 +1265,9 @@ tooltip_text = "Point where zigzag begins"
 text = "Start Point"
 
 [node name="HSlider" parent="extend_zigzag_1/VBoxContainer/HSplitContainer" index="0"]
-max_value = 1000.0
 step = 0.01
 value = 0.0
+metadata/time = true
 
 [node name="VBoxContainer2" parent="extend_zigzag_1" instance=ExtResource("3_b6nw4")]
 layout_mode = 2
@@ -1279,8 +1278,8 @@ text = "End Point"
 
 [node name="HSlider" parent="extend_zigzag_1/VBoxContainer2/HSplitContainer" index="0"]
 min_value = 1.0
-max_value = 1000.0
 step = 0.01
+metadata/time = true
 
 [node name="VBoxContainer3" parent="extend_zigzag_1" instance=ExtResource("3_b6nw4")]
 layout_mode = 2
@@ -2161,10 +2160,10 @@ tooltip_text = "The time in the file to reach that speed"
 text = "Goal Time"
 
 [node name="HSlider" parent="modify_speed_5/VBoxContainer2/HSplitContainer" index="0"]
-min_value = 0.01
-max_value = 120.0
+min_value = 1.0
 step = 0.01
 value = 10.01
+metadata/time = true
 
 [node name="modify_loudness_1" type="GraphNode" parent="."]
 layout_mode = 0
@@ -2335,9 +2334,9 @@ tooltip_text = "Adjusts the time at which the attack of each sound occurs"
 text = "Attack Offset"
 
 [node name="HSlider" parent="modify_stack/VBoxContainer4/HSplitContainer" index="0"]
-max_value = 30.0
 step = 0.01
 value = 0.0
+metadata/time = true
 
 [node name="VBoxContainer5" parent="modify_stack" instance=ExtResource("3_b6nw4")]
 layout_mode = 2

+ 13 - 138
scenes/main/control.gd

@@ -937,102 +937,18 @@ func _get_slider_values_ordered(node: Node) -> Array:
 	for child in node.get_children():
 		if child is Range:
 			var flag = child.get_meta("flag") if child.has_meta("flag") else ""
-			results.append([flag, child.value])
+			var time
+			if child.has_meta("time"):
+				time = child.get_meta("time")
+			else:
+				time = false
+			results.append([flag, child.value, time])
 		elif child.get_child_count() > 0:
 			var nested := _get_slider_values_ordered(child)
 			results.append_array(nested)
 	return results
 
-#func build_graph_from_connections(graph_edit: GraphEdit) -> Dictionary:
-	#var connections = graph_edit.get_connection_list()
-	#var graph := {}
-	#var reverse_graph := {}
-	#var all_nodes := {}
-#
-	## Collect all GraphNode names
-	#for child in graph_edit.get_children():
-		#if child is GraphNode:
-			#var name = str(child.name)
-			#all_nodes[name] = true
-			#graph[name] = []
-			#reverse_graph[name] = []
-#
-	## Build forward and reverse graphs
-	#for conn in connections:
-		#var from = str(conn["from_node"])
-		#var to = str(conn["to_node"])
-		#if graph.has(from) and graph.has(to):
-			#graph[from].append(to)
-			#reverse_graph[to].append(from)
-#
-	## Perform BFS from "inputfile"
-	#var reachable := {}
-	#var queue := ["inputfile"]
-	#while not queue.is_empty():
-		#var current = queue.pop_front()
-		#if reachable.has(current):
-			#continue
-		#reachable[current] = true
-		#for neighbor in graph.get(current, []):
-			#queue.append(neighbor)
-#
-	## Reverse BFS from "outputfile"
-	#var required := {}
-	#queue = ["outputfile"]
-	#while not queue.is_empty():
-		#var current = queue.pop_front()
-		#if required.has(current):
-			#continue
-		#required[current] = true
-		#for parent in reverse_graph.get(current, []):
-			#queue.append(parent)
-#
-	## Keep only nodes that are reachable both ways
-	#var used_nodes := []
-	#for node in reachable.keys():
-		#if required.has(node):
-			#used_nodes.append(node)
-#
-	#var pruned_graph := {}
-	#for node in used_nodes:
-		#var filtered_neighbors := []
-		#for neighbor in graph.get(node, []):
-			#if used_nodes.has(neighbor):
-				#filtered_neighbors.append(neighbor)
-		#pruned_graph[node] = filtered_neighbors
-#
-	#return {
-		#"graph": pruned_graph,
-		#"nodes": used_nodes
-	#}
-
-#func topological_sort(graph: Dictionary, nodes: Array) -> Array:
-	#var indegree := {}
-	#for node in nodes:
-		#indegree[node] = 0
-	#for node in nodes:
-		#for neighbor in graph[node]:
-			#indegree[neighbor] += 1
-#
-	#var queue := []
-	#for node in nodes:
-		#if indegree[node] == 0:
-			#queue.append(node)
-#
-	#var sorted := []
-	#while not queue.is_empty():
-		#var current = queue.pop_front()
-		#sorted.append(current)
-		#for neighbor in graph[current]:
-			#indegree[neighbor] -= 1
-			#if indegree[neighbor] == 0:
-				#queue.append(neighbor)
-#
-	#if sorted.size() != nodes.size():
-		#push_error("Cycle detected or disconnected graph.")
-		#return []
-	#
-	#return sorted
+
 
 func make_process(node: Node, process_count: int, current_infile: String, slider_data: Array) -> Array:
 	# Determine output extension: .wav or .ana based on the node's slot type
@@ -1052,6 +968,11 @@ func make_process(node: Node, process_count: int, current_infile: String, slider
 	for entry in slider_data:
 		var flag = entry[0]
 		var value = entry[1]
+		var time = entry[2] #checks if slider is a time percentage slider
+		if time == true:
+			var infile_length = run_command(cdpprogs_location + "/sfprops -d " + "\"%s\"" % current_infile)
+			infile_length = float(infile_length[0].strip_edges())
+			value = infile_length * (value / 100) #calculate percentage time of the input file
 		line += ("%s%.2f " % [flag, value]) if flag.begins_with("-") else ("%.2f " % value)
 	
 	return [line.strip_edges(), output_file]
@@ -1099,53 +1020,7 @@ func run_command(command: String) -> Array:
 	
 	return output
 
-#func run_batch_file():
-	#var is_windows = OS.get_name() == "Windows"
-	#var script_ext = ".bat" if is_windows else ".sh"
-	#var script_name = "ordered_script" + script_ext
-	#var script_path = ProjectSettings.globalize_path("user://%s" % script_name)
-#
-	#var output: Array = []
-	#var error: Array = []
-#
-	#var exit_code := 0
-	#if is_windows:
-		#exit_code = OS.execute("cmd.exe", ["/c", script_path], output, true, true)
-	#else:
-		#exit_code = OS.execute("sh", [script_path], output, true, true)
-#
-	#var output_str := ""
-	#for item in output:
-		#output_str += item + "\n"
-#
-	#var error_str := ""
-	#for item in error:
-		#error_str += item + "\n"
-#
-	#if exit_code == 0:
-		#if output_str.contains("ERROR:"): #checks if CDP reported an error but passed exit code 0 anyway
-			#console_output.append_text("[color=red][b]Processes failed[/b][/color]\n\n")
-			#console_output.append_text("[b]Error:[/b]\n")
-			#console_output.scroll_to_line(console_output.get_line_count() - 1)
-			#console_output.append_text(output_str + "\n")
-		#else:
-			#console_output.append_text("[color=green]Processes ran successfully[/color]\n\n")
-			#console_output.append_text("[b]Output:[/b]\n")
-			#console_output.scroll_to_line(console_output.get_line_count() - 1)
-			#console_output.append_text(output_str + "\n")
-			#
-			#if final_output_dir.ends_with(".wav"):
-				#output_audio_player.play_outfile(final_output_dir)
-				#outfile = final_output_dir
-			#
-			#var interface_settings = ConfigHandler.load_interface_settings() #checks if close console is enabled and closes console on a success
-			#if interface_settings.auto_close_console:
-				#$Console.hide()
-	#else:
-		#console_output.append_text("[color=red][b]Processes failed with exit code: %d[/b][/color]\n\n" % exit_code)
-		#console_output.append_text("[b]Error:[/b]\n")
-		#console_output.scroll_to_line(console_output.get_line_count() - 1)
-		#console_output.append_text(error_str + "\n")
+
 	
 func path_exists_through_all_nodes() -> bool:
 	var all_nodes = {}