1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-30 23:19:49 +00:00

Compare commits

..

5 commits

Author SHA1 Message Date
Emmanouil Papadeas b274e7ad0e
Merge 710f6d41e6 into 5ec316a50f 2024-12-13 15:29:46 +00:00
Emmanouil Papadeas 710f6d41e6 Only plays the portion of the sound that corresponds to the specific frame so maybe we should do that as well
When the animation is not running. If it is running, play the sound properly.
2024-12-13 17:29:35 +02:00
Emmanouil Papadeas 214ba1b17d Mute audio layer when hiding it mid-play 2024-12-13 17:21:49 +02:00
Emmanouil Papadeas 97495a19da Update audio cel buttons when changing the audio of the layer 2024-12-13 17:16:22 +02:00
Emmanouil Papadeas 019a8db21c Stop audio from playing when looping, and the audio does not play at the first frame 2024-12-13 17:13:32 +02:00
3 changed files with 41 additions and 8 deletions

View file

@ -1,7 +1,14 @@
extends Panel
## Emitted when the animation starts playing.
signal animation_started(forward: bool)
## Emitted when the animation reaches the final frame and is not looping,
## or if the animation is manually paused.
## Note: This signal is not emitted if the animation is looping.
signal animation_finished
## Emitted when the animation loops, meaning when it reaches the final frame
## and the animation keeps playing.
signal animation_looped
enum LoopType { NO, CYCLE, PINGPONG }
@ -688,9 +695,11 @@ func _on_AnimationTimer_timeout() -> void:
animation_timer.wait_time = (
project.frames[project.current_frame].duration * (1 / fps)
)
animation_looped.emit()
animation_timer.start()
LoopType.PINGPONG:
animation_forward = false
animation_looped.emit()
_on_AnimationTimer_timeout()
else:
@ -713,9 +722,11 @@ func _on_AnimationTimer_timeout() -> void:
animation_timer.wait_time = (
project.frames[project.current_frame].duration * (1 / fps)
)
animation_looped.emit()
animation_timer.start()
LoopType.PINGPONG:
animation_forward = true
animation_looped.emit()
_on_AnimationTimer_timeout()
frame_scroll_container.ensure_control_visible(
Global.frame_hbox.get_child(project.current_frame)

View file

@ -36,6 +36,7 @@ func _ready() -> void:
_is_playing_audio()
Global.cel_switched.connect(_is_playing_audio)
Global.current_project.fps_changed.connect(_is_playing_audio)
Global.current_project.layers[layer].audio_changed.connect(_is_playing_audio)
Global.current_project.layers[layer].playback_frame_changed.connect(_is_playing_audio)

View file

@ -47,6 +47,7 @@ func _ready() -> void:
layer.audio_changed.connect(func(): audio_player.stream = layer.audio)
add_child(audio_player)
Global.animation_timeline.animation_started.connect(_on_animation_started)
Global.animation_timeline.animation_looped.connect(_on_animation_looped)
Global.animation_timeline.animation_finished.connect(_on_animation_finished)
custom_minimum_size.y = Global.animation_timeline.cel_size
label.text = layer.name
@ -69,13 +70,29 @@ func _on_cel_switched() -> void:
z_index = 1 if button_pressed else 0
var layer := Global.current_project.layers[layer_index]
if layer is AudioLayer:
if not animation_running or Global.current_project.current_frame == layer.playback_frame:
_play_audio()
if not is_instance_valid(audio_player):
return
if not layer.is_visible_in_hierarchy():
audio_player.stop()
return
if animation_running:
if Global.current_project.current_frame == layer.playback_frame:
_play_audio(false)
else:
_play_audio(true)
func _on_animation_started(_dir: bool) -> void:
animation_running = true
_play_audio()
_play_audio(false)
func _on_animation_looped() -> void:
var layer := Global.current_project.layers[layer_index]
if layer is AudioLayer:
if layer.playback_frame != 0 or not layer.is_visible_in_hierarchy():
if is_instance_valid(audio_player):
audio_player.stop()
func _on_animation_finished() -> void:
@ -84,17 +101,21 @@ func _on_animation_finished() -> void:
audio_player.stop()
func _play_audio() -> void:
func _play_audio(single_frame: bool) -> void:
if not is_instance_valid(audio_player):
return
var layer := Global.current_project.layers[layer_index] as AudioLayer
if not layer.visible:
var project := Global.current_project
var layer := project.layers[layer_index] as AudioLayer
if not layer.is_visible_in_hierarchy():
return
var audio_length := layer.get_audio_length()
var frame := Global.current_project.frames[Global.current_project.current_frame]
var frame_pos := frame.position_in_seconds(Global.current_project, layer.playback_frame)
var frame := project.frames[project.current_frame]
var frame_pos := frame.position_in_seconds(project, layer.playback_frame)
if frame_pos >= 0 and frame_pos < audio_length:
audio_player.play(frame_pos)
if single_frame:
var timer := get_tree().create_timer(frame.get_duration_in_seconds(project.fps))
timer.timeout.connect(func(): audio_player.stop())
else:
audio_player.stop()