Add track moving to audio clips
This commit is contained in:
@@ -13,11 +13,11 @@ variation_opentype = {
|
||||
|
||||
[node name="Track" type="Control"]
|
||||
clip_children = 1
|
||||
custom_minimum_size = Vector2(128, 74)
|
||||
custom_minimum_size = Vector2(128, 64)
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 382.0
|
||||
offset_bottom = 74.0
|
||||
offset_bottom = 64.0
|
||||
theme = ExtResource("1_tbi88")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||
|
||||
@@ -49,17 +49,23 @@ func _input(event):
|
||||
|
||||
if selected and dragging:
|
||||
if event is InputEventMouseMotion:
|
||||
var movement = event.relative.x / timeline.get_pixels_per_unit() * timeline.time_interval
|
||||
var movement = event.relative / timeline.get_pixels_per_unit() * timeline.time_interval
|
||||
|
||||
var mouse_position_timeline = (timeline.get_local_mouse_position().x / timeline.get_pixels_per_unit()) * timeline.time_interval
|
||||
var mouse_position_snapped = snapped(mouse_position_timeline, timeline.time_interval)
|
||||
|
||||
var track = timeline.get_track_idx_by_y(event.position.y)
|
||||
|
||||
if track != -1:
|
||||
track_idx = track
|
||||
|
||||
if event.is_command_or_control_pressed():
|
||||
var clip_length = end_time - start_time
|
||||
start_time = mouse_position_snapped
|
||||
end_time = start_time + clip_length
|
||||
else:
|
||||
start_time += movement
|
||||
end_time += movement
|
||||
start_time += movement.x
|
||||
end_time += movement.x
|
||||
|
||||
timeline.queue_sort()
|
||||
pass
|
||||
|
||||
@@ -35,6 +35,18 @@ func format_time_ms_minutes(ms: float) -> String:
|
||||
return "%02d:%02d.%03d" % [minutes, seconds, milliseconds]
|
||||
|
||||
|
||||
func get_track_idx_by_y(y: float):
|
||||
var idx = 0
|
||||
for track in track_list.get_children():
|
||||
if y >= track.global_position.y and y <= track.global_position.y + track.size.y:
|
||||
return idx
|
||||
idx += 1
|
||||
pass
|
||||
return -1
|
||||
|
||||
func get_track_by_idx(idx: int) -> Control:
|
||||
return track_list.get_child(idx)
|
||||
|
||||
func get_pixels_per_unit() -> float:
|
||||
return 50.0 * zoom
|
||||
|
||||
@@ -82,12 +94,17 @@ func _notification(what):
|
||||
if what == NOTIFICATION_SORT_CHILDREN:
|
||||
for c in get_children():
|
||||
if c is not AudioClip: continue
|
||||
|
||||
var track = get_track_by_idx(c.track_idx)
|
||||
|
||||
if track == null: return
|
||||
|
||||
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)
|
||||
c.position = Vector2(start, track.global_position.y - global_position.y)
|
||||
c.size = Vector2(width, track.size.y)
|
||||
|
||||
func _gui_input(event):
|
||||
var zoom_factor = 1.1
|
||||
|
||||
@@ -147,9 +147,20 @@ layout = SubResource("Resource_20kxa")
|
||||
[node name="Tracks" parent="VBoxContainer/VSplitContainer/HSplitContainer/LeftDock" instance=ExtResource("5_rgxdu")]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Track" parent="VBoxContainer/VSplitContainer/HSplitContainer/LeftDock/Tracks/VBoxContainer/TrackList" index="0"]
|
||||
custom_minimum_size = Vector2(128, 74)
|
||||
|
||||
[node name="Track2" parent="VBoxContainer/VSplitContainer/HSplitContainer/LeftDock/Tracks/VBoxContainer/TrackList" index="1"]
|
||||
custom_minimum_size = Vector2(128, 74)
|
||||
|
||||
[node name="Track3" parent="VBoxContainer/VSplitContainer/HSplitContainer/LeftDock/Tracks/VBoxContainer/TrackList" index="2"]
|
||||
custom_minimum_size = Vector2(128, 74)
|
||||
|
||||
[node name="Track4" parent="VBoxContainer/VSplitContainer/HSplitContainer/LeftDock/Tracks/VBoxContainer/TrackList" index="3"]
|
||||
custom_minimum_size = Vector2(128, 74)
|
||||
|
||||
[node name="Timeline" parent="VBoxContainer/VSplitContainer/HSplitContainer" node_paths=PackedStringArray("track_list") instance=ExtResource("7_xu70y")]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
track_list = NodePath("../LeftDock/Tracks/VBoxContainer/TrackList")
|
||||
|
||||
[node name="BottomDock" type="Container" parent="VBoxContainer/VSplitContainer"]
|
||||
|
||||
@@ -28,3 +28,4 @@ end_time = 1000.0
|
||||
layout_mode = 2
|
||||
start_time = 3000.0
|
||||
end_time = 10000.0
|
||||
track_idx = 1
|
||||
|
||||
@@ -26,15 +26,19 @@ layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="Track" parent="VBoxContainer/TrackList" instance=ExtResource("1_ueogm")]
|
||||
custom_minimum_size = Vector2(128, 74)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Track2" parent="VBoxContainer/TrackList" instance=ExtResource("1_ueogm")]
|
||||
custom_minimum_size = Vector2(128, 74)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Track3" parent="VBoxContainer/TrackList" instance=ExtResource("1_ueogm")]
|
||||
custom_minimum_size = Vector2(128, 74)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Track4" parent="VBoxContainer/TrackList" instance=ExtResource("1_ueogm")]
|
||||
custom_minimum_size = Vector2(128, 74)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="AddTrack" type="MenuButton" parent="VBoxContainer"]
|
||||
|
||||
Reference in New Issue
Block a user