--make a MIDI cue with a prewait based on the cursor position.
tell application id "com.figure53.QLab.5" to tell front workspace
set theCue to last item of (selected as list)
set theOffset to pre wait of theCue
set theTime to (action elapsed of theCue) + theOffset
make type "midi" --assumes MSC cue is set up in cue template
set theMidiCue to last item of (selected as list)
set the pre wait of theMidiCue to theTime
set the selected to theCue
end tell
tell application id "com.figure53.QLab.5" to tell front workspace
set theCues to (selected as list)
set thearray to {} as list
repeat with eachcue in theCues
set end of thearray to {idid:uniqueID of eachcue, prewait:pre wait of eachcue}
end repeat
end tell
qsort(thearray, 1, ((number of items of thearray)))
set thecounter to 1
tell application id "com.figure53.QLab.5" to tell front workspace
make type "group"
set theGroup to last item of (selected as list)
set the q name of theGroup to (q list name of first cue of theGroup & " with MSC cues")
repeat ((number of items of thearray)) times
set thesortcue to (first cue of theGroup whose uniqueID is (idid of item thecounter of thearray))
move thesortcue to end of theGroup
set thecounter to thecounter + 1
end repeat
set the q name of theGroup to (q name of first cue of theGroup & "with MSC cues")
end tell
on qsort(array, l, r)
set i to l
set j to r
set v to item ((l + r) div 2) of array -- pivot
repeat while (j > i)
repeat while (prewait of item i of array < prewait of v)
set i to i + 1
end repeat
repeat while (prewait of item j of array > prewait of v)
set j to j - 1
end repeat
if (not i > j) then
tell array to set {item i, item j} to {item j, item i} -- swap
set i to i + 1
set j to j - 1
end if
end repeat
if (l < j) then qsort(array, l, j)
if (r > i) then qsort(array, i, r)
end qsort