Skip to content

Commit 4705c5b

Browse files
committed
Make use of new Timeline lookup APIs
1 parent cc1735b commit 4705c5b

File tree

5 files changed

+36
-108
lines changed

5 files changed

+36
-108
lines changed

src/windows/export.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,7 @@ def updateFrameRate(self):
359359
self.delayed_fps_timer.start()
360360

361361
# Determine max frame (based on clips)
362-
timeline_length = 0.0
363-
fps = self.timeline.info.fps.ToFloat()
364-
clips = self.timeline.Clips()
365-
for clip in clips:
366-
clip_last_frame = clip.Position() + clip.Duration()
367-
if clip_last_frame > timeline_length:
368-
# Set max length of timeline
369-
timeline_length = clip_last_frame
370-
371-
# Convert to int and round
372-
self.timeline_length_int = round(timeline_length * fps) + 1
362+
self.timeline_length_int = self.timeline.GetMaxFrame()
373363

374364
# Set the min and max frame numbers for this project
375365
self.txtStartFrame.setValue(1)

src/windows/main_window.py

+6-30
Original file line numberDiff line numberDiff line change
@@ -914,28 +914,16 @@ def actionUpdate_trigger(self, event):
914914
log.error("Unable to open the download page: {}".format(str(ex)))
915915

916916
def actionPlay_trigger(self, event, force=None):
917-
918-
# Determine max frame (based on clips)
919-
timeline_length = 0.0
920-
fps = get_app().window.timeline_sync.timeline.info.fps.ToFloat()
921-
clips = get_app().window.timeline_sync.timeline.Clips()
922-
for clip in clips:
923-
clip_last_frame = clip.Position() + clip.Duration()
924-
if clip_last_frame > timeline_length:
925-
# Set max length of timeline
926-
timeline_length = clip_last_frame
927-
928-
# Convert to int and round
929-
timeline_length_int = round(timeline_length * fps) + 1
930-
931917
if force == "pause":
932918
self.actionPlay.setChecked(False)
933919
elif force == "play":
934920
self.actionPlay.setChecked(True)
935921

936922
if self.actionPlay.isChecked():
923+
# Determine max frame (based on clips)
924+
max_frame = get_app().window.timeline_sync.timeline.GetMaxFrame()
937925
ui_util.setup_icon(self, self.actionPlay, "actionPlay", "media-playback-pause")
938-
self.PlaySignal.emit(timeline_length_int)
926+
self.PlaySignal.emit(max_frame)
939927

940928
else:
941929
ui_util.setup_icon(self, self.actionPlay, "actionPlay") # to default
@@ -1014,21 +1002,9 @@ def actionJumpStart_trigger(self, event):
10141002
def actionJumpEnd_trigger(self, event):
10151003
log.info("actionJumpEnd_trigger")
10161004

1017-
# Determine max frame (based on clips)
1018-
timeline_length = 0.0
1019-
fps = get_app().window.timeline_sync.timeline.info.fps.ToFloat()
1020-
clips = get_app().window.timeline_sync.timeline.Clips()
1021-
for clip in clips:
1022-
clip_last_frame = clip.Position() + clip.Duration()
1023-
if clip_last_frame > timeline_length:
1024-
# Set max length of timeline
1025-
timeline_length = clip_last_frame
1026-
1027-
# Convert to int and round
1028-
timeline_length_int = round(timeline_length * fps) + 1
1029-
1030-
# Seek to the 1st frame
1031-
self.SeekSignal.emit(timeline_length_int)
1005+
# Determine last frame (based on clips) & seek there
1006+
max_frame = get_app().window.timeline_sync.timeline.GetMaxFrame()
1007+
self.SeekSignal.emit(max_frame)
10321008

10331009
def actionSaveFrame_trigger(self, event):
10341010
log.info("actionSaveFrame_trigger")

src/windows/models/properties_model.py

+18-38
Original file line numberDiff line numberDiff line change
@@ -91,42 +91,24 @@ def update_item_timeout(self):
9191
log.info("Update item: %s" % item_type)
9292

9393
if item_type == "clip":
94-
c = None
95-
clips = get_app().window.timeline_sync.timeline.Clips()
96-
for clip in clips:
97-
if clip.Id() == item_id:
98-
c = clip
99-
break
100-
101-
# Append to selected clips
102-
self.selected.append((c, item_type))
94+
c = get_app().window.timeline_sync.timeline.GetClip(item_id)
95+
if c:
96+
# Append to selected items
97+
self.selected.append((c, item_type))
10398

10499
if item_type == "transition":
105-
t = None
106-
trans = get_app().window.timeline_sync.timeline.Effects()
107-
for tran in trans:
108-
if tran.Id() == item_id:
109-
t = tran
110-
break
111-
112-
# Append to selected clips
113-
self.selected.append((t, item_type))
100+
t = get_app().window.timeline_sync.timeline.GetTimelineEffect(item_id)
101+
if t:
102+
# Append to selected items
103+
self.selected.append((t, item_type))
114104

