diff --git a/assets/graphics/misc/musical_note.png b/assets/graphics/misc/musical_note.png new file mode 100644 index 000000000..9e9d64499 Binary files /dev/null and b/assets/graphics/misc/musical_note.png differ diff --git a/assets/graphics/misc/musical_note.png.import b/assets/graphics/misc/musical_note.png.import new file mode 100644 index 000000000..d55d651c5 --- /dev/null +++ b/assets/graphics/misc/musical_note.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dfjd72smxp6ma" +path="res://.godot/imported/musical_note.png-f1be7cc6341733e6ffe2fa5b650b80c2.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/misc/musical_note.png" +dest_files=["res://.godot/imported/musical_note.png-f1be7cc6341733e6ffe2fa5b650b80c2.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/src/Autoload/Export.gd b/src/Autoload/Export.gd index 3978edf0a..8f0e8a817 100644 --- a/src/Autoload/Export.gd +++ b/src/Autoload/Export.gd @@ -282,7 +282,7 @@ func process_animation(project := Global.current_project) -> void: for cel in frame.cels: var image := Image.new() image.copy_from(cel.get_image()) - var duration := frame.duration * (1.0 / project.fps) + var duration := frame.get_duration_in_seconds(project.fps) processed_images.append( ProcessedImage.new(image, project.frames.find(frame), duration) ) @@ -298,7 +298,7 @@ func process_animation(project := Global.current_project) -> void: image.copy_from(crop) if trim_images: image = image.get_region(image.get_used_rect()) - var duration := frame.duration * (1.0 / project.fps) + var duration := frame.get_duration_in_seconds(project.fps) processed_images.append(ProcessedImage.new(image, project.frames.find(frame), duration)) diff --git a/src/Classes/Frame.gd b/src/Classes/Frame.gd index 57f9611f5..52994988c 100644 --- a/src/Classes/Frame.gd +++ b/src/Classes/Frame.gd @@ -11,3 +11,17 @@ var user_data := "" ## User defined data, set in the frame properties. func _init(_cels: Array[BaseCel] = [], _duration := 1.0) -> void: cels = _cels duration = _duration + + +func get_duration_in_seconds(fps: float) -> float: + return duration * (1.0 / fps) + + +func position_in_seconds(project: Project, start_from := 0) -> float: + var pos := 0.0 + for i in range(start_from, project.frames.size()): + var frame := project.frames[i] + if frame == self: + break + pos += frame.get_duration_in_seconds(project.fps) + return pos diff --git a/src/UI/Timeline/CelButton.gd b/src/UI/Timeline/CelButton.gd index b23f2e2f6..50e0bcd48 100644 --- a/src/UI/Timeline/CelButton.gd +++ b/src/UI/Timeline/CelButton.gd @@ -404,10 +404,10 @@ func _sort_cel_indices_by_frame(a: Array, b: Array) -> bool: func _is_playing_audio() -> void: - var layer := Global.current_project.layers[layer] as AudioLayer - var audio_length := layer.audio.get_length() - var final_frame := audio_length * Global.current_project.fps - if frame < final_frame: - cel_texture.texture = preload("res://assets/graphics/icons/icon.png") + var frame_class := Global.current_project.frames[frame] + var layer_class := Global.current_project.layers[layer] as AudioLayer + var audio_length := layer_class.audio.get_length() + if frame_class.position_in_seconds(Global.current_project) < audio_length: + cel_texture.texture = preload("res://assets/graphics/misc/musical_note.png") else: cel_texture.texture = null diff --git a/src/UI/Timeline/FrameButton.gd b/src/UI/Timeline/FrameButton.gd index 82f63866c..2602a0f40 100644 --- a/src/UI/Timeline/FrameButton.gd +++ b/src/UI/Timeline/FrameButton.gd @@ -19,8 +19,9 @@ func _ready() -> void: func _update_tooltip() -> void: - var duration := Global.current_project.frames[frame].duration - var duration_sec := duration * (1.0 / Global.current_project.fps) + var frame_class := Global.current_project.frames[frame] + var duration := frame_class.duration + var duration_sec := frame_class.get_duration_in_seconds(Global.current_project.fps) var duration_str := str(duration_sec) if "." in duration_str: # If its a decimal value duration_str = "%.2f" % duration_sec # Up to 2 decimal places diff --git a/src/UI/Timeline/LayerButton.gd b/src/UI/Timeline/LayerButton.gd index c77e4e0b0..008cb4483 100644 --- a/src/UI/Timeline/LayerButton.gd +++ b/src/UI/Timeline/LayerButton.gd @@ -89,11 +89,10 @@ func _play_audio() -> void: if not layer.visible: return var audio_length := audio_player.stream.get_length() - var final_frame := audio_length * Global.current_project.fps - if Global.current_project.current_frame < final_frame: - var seconds_per_frame := 1.0 / Global.current_project.fps - var playback_position := Global.current_project.current_frame * seconds_per_frame - audio_player.play(playback_position) + var frame := Global.current_project.frames[Global.current_project.current_frame] + var frame_pos := frame.position_in_seconds(Global.current_project) + if frame_pos < audio_length: + audio_player.play(frame_pos) else: audio_player.stop()