Quellcode durchsuchen

added check for updates, fixed bug with splitting files

Jonathan Higgins vor 7 Monaten
Ursprung
Commit
db8a88c455

+ 6 - 0
addons/audio_preview/voice_preview_generator.gd

@@ -34,6 +34,7 @@ func generate_preview(stream: AudioStreamWAV, image_max_width: int = 500):
 	
 	if image_max_width <= 0:
 		return # User wasn't remarkably brilliant
+		
 	
 	if is_working:
 		must_abort = true
@@ -155,3 +156,8 @@ func generate_preview(stream: AudioStreamWAV, image_max_width: int = 500):
 	
 	emit_signal("texture_ready", ImageTexture.create_from_image(img))
 	
+func _reset_to_blank():
+	var img = Image.create(1, IMAGE_HEIGHT, true, Image.FORMAT_RGBA8)
+	img.fill(Color.DARK_SLATE_GRAY)
+	emit_signal("texture_ready", ImageTexture.create_from_image(img))
+	

+ 0 - 17
graph_node.gd

@@ -1,17 +0,0 @@
-extends GraphNode
-
-
-# Called when the node enters the scene tree for the first time.
-func _ready() -> void:
-	var titlebar = self.get_titlebar_hbox()
-	var btn = Button.new()
-	btn.text = "?"
-	btn.connect("pressed", Callable(self, "_open_help").bind("help_pressed")) #pass key (process name) when button is pressed
-	titlebar.add_child(btn)
-
-# Called every frame. 'delta' is the elapsed time since the previous frame.
-func _process(delta: float) -> void:
-	pass
-
-func _open_help(key: String):
-	print(key)

+ 0 - 1
graph_node.gd.uid

@@ -1 +0,0 @@
-uid://b362lflsl8oov

+ 0 - 23
node_test.tscn

@@ -1,23 +0,0 @@
-[gd_scene load_steps=2 format=3 uid="uid://0o42n3yf5uah"]
-
-[ext_resource type="Script" uid="uid://b362lflsl8oov" path="res://graph_node.gd" id="1_h6fog"]
-
-[node name="GraphNode" type="GraphNode"]
-offset_left = 230.0
-offset_top = 100.0
-offset_right = 621.0
-offset_bottom = 543.0
-title = "TestNode"
-slot/0/left_enabled = false
-slot/0/left_type = 0
-slot/0/left_color = Color(1, 1, 1, 1)
-slot/0/left_icon = null
-slot/0/right_enabled = false
-slot/0/right_type = 0
-slot/0/right_color = Color(1, 1, 1, 1)
-slot/0/right_icon = null
-slot/0/draw_stylebox = true
-script = ExtResource("1_h6fog")
-
-[node name="Control" type="Control" parent="."]
-layout_mode = 2

+ 14 - 2
scenes/Nodes/audioplayer.gd

@@ -63,13 +63,26 @@ func _on_file_selected(path: String):
 	voice_preview_generator.generate_preview(audio_player.stream)
 	Global.infile = path
 	print("Infile set: " + Global.infile)
+	reset_playback()
+	
+func reset_playback():
 	$LoopRegion.size.x = 0
 	$Playhead.position.x = 0
+	$PlayButton.text = "Play"
+	$Timer.stop()
+	Global.trim_infile = false
+	
 	
 func play_outfile(path: String):
 	outfile_path = path
 	audio_player.stream = AudioStreamWAV.load_from_file(path)
+	print(audio_player.stream)
+	if audio_player.stream == null:
+		voice_preview_generator._reset_to_blank()
+		reset_playback()
+		return
 	voice_preview_generator.generate_preview(audio_player.stream)
+	reset_playback()
 
 	
 func recycle_outfile(path: String):
@@ -81,8 +94,7 @@ func recycle_outfile(path: String):
 	voice_preview_generator.generate_preview(audio_player.stream)
 	Global.infile = path
 	print("Infile set: " + Global.infile)
-	$LoopRegion.size.x = 0
-	$Playhead.position.x = 0
+	reset_playback()
 
 
 func _on_play_button_button_down() -> void:

+ 71 - 0
scenes/Nodes/check_for_updates.gd

@@ -0,0 +1,71 @@
+extends HTTPRequest
+
+const GITHUB_API_URL := "https://api.github.com/repos/j-p-higgins/SoundThread/releases/latest"
+var current_version 
+
+func _ready():
+	$UpdatePopup.hide()
+	
+	#get current version from export presets
+	var export_config = ConfigFile.new()
+	export_config.load("res://export_presets.cfg")
+	current_version =  export_config.get_value("preset.0.options", "application/product_version", "version unknown")
+	
+	#call github api
+	if not is_connected("request_completed", Callable(self, "_on_request_completed")):
+		connect("request_completed", Callable(self, "_on_request_completed"))
+	request(GITHUB_API_URL, ["User-Agent: SoundThread0"])
+
+func _on_request_completed(result, response_code, headers, body):
+	if response_code != 200:
+		print("Failed to check for updates.")
+		return
+
+	var response = JSON.parse_string(body.get_string_from_utf8())
+	if typeof(response) != TYPE_DICTIONARY:
+		print("Invalid JSON in GitHub response.")
+		return
+
+	var latest_version = response.get("tag_name", "")
+	print("Latest GitHub version: ", latest_version)
+
+	if _version_is_newer(latest_version, current_version):
+		_show_update_popup(latest_version)
+		
+func _version_is_newer(latest: String, current: String) -> bool:
+	#clean up version tags remove -alpha -beta and v and split the number sup
+	latest = trim_suffix(latest, "-alpha")
+	latest = trim_suffix(latest, "-beta")
+	var latest_parts = latest.trim_prefix("v").split(".")
+	
+	current = trim_suffix(current, "-alpha")
+	current = trim_suffix(current, "-beta")
+	var current_parts = current.trim_prefix("v").split(".")
+	
+	#check if current version < latest
+	for i in range(min(latest_parts.size(), current_parts.size())):
+		var l = int(latest_parts[i])
+		var c = int(current_parts[i])
+		if l > c:
+			return true
+		elif l < c:
+			return false
+	return latest_parts.size() > current_parts.size()
+	
+func trim_suffix(text: String, suffix: String) -> String:
+	#used to remove -alpha and -beta tags
+	if text.ends_with(suffix):
+		return text.substr(0, text.length() - suffix.length())
+	return text
+	
+func _show_update_popup(new_version: String):
+	$UpdatePopup/Label.text = "A new version of SoundThread (" + new_version + ") is available to download."
+	$UpdatePopup.show()
+
+func _on_open_audio_settings_button_down() -> void:
+	$UpdatePopup.hide()
+	OS.shell_open("https://github.com/j-p-higgins/SoundThread/releases/latest")
+
+
+func _on_update_popup_close_requested() -> void:
+	$UpdatePopup.hide()

