set setlevelcue to "1" --cue to set master level of
tell application id "com.figure53.QLab.4" to tell front workspace
set thevalues to notes of cue "SPL" as text
set olddelimiter to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set thecount to (count of text items of thevalues) - 1
set theaccumulator to 0.0
repeat with n from 1 to thecount
set theaccumulator to theaccumulator + (text item n of thevalues as number)
end repeat
set theaccumulator to theaccumulator / thecount
set thelog to my log10(theaccumulator)
set thedecibel to 20 * (thelog)
set the notes of cue "REC" to thedecibel
set notes of cue "CALC" to thecount
--insert any extra maths to modify level setting (min. max etc) here
cue setlevelcue setLevel row 0 column 0 db thedecibel
set AppleScript's text item delimiters to olddelimiter
end tell
on log10(thenumber)
set natural_log to (do shell script ("echo 'l(" & (thenumber as string) & ")' | bc -l")) as real
set natural_log_of_10 to (do shell script ("echo 'l(10)' | bc -l")) as real
set common_log to natural_log / natural_log_of_10
return common_log
end log10
set theccumulator to (do shell script "echo " & notes of cue "SPL" & " | awk '{s+=$1}END{print s/NR}' RS=\" \" ")
set thedecibel to (do shell script "echo " & notes of cue "SPL" & " | awk '{s+=$1}END{print 20*log(s/NR)/log(10)}' RS=\" \" ")
set thedecibel to (do shell script "echo " & notes of cue "SPL" & " | awk '{s+=$1}END{print 20*log(s/(NR-1))/log(10)}' RS=\":\" ")
On 6 Dec 2017, at 14:39, micpool <m...@micpool.com> wrote:Thanks RichI think I’m going to write this up on The Cook Book as a project to do gap ambient level control on a preshow sequence with music and announcements as I can do a workspace which replays audience chatter recordings so that it can be used for testing and experiment before trying it with a live audience.I’ll present the program the long winded way first, as I like any code on the Cook Book to be readily understandable and adaptable by people with rudimentary programming ability.
However, these awk methods are so brilliant and, in the simple example we have to resort to UNIX stuff to do some of the maths anyway. Its a good project to present this level of optimised coding, and that could be part 2 of the tutorial.If I may, I’ll send you a draft when it’s done If you were able to do a short commentary or annotation on the awk stuff that would be brilliant.
One question about delimiters. How long to they persist when set? I’ve read you can’t assume what they are set to and it’s good practice to set them back where they were, but does that still apply in the QLab script context? Can a script cue assume they are set to space so you can use words of ?
If you change thetext item delimitersproperty in Script Editor, it remains changed until you restore its previous value or until you quit Script Editor and launch it again. If you changetext item delimitersin a script application, it remains changed in that application until you restore its previous value or until the script application quits; however, the delimiters are not changed in Script Editor or in other script applications you run.
A continuous series of characters, with word elements parsed according to the word-break rules set in the International preference pane.