1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Some code changes to allow for potential negative frames placement for audio

This woud allow audio to be placed in negative frames, which essentially means that audio would start before the first frame. This is not yet supported, however, because I don't know how to make it work with FFMPEG.
This commit is contained in:
Emmanouil Papadeas 2024-12-14 00:25:57 +02:00
parent 710f6d41e6
commit a150b66fe7
3 changed files with 18 additions and 6 deletions

View file

@ -22,8 +22,11 @@ func position_in_seconds(project: Project, start_from := 0) -> float:
var index := project.frames.find(self) var index := project.frames.find(self)
if index > start_from: if index > start_from:
for i in range(start_from, index): for i in range(start_from, index):
var frame := project.frames[i] if i >= 0:
pos += frame.get_duration_in_seconds(project.fps) var frame := project.frames[i]
pos += frame.get_duration_in_seconds(project.fps)
else:
pos += 1.0 / project.fps
else: else:
if start_from >= project.frames.size(): if start_from >= project.frames.size():
return -1.0 return -1.0

View file

@ -13,8 +13,13 @@ var audio: AudioStream: ## The audio stream of the layer.
audio_changed.emit() audio_changed.emit()
var playback_position := 0.0: ## The time in seconds where the audio stream starts playing. var playback_position := 0.0: ## The time in seconds where the audio stream starts playing.
get(): get():
var frame := project.frames[playback_frame] if playback_frame >= 0:
return frame.position_in_seconds(project) 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. var playback_frame := 0: ## The frame where the audio stream starts playing.
set(value): set(value):
playback_frame = value playback_frame = value

View file

@ -76,7 +76,11 @@ func _on_cel_switched() -> void:
audio_player.stop() audio_player.stop()
return return
if animation_running: 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) _play_audio(false)
else: else:
_play_audio(true) _play_audio(true)
@ -90,7 +94,7 @@ func _on_animation_started(_dir: bool) -> void:
func _on_animation_looped() -> void: func _on_animation_looped() -> void:
var layer := Global.current_project.layers[layer_index] var layer := Global.current_project.layers[layer_index]
if layer is AudioLayer: 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): if is_instance_valid(audio_player):
audio_player.stop() audio_player.stop()