top of page
  • Writer's pictureTaylor Glad

Snap Cues to Slice Markers

Updated: Mar 31

Explanation

Snap cues to slice markers in a timeline group.


When I have to time a lot of cues out to music or an audio track, I like to add slice markers to a designated audio/video cue in the Time & Loops tab of the inspector. (If I have multiple things to time out, I will duplicate the audio cues and label them for each purpose.) To add the markers, I just preview the cue I want to add slices to (hotkey v) and add slice markers as it plays (hotkey m). I prefer this over the "Record Cue Sequence" feature because it lets me visually line things up with the audio waveform, and it lets me tweak timings a little easier as I go (rewinding or jumping around the timeline is pretty easy). This also lets me keep different versions of the timings to refer back to by duplicating the cues.


In the group cue's timeline view, the audio/video cue's slice markers form vertical lines, letting you align additional cues to the times you marked. Usually it's pretty easy to line up cues manually by dragging them in this view, but when you have more than 50 cues to time out, this script is handy to line them all up instantly.


Run this script after selecting an audio or video cue within a timeline group, or with a timeline group selected that has an audio or video cue as the first child (at the top of the group). The script skips lining up cues that aren't armed, and omits slices before the start time of the audio/video cue. It will also adjust for pre-wait time on the audio/video cue to make everything line up in timeline view.





 

Script

Copy the text below and paste it into a script cue in your QLab workspace. I recommend assigning it a hotkey, or I like to give each script cue a unique cue number using letters, and then trigger it from Bitfocus Companion.

Built for QLab 5. Works for QLab 4 if you change the line: "tell application id "com.figure53.QLab.5" to tell front workspace" for "tell application id "com.figure53.QLab.4" to tell front workspace"




--Snap cues to slice markers
--Run with an audio or video cue selected within a timeline group, or with a timeline group selected that has an audio or video cue as the first child (at the top of the group)
--the script omits cues that aren't armed, and omits slices before the start time of a cue. It will also adjust for the slice cue's pre-wait time to make everything line up in timeline view.
--Taylor Glad 12/28/2023

--set the type of cue here that you want the script to look for and snap to slice markers
set cueTypeToSnap to "start"

tell application id "com.figure53.QLab.5" to tell front workspace
set selectedCue to first item of (selected as list)
set cueType to q type of selectedCue
if cueType is not in {"Group", "Audio", "Video"} then
display dialog "Please select a group cue with an audio/video cue, or select an audio/video cue inside a group cue." with icon 2
else

--set groupCue and sliceCue
if cueType is in {"Audio", "Video"} then
set groupCue to parent of selectedCue
set sliceCue to selectedCue
set groupChildren to cues of item 1 of groupCue
else if cueType is "group" then
set groupCue to selectedCue
set groupChildren to cues of item 1 of groupCue

--if the group cue doesn't have the right conditions
if (count of groupChildren) is 0 then
display dialog "Please select a Timeline group with an audio or video cue at the top." with icon 2
return
else
set sliceCue to item 1 of groupChildren
if q type of sliceCue is not in {"Audio", "Video"} then
display dialog "Please select a Timeline group with an audio or video cue at the top." with icon 2
return
end if
end if --if the group has children
end if --if the selected cue is an audio, video or group cue
if the mode of groupCue is not timeline then
display dialog "This script is only for groups in Timeline mode." with icon 2
return
end if

--makes a list omitting the cues in the list that aren't the cueTypeToSnap, and that aren't armed
set groupChildren to cues of item 1 of groupCue
set cuesToSnap to {}
repeat with eachCue in groupChildren
if q type of eachCue is cueTypeToSnap and the armed of eachCue is true then
copy eachCue to the end of cuesToSnap
end if
end repeat

--makes a list omitting the slices that are in the cue but before the start time of the cue
set mySlices to {}
set allSlices to slice markers of sliceCue
repeat with eachSlice in allSlices
if time of eachSlice is greater than start time of sliceCue then
copy eachSlice to the end of mySlices
end if
end repeat

--Make choose from list menus. Different prompts depending on the selected cue
if cueType is "Group" then
set userChoice to choose from list {"Just the slice markers", "Start of timeline and slice markers", "End of timeline and slice markers", "Start and end of timeline, and slice markers"} with title ("Snap " & cueTypeToSnap & " Cues to Slice Markers") with prompt ("This script will use the slices in the first audio/video cue in the group. Snap " & cueTypeToSnap & " cues to:")
else
set userChoice to choose from list {"Just the slice markers", "Start of timeline and slice markers", "End of timeline and slice markers", "Start and end of timeline, and slice markers"} with title ("Snap " & cueTypeToSnap & " Cues to Slice Markers") with prompt ("This script will use the slices in the selected audio/video cue. Snap " & cueTypeToSnap & " cues to:")
end if --if the cueType is Group or Audio/Video

--add slice markers for beginning or end depending on menu selection
if userChoice contains "Start of timeline and slice markers" then
set beginning of mySlices to {time:start time of sliceCue, playCount:1}
else if userChoice contains "End of timeline and slice markers" then
set end of mySlices to {time:end time of sliceCue, playCount:1}
else if userChoice contains "Start and end of timeline, and slice markers" then
set beginning of mySlices to {time:start time of sliceCue, playCount:1}
set end of mySlices to {time:end time of sliceCue, playCount:1}
end if --choose from list options


--set the repeat limit to the lower quantity, either slice markers or cues to snap
if (count of mySlices) is greater than (count of cuesToSnap) then
set snapLimit to count of cuesToSnap
else
set snapLimit to count of mySlices
end if
set sliceCount to 0

--Snap all the cues to slice markers
repeat with cueCount from 1 to snapLimit
set sliceCount to (sliceCount + 1)
set theSlice to item sliceCount of mySlices
set theTime to (time of theSlice) - ((start time of sliceCue) - (pre wait of sliceCue)) --this will account for start time or pre wait time
set the pre wait of (item cueCount of cuesToSnap) to theTime
end repeat

--report missing cues or slice markers
set leftoverCues to (count of cuesToSnap) - (count of mySlices)
if leftoverCues is greater than 1 then
display dialog ("" & leftoverCues & " cues were left without a time to snap them to.") with icon 1
else if leftoverCues is 1 then
display dialog ("1 cue was left without a time to snap to.") with icon 1
else if leftoverCues is -1 then
display dialog ("You have 1 less " & cueTypeToSnap & " cue than slice markers.") with icon 1
else if leftoverCues is less than -1 then
display dialog ("You have " & -(leftoverCues) & " less " & cueTypeToSnap & " cues than slice markers.") with icon 1
end if -- leftoverCue options


end if --if the selected cue is a group cue, audio cue, or video cue
end tell



35 views0 comments

Recent Posts

See All
bottom of page