115105
if item_type == "effect":
116-
e = None
117-
clips = get_app().window.timeline_sync.timeline.Clips()
118-
for clip in clips:
119-
for effect in clip.Effects():
120-
if effect.Id() == item_id:
121-
e = effect
122-
break
123-
124-
# Filter out basic properties, since this is an effect on a clip
125-
self.filter_base_properties = ["position", "layer", "start", "end", "duration"]
126-
127-
# Append to selected items
128-
self.selected.append((e, item_type))
129-
106+
e = get_app().window.timeline_sync.timeline.GetClipEffect(item_id)
107+
if e:
108+
# Filter out basic properties, since this is an effect on a clip
109+
self.filter_base_properties = ["position", "layer", "start", "end", "duration"]
110+
# Append to selected items
111+
self.selected.append((e, item_type))
130112

131113
# Update frame # from timeline
132114
self.update_frame(get_app().window.preview_thread.player.Position(), reload_model=False)
@@ -159,12 +141,10 @@ def update_frame(self, frame_number, reload_model=True):
159141
parent_clip_id = effect.parent["id"]
160142

161143
# Find this clip object
162-
clips = get_app().window.timeline_sync.timeline.Clips()
163-
for c in clips:
164-
if c.Id() == parent_clip_id:
165-
# Override the selected clip object (so the effect gets the correct starting position)
166-
clip = c
167-
break
144+
c = get_app().window.timeline_sync.timeline.GetClip(parent_clip_id)
145+
if c:
146+
# Override the selected clip object (so the effect gets the correct starting position)
147+
clip = c
168148

169149
# Get FPS from project
170150
fps = get_app().project.get("fps")

src/windows/video_widget.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,9 @@ def refreshTriggered(self):
679679

680680
def transformTriggered(self, clip_id):
681681
"""Handle the transform signal when it's emitted"""
682+
win = get_app().window
682683
need_refresh = False
684+
683685
# Disable Transform UI
684686
if self and self.transforming_clip:
685687
# Is this the same clip_id already being transformed?
@@ -691,20 +693,15 @@ def transformTriggered(self, clip_id):
691693
# Get new clip for transform
692694
if clip_id:
693695
self.transforming_clip = Clip.get(id=clip_id)
696+
self.transforming_clip_object = win.timeline_sync.timeline.GetClip(clip_id)
697+
if self.transforming_clip and self.transforming_clip_object:
698+
needs_refresh = True
694699

695-
if self.transforming_clip:
696-
self.transforming_clip_object = None
697-
clips = get_app().window.timeline_sync.timeline.Clips()
698-
for clip in clips:
699-
if clip.Id() == self.transforming_clip.id:
700-
self.transforming_clip_object = clip
701-
need_refresh = True
702-
break
703700

704701
# Update the preview and reselct current frame in properties
705702
if need_refresh:
706-
get_app().window.refreshFrameSignal.emit()
707-
get_app().window.propertyTableView.select_frame(get_app().window.preview_thread.player.Position())
703+
win.refreshFrameSignal.emit()
704+
win.propertyTableView.select_frame(win.preview_thread.player.Position())
708705

709706
def resizeEvent(self, event):
710707
"""Widget resize event"""

src/windows/views/timeline_webview.py

+4-19
Original file line numberDiff line numberDiff line change
@@ -942,12 +942,7 @@ def Show_Waveform_Triggered(self, clip_ids):
942942
file_path = clip.data["reader"]["path"]
943943

944944
# Find actual clip object from libopenshot
945-
c = None
946-
clips = get_app().window.timeline_sync.timeline.Clips()
947-
for clip_object in clips:
948-
if clip_object.Id() == clip_id:
949-
c = clip_object
950-
945+
c = get_app().window.timeline_sync.timeline.GetClip(clip_id)
951946
if c and c.Reader() and not c.Reader().info.has_single_image:
952947
# Find frame 1 channel_filter property
953948
channel_filter = c.channel_filter.GetInt(1)
@@ -2209,7 +2204,7 @@ def Time_Triggered(self, action, clip_ids, speed="1X", playhead_position=0.0):
22092204
original_duration = clip.data["original_data"]["duration"]
22102205

22112206
log.info('Updating timing for clip ID {}, original duration: {}'
2212-
.format(clip.id, original_duration))
2207+
.format(clip.id, original_duration))
22132208
log.debug(clip.data)
22142209

22152210
# Extend end & duration (due to freeze)
@@ -2237,25 +2232,15 @@ def Time_Triggered(self, action, clip_ids, speed="1X", playhead_position=0.0):
22372232
del clip.data["time"]["Points"][-1]
22382233

22392234
# Find actual clip object from libopenshot
2240-
c = None
2241-
clips = get_app().window.timeline_sync.timeline.Clips()
2242-
for clip_object in clips:
2243-
if clip_object.Id() == clip_id:
2244-
c = clip_object
2245-
break
2235+
c = get_app().window.timeline_sync.timeline.GetClip(clip_id)
22462236
if c:
22472237
# Look up correct position from time curve
22482238
start_animation_frames_value = c.time.GetLong(start_animation_frames)
22492239

22502240
# Do we already have a volume curve? Look up intersecting frame # from volume curve
22512241
if len(clip.data["volume"]["Points"]) > 1:
22522242
# Find actual clip object from libopenshot
2253-
c = None
2254-
clips = get_app().window.timeline_sync.timeline.Clips()
2255-
for clip_object in clips:
2256-
if clip_object.Id() == clip_id:
2257-
c = clip_object
2258-
break
2243+
c = get_app().window.timeline_sync.timeline.GetClip(clip_id)
22592244
if c:
22602245
# Look up correct volume from time curve
22612246
start_volume_value = c.volume.GetValue(start_animation_frames)

0 commit comments

Comments
 (0)