Sorting Cue Lists by Cue Names

475 views
Skip to first unread message

micpool

unread,
Nov 1, 2019, 6:07:44 PM11/1/19
to QLab
I generally like to have a cue list containing a directory of all my cues for a project  in alphabetical order (with all the cinemas having a prefix in CAPITALS showing the group of sounds they belong to  e.g RAIN on concrete, RAIN splatty,  THUNDER boom  short,  THUNDER rolling long,   etc.

After importing the first batch of cues  into a list named Audition or similar, I have generally then maintained the alphabetical order of the cues in these lists manually, as I have felt that the presence of a sort script in a QLab workspace is potentially catastrophic.

It's just occurred to me that it's possible to just include a character sequence into the cue list names of  lists that you  might want to sort alphabetically after adding fresh material to indicate the sort script is allowed to act on them,  so I thought I'd try and develop a sort script.

tell application id "com.figure53.QLab.4" to tell front workspace

if the q list name of current cue list does not contain "###" then return -- guards against applying a sort to a show cue list

set thecues to cues of current cue list as list

set thearray to {} as list

repeat with eachcue in thecues

set end of thearray to {idid:uniqueID of eachcue, qname:q list name of eachcue}

end repeat

end tell


sortlist(thearray)



set thecounter to 1


tell application id "com.figure53.QLab.4" to tell front workspace

repeat ((number of items of thearray)) times

set thesortcue to (first cue of current cue list whose uniqueID is (idid of item thecounter of thearray))

move cue id (uniqueID of thesortcue) of parent of thesortcue to end of parent of thesortcue

set thecounter to thecounter + 1

end repeat

end tell


on sortlist(mylist)

repeat with i from 1 to (count of mylist)

repeat with j from i + 1 to count of mylist

if qname of item j of mylist < qname of item i of mylist then

set temp to item i of mylist

set item i of mylist to item j of mylist

set item j of mylist to temp

end if

end repeat

end repeat

end sortlist



Unfortunately although it will rip through sorting 10 cues, on large cue lists e.g 1000, this is so slow as to be unusable, any suggestions for improvements to the sorting algorithms or any 'a reference to ' tricks??


Mic






Bruno Carneiro da Cunha

unread,
Nov 1, 2019, 9:06:36 PM11/1/19
to QLab
Hey mic, nice script!

I just plugged in a quicksort implementation into your script. It looks like this now:

tell application id "com.figure53.QLab.4" to tell front workspace
   
if the q list name of current cue list does not contain "###" then return -- guards against applying a sort to a show cue list
   
set thecues to cues of current cue list as list
   
set thearray to {} as list
    repeat
with eachcue in thecues
       
set end of thearray to {idid:uniqueID of eachcue, qname:q list name of eachcue}
   
end repeat
end
tell

qsort
(thearray, 1, ((number of items of thearray)))


set thecounter to 1
tell application id
"com.figure53.QLab.4" to tell front workspace
    repeat
((number of items of thearray)) times
       
set thesortcue to (first cue of current cue list whose uniqueID is (idid of item thecounter of thearray))
        move cue id
(uniqueID of thesortcue) of parent of thesortcue to end of parent of thesortcue
       
set thecounter to thecounter + 1
   
end repeat
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 (qname of item i of array < qname of v)
           
set i to i + 1
       
end repeat
        repeat
while (qname of item j of array > qname 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

On my MacBook Air, I sorted a 500-cue list in 18 seconds. Before it would take 45 seconds. Is this fast enough?

Bruno

micpool

unread,
Nov 2, 2019, 5:58:00 AM11/2/19
to QLab
Thanks Bruno, that makes the whole thing feasible. It makes around a minute for 1000 cues on my system.

Mic

Artur Arturov

unread,
Mar 31, 2024, 8:43:49 AM3/31/24
to QLab
Hi,Bruno!
Help me please. How do I make the script sort the list in a group cue? 

суббота, 2 ноября 2019 г. в 04:06:36 UTC+3, Bruno Carneiro da Cunha:

micpool

unread,
Mar 31, 2024, 11:40:50 AM3/31/24
to QLab

This is a potentially dangerous script as it is not undoable. Undoing a sort will delete the sorted cues (one by one!).  Because of this, I have retained the sort authorisation string "###."  Your group's name must include this string. For QLab 4 change all QLab.5 references to QLab.4




tell application id "com.figure53.QLab.5" to tell front workspace

set theGroup to last item of (selected as list)

if q type of theGroup is not "group" then

display alert "Selected cue is not a group cue "

return

end if

if the q list name of theGroup does not contain "###" then -- guards against applying a sort to a show cue list

display alert "Selected Group is not authorised for sorting"

return

end if

display dialog "This sort is not undoable! Proceed?"

set thecues to cues of theGroup as list

set thearray to {} as list

repeat with eachcue in thecues

set end of thearray to {idid:uniqueID of eachcue, qname:q list name 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

repeat ((number of items of thearray)) times

set thesortcue to (first cue of theGroup whose uniqueID is (idid of item thecounter of thearray))

move cue id (uniqueID of thesortcue) of parent of thesortcue to end of parent of thesortcue

set thecounter to thecounter + 1

end repeat

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 (qname of item i of array < qname of v)

set i to i + 1

end repeat

repeat while (qname of item j of array > qname 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



Mic
sort group.mov
Reply all
Reply to author
Forward
0 new messages