WIP: audio clip controls and UI

This commit is contained in:
2025-02-16 17:17:53 +01:00
parent 60282fc89c
commit ec16023158
5 changed files with 138 additions and 1 deletions

63
Scripts/AudioClip.gd Normal file
View File

@@ -0,0 +1,63 @@
class_name AudioClip
extends Panel
@export var start_time: float = 0.0
@export var end_time: float = 0.0
@export var track_idx: int = 0
var timeline: Timeline
var dragging: bool
var selected: bool
func _ready():
timeline = get_parent()
func _input(event):
var rect = get_global_rect()
var mouse_position = get_global_mouse_position()
if event is InputEventMouseButton:
if event.pressed and event.button_mask == MOUSE_BUTTON_LEFT:
if selected:
mouse_default_cursor_shape = CURSOR_MOVE
dragging = true
else:
dragging = false
mouse_default_cursor_shape = CURSOR_ARROW
if rect.has_point(mouse_position):
selected = true
make_selected()
return
else:
selected = false
make_deselected()
return
if !event.pressed and dragging:
dragging = false
mouse_default_cursor_shape = CURSOR_ARROW
if selected and dragging:
if event is InputEventMouseMotion:
var movement = event.relative.x / timeline.get_pixels_per_unit() * timeline.time_interval
start_time += movement
end_time += movement
if event.is_command_or_control_pressed():
start_time = snapped(start_time, timeline.time_interval)
end_time = snapped(end_time, timeline.time_interval)
timeline.queue_sort()
pass
func make_selected():
var color = get_theme_color("selected_modulate", "AudioClip")
modulate = color
pass
func make_deselected():
var color = get_theme_color("deselected_modulate", "AudioClip")
modulate = color
pass

View File

@@ -34,6 +34,10 @@ func format_time_ms_minutes(ms: float) -> String:
var milliseconds = fmod(ms, 1000.0)
return "%02d:%02d.%03d" % [minutes, seconds, milliseconds]
func get_pixels_per_unit() -> float:
return 50.0 * zoom
func _draw():
var primary_color = get_theme_color("line_primary_color", "Timeline")
var secondary_color = get_theme_color("line_secondary_color", "Timeline")
@@ -70,8 +74,21 @@ func _draw():
draw_string(font, Vector2(x - time_label_offset_x, time_label_offset_y), format_time_ms_minutes(time), HORIZONTAL_ALIGNMENT_CENTER, -1, font_size, primary_color)
else:
draw_line(Vector2(x, 28.0), Vector2(x, timeline_y), secondary_color, 1)
queue_sort()
pass
func _notification(what):
if what == NOTIFICATION_SORT_CHILDREN:
for c in get_children():
if c is not AudioClip: continue
var pixels_per_unit := 50.0 * zoom
var start = ((c.start_time / time_interval) * pixels_per_unit) - time_offset
var width = (c.end_time - c.start_time) / time_interval * pixels_per_unit
c.position = Vector2(start, 0.0)
c.size = Vector2(width, c.size.y)
func _gui_input(event):
var zoom_factor = 1.1
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_WHEEL_DOWN: