Interacting with the Timeline

The TimelinePanel allows to control the TimelinePanel.currentTime, the TimelinePanel.activeComposition, the current TimelineRow selection and the selected keyframes.

Controlling the time

# Get the user focused timeline panel
timeline=project.getLastFocusedTimelinePanel()

# Move the timeline to 1 sec
timeline.currentTime = Autograph.Timecode(0,0,1,0)

You can react to the timeline’s changes with the TimelinePanel.onCurrentTimeChanged() :

def onTimeChanged(timeline, time):
  print("The time is now %r" % time)

timeline.onCurrentTimeChanged(onTimeChanged)

Get the current rows selection

for row in timeline.getSelectedRows():
  # row.model is a tuple [Effect,Param] since each row
  # can be either an Effect (which could be a layer or generator or modifier) or a Param
  if row.model[0]:
    print(row.model[0].getDisplayName())

You can react to changes made to the selection with TimelinePanel.onSelectionChanged() .

The keyframes selection is also available with TimelinePanel.getSelectedKeyframes() .

Saving the current selection to JSON

You can save the selected row with TimelinePanel.getClipboardFromSelection() or even with an arbitrary list of rows and keyframes with TimelinePanel.getClipboard().

The TimelineClibpoard can then be saved to JSON with TimelineClipboard.getText(). It can also be stored in the Operating System’s clipboard with TimelineClipboard.storeInSystemClipboard(). This is useful to paste the JSON text in a text editor and save it somewhere.

To load from a JSON string, you can use TimelinePanel.getClipboardFromSystem() or directly construct a TimelineClipboard from the string.

Finally, to apply a clipboard to the current timeline selection, you can use TimelinePanel.applyClipboardToSelection(cb)()

timeline.getClipboardFromSelection().storeInSystemClipboard()

...

timeline.applyClipboardToSelection(timeline.getClipboardFromSystem())

Mapping time to Params

When accessing keyframes on a Param (e.g: using DoubleParamBase.getValue() or directly using Curve), the time is always expressed in seconds, in a time-space local to the parameter.

If a layer has a time-offset or has been time-stretched, the local time of any Param on a layer is no longer the same time as the timeline’s time.

If you need to programmatically change values on a Param at the current TimelinePanel.currentTime, you will need to first map it to the Param local time using:

paramLocalTime=timeline.mapTimelineToParamTime(param, timeline.timecodeToSeconds(timeline.currentTime))

If you need to map keyframes of a Param to their actual time on the timeline, you need to apply the inverse mapping:

keyframes = param.getCurve().getKeyFrames()
for k in keyframes:
  keyTimelineTime=timeline.mapParamTimeToTimeline(param, k.time)