Search
  • Taylor Glad

Auto-Matrix Audio

Explanation

This script lets you set specify a matrix of audio patches, and key strings in the filenames of your audio stems that you want to be assigned.

For example, if you have files like:

NeverGonnaGiveYouUp_base.wav

NeverGonnaGiveYouUp_sweetener.wav

NeverGonnaGiveYouUp_click.wav

Then you can open up the script, and edit the matrix to fit your needs. Then select any quantity of audio cues (or video cues) and run the script.



Script

Copy the text to the right, 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.



--This script auto-assigns channel matrix assignments based off of file names. Any cues that cannot be sorted will be flagged, and a dialog will inform you how many there were.
--Supports mono or stereo files
--Supports up to 16 outputs -> it just won't clear the matrix more than that. Not an issue, and easy to adjust add more to the script
--Taylor Glad



set theAudioMatrix to {}
--Making letters variables so you don't need as many quotation marks when filling out the matrix
set L to "L"
set R to "R"
set M to "M"


--*******SCROLL DOWN TO BOTTOM TO DEFINE DEFAULT MATRIX FOR VALID AUDIO FILES WITH NO MATCHING STRINGS IN THE MATRIX*******


---HOW TO COMPLETE THE MATRIX---
--output #
--string options inside curly brackets: {} with each option inside quotations, and commas between each option. (Not case sensitive)
--"L","R", or "M". (L or R for Left or Right if it is a stereo output, or M for mono output.) (Your stereo pairs do not neeeed to be in order...)
--the matrix is NOT CASE SENSITIVE

--IF YOU GET ANY ERRORS, there's a 99.999% chance you left out quotation marks somewhere in the matrix below

--BE WISE IN YOUR STRINGS/ABBREVIATIONS. If your song is "Sweet Caroline" then maybe make sure your string for sweetener uses underscores; "_sweet"

--{1,{"stringOption1","stringOption2"},"L"} --Output Label (optional, for your convenience only)

---------COMPLETE THE MATRIX---------

set the end of theAudioMatrix to {1, {"_base"}, L} --Track L
set the end of theAudioMatrix to {2, {"_base"}, R} --Track R
set the end of theAudioMatrix to {3, {"Sing", "_SWT"}, L} --Sweetener L
set the end of theAudioMatrix to {4, {"Sing", "_SWT"}, R} --Sweetener R
set the end of theAudioMatrix to {5, {"_clk"}, M} --Click

---------------------------------------------
(* 16 Channel Example
set the end of theAudioMatrix to {1, {"_CLK", "Click"}, M} --Click
set the end of theAudioMatrix to {2, {"_Cues"}, M} --Cues
set the end of theAudioMatrix to {3, {"_ACGTR"}, L} --Acoustic Guitar L
set the end of theAudioMatrix to {4, {"_ACGTR"}, R} --Acoustic Guitar R
set the end of theAudioMatrix to {5, {"_BGV"}, L} --Background Vocals L
set the end of theAudioMatrix to {6, {"_BGV"}, R} --Background Vocals R
set the end of theAudioMatrix to {7, {"_BSS", "Bass"}, L} --Bass L
set the end of theAudioMatrix to {8, {"_BSS", "Bass"}, R} --Bass R
set the end of theAudioMatrix to {9, {"_DRMS", "Drums"}, L} --Drums L
set the end of theAudioMatrix to {10, {"_DRMS", "Drums"}, R} --Drums R
set the end of theAudioMatrix to {11, {"_ELGTR"}, L} --Electric Guitar L
set the end of theAudioMatrix to {12, {"_ELGTR"}, R} --Electric Guitar R
set the end of theAudioMatrix to {13, {"_KYS", "Keys"}, L} --Keys L
set the end of theAudioMatrix to {14, {"_KYS", "Keys"}, R} --Keys R
set the end of theAudioMatrix to {15, {"_PRC", "Perc"}, L} --Percussion L
set the end of theAudioMatrix to {16, {"_PRC", "Perc"}, R} --Percussion R
*)

(* 5 Channel Example
set the end of theAudioMatrix to {1, {"_Base"}, L} --Track L
set the end of theAudioMatrix to {2, {"_Base"}, R} --Track R
set the end of theAudioMatrix to {3, {"Sweet", "_SWT"}, M} --Sweetener L
set the end of theAudioMatrix to {4, {"Sweet", "_SWT"}, L} --Sweetener R
set the end of theAudioMatrix to {5, {"Click", "_CLK"}, R} --Click
*)


--make theAudioMatrix all lowercase, so it is not case sensitive
set theComparisonCharacters to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set theSourceCharacters to "abcdefghijklmnopqrstuvwxyz"
set theAlteredText to ""
set rowCount to 1
repeat with eachRow in theAudioMatrix
	set itemCount to 1
	repeat with eachItem in item 2 of eachRow
		repeat with aCharacter in eachItem
			set theoffset to offset of aCharacter in theComparisonCharacters
			if theoffset is not 0 then
				set theAlteredText to (theAlteredText & character theoffset of theSourceCharacters) as string
			else
				set theAlteredText to (theAlteredText & aCharacter) as string
			end if
		end repeat
		set item itemCount of item 2 of item rowCount of theAudioMatrix to theAlteredText
		set theAlteredText to ""
		set itemCount to itemCount + 1
	end repeat
	set rowCount to rowCount + 1
end repeat


