level-playing-field

160 views
Skip to first unread message

Florian B.

unread,
May 12, 2023, 5:24:54 AM5/12/23
to QLab
Hi there,
i've tried around a little bit with the level-playing-field script. I want to share my version with you. All the Parsing of the output of r128x-cli ist done in shell, so the actual AppleScript ist a little bit more straight forward.
Best,
Florian


set theReferenceLevel to -24 --set desired LUFS level

set thefaderLevel to -10 --set the master fader level to your preferred output level for cues with an LUFS at the reference level

set cliPath to "/usr/local/bin/r128x-cli" -- set the path of r128x-cli


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

display dialog "WARNING: This will change the master levels of all selected cues" & return & return & "A dialog will signal when the level setting is complete." & return & return & "PROCEED?"

try

set theselected to the selected as list

if (count of items of theselected) > 0 then

repeat with eachcue in theselected

if q type of eachcue is "audio" then

set currentFileTarget to quoted form of POSIX path of (file target of eachcue as alias)

set theLUFS to (do shell script "echo $( " & (cliPath as string) & " " & (currentFileTarget as string) & " | tail -n1 | awk '{print $(NF-2)}' | sed 's/\\./,/g' )") as real

set theadjustment to (theReferenceLevel - theLUFS) + thefaderLevel

-- set the notes of eachcue to "LUFS: " & theLUFS & ", Adjustment: " & theadjustment

eachcue setLevel row 0 column 0 db theadjustment

end if

end repeat

display dialog "Level Setting Complete." buttons "OK" default button "OK"

end if

end try

end tell


micpool

unread,
May 12, 2023, 7:19:40 AM5/12/23
to QLab
Very good, and a much neater programming solution! 

I think that it's also probably true to say

set theLUFS to (do shell script "echo $( " & (cliPath as string) & " " & (currentFileTarget as string) & " | tail -n1 | awk '{print $(NF-2)}' | sed 's/\\./,/g' )") as real

is 10 times shorter than the original version, but the How it works section in the   CookBook chapter would probably need to be 10 times longer, to introduce awk pattern scanning and processing and sed stream editing, to its intended readership!

Mic

micpool

unread,
May 12, 2023, 9:12:16 AM5/12/23
to QLab
Two other small points

Florian's  script doesn't work for UK and US users or anyone else that uses . a decimal point rather than a comma for decimal values. I can see where sed might be doing the substitution but don't know the syntax to fix it.

The CookBook Chapter has a note that the cli tool  r128x won't run on M1 Macs, which is not the case. (I've just tested the original script on an M1 and it works perfectly)
There are security hurdles with cli's on  the OS's that run on M1 Macs but this procedure should allow you to install  r128x (tested up to Monterey on M1)
After installing r128x-cli in /usr/local/bin, as currently described in the CookBook, right click on it and open in terminal. Reply to another warning dialog, checking that you really want to open it by clicking Open. When it runs in the terminal window, close terminal. It will then open from the QLab shell script without further problems. 

Mic


micpool

unread,
May 12, 2023, 9:17:21 AM5/12/23
to QLab
Actually all the sed was doing was converting decimal point to decimal comma so decimal point users can just delete it. The shell script then becomes:

set theLUFS to (do shell script "echo $( " & (cliPath as string) & " " & (currentFileTarget as string) & " | tail -n1 | awk '{print $(NF-2)}' )") as real

Florian B.

unread,
May 13, 2023, 4:08:34 AM5/13/23
to QLab
Hi Mic,

thanks for your hints. Could you try this:

set theLUFS to (do shell script "echo $( " & (cliPath as string) & " " & (currentFileTarget as string) & " | tail -n1 | awk '{print $(NF-2)}' | sed 's/\\./" & character 2 of ((1 / 2) as text) & "/g' )") as real


This works fine on my german Mac, as it sets the decimal separator with a little more coding.

Some more instructions on the Shell script:

The whole query is made in a subshell $(). echo returns the result of that subshell. This ensures that only a single output is made to Qlab at the end.
The first part of the subshell calls r128x-cli with the file to be normalized. 
Pipe hands over the result to the next command: tail -n1 "selects" the last line.
Pipe to the next command: awk "selects" the third last word.
Pipe again: sed exchanges the decimal separator. This is necessary on the German Mac.

The new part character 2 of ((1 / 2) as text) sets the decimal separator within the sed command, as it does simple math to get 0.5, converts it to text and selects the 2nd character.

Florian
Reply all
Reply to author
Forward
0 new messages