+ 1 - 0
scenes/Nodes/check_for_updates.gd.uid

@@ -0,0 +1 @@
+uid://b6r7k326k3vif

+ 1 - 1
scenes/main/control.gd

@@ -740,7 +740,7 @@ func run_thread_with_branches():
 	
 	#If trim is enabled trim input audio
 	if Global.trim_infile == true:
-		run_command(cdpprogs_location + "/sfedit", ["cut", "1", "2\"%s\"" % starting_infile, "\"%s_trimmed.wav\"" % Global.outfile, str(Global.infile_start), str(Global.infile_stop)])
+		run_command(cdpprogs_location + "/sfedit", ["cut", "1", starting_infile, "%s_trimmed.wav" % Global.outfile, str(Global.infile_start), str(Global.infile_stop)])
 		starting_infile = Global.outfile + "_trimmed.wav"
 		# Mark trimmed file for cleanup if needed
 		if delete_intermediate_outputs:

+ 35 - 1
scenes/main/control.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=7 format=3 uid="uid://bcs87y7ptx3ke"]
+[gd_scene load_steps=8 format=3 uid="uid://bcs87y7ptx3ke"]
 
 [ext_resource type="Script" uid="uid://bdlfvuljckmu1" path="res://scenes/main/control.gd" id="1_2f0aq"]
 [ext_resource type="Script" uid="uid://l2yejnjysupr" path="res://scenes/main/graph_edit.gd" id="2_3ioqo"]
@@ -6,6 +6,7 @@
 [ext_resource type="Texture2D" uid="uid://cdwux1smquvpi" path="res://theme/images/logo.png" id="4_3ioqo"]
 [ext_resource type="PackedScene" uid="uid://dta7rfalv4uvd" path="res://scenes/main/audio_settings.tscn" id="5_dtf4o"]
 [ext_resource type="Script" uid="uid://dlcbmyu3s2phc" path="res://scenes/menu/search_menu.gd" id="6_fyarh"]
+[ext_resource type="Script" uid="uid://b6r7k326k3vif" path="res://scenes/Nodes/check_for_updates.gd" id="7_1kc3g"]
 
 [node name="Control" type="Control"]
 layout_mode = 3
@@ -370,6 +371,37 @@ horizontal_scroll_mode = 0
 layout_mode = 2
 size_flags_horizontal = 3
 
+[node name="CheckForUpdates" type="HTTPRequest" parent="."]
+script = ExtResource("7_1kc3g")
+
+[node name="UpdatePopup" type="Window" parent="CheckForUpdates" groups=["popup_windows"]]
+auto_translate_mode = 1
+title = "New Update Available"
+initial_position = 2
+size = Vector2i(379, 100)
+visible = false
+transient = true
+exclusive = true
+unresizable = true
+popup_window = true
+
+[node name="Label" type="Label" parent="CheckForUpdates/UpdatePopup"]
+offset_left = 14.0
+offset_top = 8.0
+offset_right = 366.0
+offset_bottom = 65.0
+text = "A new version of SoundThread (0.0.0) is available to download."
+horizontal_alignment = 1
+vertical_alignment = 1
+autowrap_mode = 2
+
+[node name="OpenAudioSettings" type="Button" parent="CheckForUpdates/UpdatePopup"]
+offset_left = -2.0
+offset_top = 69.0
+offset_right = 382.0
+offset_bottom = 100.0
+text = "Get the update"
+
 [connection signal="connection_request" from="GraphEdit" to="." method="_on_graph_edit_connection_request"]
 [connection signal="delete_nodes_request" from="GraphEdit" to="." method="_on_graph_edit_delete_nodes_request"]
 [connection signal="disconnection_request" from="GraphEdit" to="." method="_on_graph_edit_disconnection_request"]
@@ -399,3 +431,5 @@ size_flags_horizontal = 3
 [connection signal="close_requested" from="AudioSettings" to="." method="_on_audio_settings_close_requested"]
 [connection signal="about_to_popup" from="SearchMenu" to="SearchMenu" method="_on_about_to_popup"]
 [connection signal="text_changed" from="SearchMenu/VBoxContainer/SearchBar" to="SearchMenu" method="_on_search_bar_text_changed"]
+[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"]