set cueErrors to 0
tell application id "com.figure53.QLab.4" to tell front workspace
	
	set selectedCues to selected as list
	repeat with eachCue in selectedCues
		
		if (the q type of eachCue is "Video") or (the q type of eachCue is "Audio") then
			
			if the audio input channels of eachCue is greater than 2 then --skips this audio cue if it has more than 2 channels
				set the flagged of eachCue to 1
				set cueErrors to (cueErrors + 1)
			else
				
				set notEmptyCue to true
				set theCueName to the q default name of eachCue
				try
					item 1 of theCueName
				on error
					set the flagged of eachCue to 1
					set cueErrors to (cueErrors + 1)
					set notEmptyCue to false
				end try
				
				if notEmptyCue then
					
					--make theCueName all lowercase, so it is not case sensitive
					set theComparisonCharacters to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
					set theSourceCharacters to "abcdefghijklmnopqrstuvwxyz"
					set theAlteredText to ""
					repeat with aCharacter in theCueName
						set theoffset to offset of aCharacter in theComparisonCharacters
						if theoffset is not 0 then
							set theAlteredText to (theAlteredText & character theoffset of theSourceCharacters) as string
						else
							set theAlteredText to (theAlteredText & aCharacter) as string
						end if
					end repeat
					set theCueName to theAlteredText
					
					
					--clear default values --add more if this isn't enough for you
					setLevel eachCue row 1 column 1 db -100
					setLevel eachCue row 1 column 2 db -100
					setLevel eachCue row 1 column 3 db -100
					setLevel eachCue row 1 column 4 db -100
					setLevel eachCue row 1 column 5 db -100
					setLevel eachCue row 1 column 6 db -100
					setLevel eachCue row 1 column 7 db -100
					setLevel eachCue row 1 column 8 db -100
					setLevel eachCue row 1 column 9 db -100
					setLevel eachCue row 1 column 10 db -100
					setLevel eachCue row 1 column 11 db -100
					setLevel eachCue row 1 column 12 db -100
					setLevel eachCue row 1 column 13 db -100
					setLevel eachCue row 1 column 14 db -100
					setLevel eachCue row 1 column 15 db -100
					setLevel eachCue row 1 column 16 db -100
					setLevel eachCue row 2 column 1 db -100
					setLevel eachCue row 2 column 2 db -100
					setLevel eachCue row 2 column 3 db -100
					setLevel eachCue row 2 column 4 db -100
					setLevel eachCue row 2 column 5 db -100
					setLevel eachCue row 2 column 6 db -100
					setLevel eachCue row 2 column 7 db -100
					setLevel eachCue row 2 column 8 db -100
					setLevel eachCue row 2 column 9 db -100
					setLevel eachCue row 2 column 10 db -100
					setLevel eachCue row 2 column 11 db -100
					setLevel eachCue row 2 column 12 db -100
					setLevel eachCue row 2 column 13 db -100
					setLevel eachCue row 2 column 14 db -100
					setLevel eachCue row 2 column 15 db -100
					setLevel eachCue row 2 column 16 db -100
					
					
					set matchFound to false
					repeat with eachRow in theAudioMatrix
						repeat with eachString in item 2 of eachRow
							
							
							if the theCueName contains eachString then
								if item 3 of eachRow is "L" then
									
									if the audio input channels of eachCue is 1 then --Mono audio file
										setLevel eachCue row 1 column (item 1 of eachRow) db 0
									else --Stereo audio file
										setLevel eachCue row 1 column (item 1 of eachRow) db 0
									end if --
									
								else if item 3 of eachRow is "R" then
									
									if the audio input channels of eachCue is 1 then --Mono audio file
										setLevel eachCue row 1 column (item 1 of eachRow) db 0
									else --Stereo audio file
										setLevel eachCue row 2 column (item 1 of eachRow) db 0
									end if --
									
								else --if item 3 of eachRow is "M" or anything else then
									
									if the audio input channels of eachCue is 1 then --Mono audio file
										setLevel eachCue row 1 column (item 1 of eachRow) db 0
									else --Stereo audio file
										setLevel eachCue row 1 column (item 1 of eachRow) db -3
										setLevel eachCue row 2 column (item 1 of eachRow) db -3
									end if --
									
								end if --if item 3 is L, R, or M (If the cue output is Stereo or Mono)
								
								set matchFound to true
								exit repeat --exits the loop since a match was found
							end if --theCueName contains eachString
						end repeat --each string in eachRow
					end repeat --eachRow in theAudioMatrix
					
					if matchFound is false then
						set the flagged of eachCue to 1
						set cueErrors to (cueErrors + 1)
						
						--*******DEFINE DEFAULT MATRIX FOR VALID AUDIO FILES WITH NO MATCHING STRINGS IN THE MATRIX*******
						if the audio input channels of eachCue is 1 then --Mono audio file
							setLevel eachCue row 1 column 1 db 0
							setLevel eachCue row 1 column 2 db 0
						else --Stereo audio file
							setLevel eachCue row 1 column 1 db 0
							setLevel eachCue row 2 column 2 db 0
						end if --mono vs stereo file
					end if --if no match is found
					
				end if --notEmptyCue (cue's default name won't produce an error)
			end if --the cue doesn't have more than 2 channels
		end if --if the cue is an audio cue or video cue
	end repeat --eachCue
	if cueErrors = 1 then
		display dialog "1 track could not be auto-matrixed" with title "Auto-Matrix Erros" with icon 2
	else if cueErrors > 1 then
		display dialog (cueErrors as string) & " tracks could not be auto-matrixed" with title "Auto-Matrix Erros" with icon 2
	end if
end tell

24 views0 comments

Recent Posts

See All