From 1b7494a76745959e25d0ec9a194d872b1e012269 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Sun, 8 Dec 2024 00:23:38 +0200 Subject: [PATCH] Load ogg audio files --- src/Autoload/OpenSave.gd | 16 ++++++++++++++++ src/UI/Timeline/LayerButton.gd | 1 + 2 files changed, 17 insertions(+) diff --git a/src/Autoload/OpenSave.gd b/src/Autoload/OpenSave.gd index 0a8eb3237..cc709a8e4 100644 --- a/src/Autoload/OpenSave.gd +++ b/src/Autoload/OpenSave.gd @@ -45,6 +45,8 @@ func handle_loading_file(file: String) -> void: return var file_name: String = file.get_file().get_basename() Global.control.find_child("ShaderEffect").change_shader(shader, file_name) + elif file_ext == "ogg": # Audio file + open_audio_file(file) else: # Image files # Attempt to load as APNG. @@ -902,6 +904,20 @@ func set_new_imported_tab(project: Project, path: String) -> void: Global.tabs.delete_tab(prev_project_pos) +func open_audio_file(path: String) -> void: + var audio_stream := AudioStreamOggVorbis.load_from_file(path) + if not is_instance_valid(audio_stream): + return + var project := Global.current_project + for layer in project.layers: + if layer is AudioLayer and not is_instance_valid(layer.audio): + layer.audio = audio_stream + return + var new_layer := AudioLayer.new(project) + new_layer.audio = audio_stream + Global.animation_timeline.add_layer(new_layer, project) + + func update_autosave() -> void: if not is_instance_valid(autosave_timer): return diff --git a/src/UI/Timeline/LayerButton.gd b/src/UI/Timeline/LayerButton.gd index 7c2aa0896..9ffbbdcbd 100644 --- a/src/UI/Timeline/LayerButton.gd +++ b/src/UI/Timeline/LayerButton.gd @@ -43,6 +43,7 @@ func _ready() -> void: elif layer is AudioLayer: audio_player = AudioStreamPlayer.new() audio_player.stream = layer.audio + layer.audio_changed.connect(func(): audio_player.stream = layer.audio) add_child(audio_player) custom_minimum_size.y = Global.animation_timeline.cel_size label.text = layer.name