diff --git a/src/Classes/Frame.gd b/src/Classes/Frame.gd index 21ef3ff9b..ec5358ab2 100644 --- a/src/Classes/Frame.gd +++ b/src/Classes/Frame.gd @@ -22,8 +22,11 @@ func position_in_seconds(project: Project, start_from := 0) -> float: var index := project.frames.find(self) if index > start_from: for i in range(start_from, index): - var frame := project.frames[i] - pos += frame.get_duration_in_seconds(project.fps) + if i >= 0: + var frame := project.frames[i] + pos += frame.get_duration_in_seconds(project.fps) + else: + pos += 1.0 / project.fps else: if start_from >= project.frames.size(): return -1.0 diff --git a/src/Classes/Layers/AudioLayer.gd b/src/Classes/Layers/AudioLayer.gd index ca22fb086..7dd2f5f27 100644 --- a/src/Classes/Layers/AudioLayer.gd +++ b/src/Classes/Layers/AudioLayer.gd @@ -13,8 +13,13 @@ var audio: AudioStream: ## The audio stream of the layer. audio_changed.emit() var playback_position := 0.0: ## The time in seconds where the audio stream starts playing. get(): - var frame := project.frames[playback_frame] - return frame.position_in_seconds(project) + if playback_frame >= 0: + var frame := project.frames[playback_frame] + return frame.position_in_seconds(project) + var pos := 0.0 + for i in absi(playback_frame): + pos -= 1.0 / project.fps + return pos var playback_frame := 0: ## The frame where the audio stream starts playing. set(value): playback_frame = value diff --git a/src/UI/Timeline/LayerButton.gd b/src/UI/Timeline/LayerButton.gd index ecd09324a..fbb564bd5 100644 --- a/src/UI/Timeline/LayerButton.gd +++ b/src/UI/Timeline/LayerButton.gd @@ -76,7 +76,11 @@ func _on_cel_switched() -> void: audio_player.stop() return if animation_running: - if Global.current_project.current_frame == layer.playback_frame: + var current_frame := Global.current_project.current_frame + if ( + current_frame == layer.playback_frame + or (current_frame == 0 and layer.playback_frame < 0) + ): _play_audio(false) else: _play_audio(true) @@ -90,7 +94,7 @@ func _on_animation_started(_dir: bool) -> void: 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 layer.playback_frame > 0 or not layer.is_visible_in_hierarchy(): if is_instance_valid(audio_player): audio_player.stop()