Fan-Chase-Generator Script

LXConsole support and feedback
Post Reply
freadZdead
Posts: 211
Joined: Sat Jun 01, 2013 8:23 am
Location: Adelaide, Australia

Fan-Chase-Generator Script

Post by freadZdead »

Hi all,

Available due to recent improvements in LXConsole from build 3.3.11 (7328A):

A smooth Fan-Chase-Generator, that creates smooth fans and fan chases over the selected channels in the order of their selection. Great to do things like "pixel" walls of blinders etc, and one can easily imagine to extend it to a script that works on other subchannels than just intensity, so feel free to adapt to your liking - enjoy :D!

Code: Select all

-- FAN-CHASE-GENERATOR V1
-- Select 2 or more channels (usually, an odd number looks nicer) in the order that you would like the fan to be applied,
-- and exectute script to create smooth static fans and chases 
set tid to AppleScript's text item delimiters
try
	tell application "LXConsole"
		if ((currentCommand of the front document) as text) is "" then
			set theCommand to (lastCommand of the front document) as text
		else
			set theCommand to (currentCommand of the front document) as text
			set AppleScript's text item delimiters to "@"
			set dummyList to text items of theCommand
			set theCommand to (item 1 of dummyList) as text
			set AppleScript's text item delimiters to ";"
		end if
		set curChan to ""
		set curMode to "and"
		set startChan to ""
		set endChan to ""
		set numbs to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
		set legals to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "&", "-", ">"}
		set selectedChannels to {}
		repeat with thisCharacter in the characters of theCommand
			set thisCharacter to thisCharacter as text
			if thisCharacter is not in legals then
				error number 666
			else
				--				display dialog "thisCharacter: " & thisCharacter & (ASCII character 10) & (ASCII character 13) & "curChan: " & (curChan as text) & (ASCII character 10) & (ASCII character 13) & "curMode: " & curMode & (ASCII character 10) & (ASCII character 13) & "startChan: " & (startChan as text) & (ASCII character 10) & (ASCII character 13) & "endChan: " & (endChan as text) & (ASCII character 10) & (ASCII character 13) & "changer: " & (changer as text) & (ASCII character 10) & (ASCII character 13) & "selectedChannels: " & (selectedChannels as text)
				if thisCharacter is in numbs then
					set curChan to curChan & thisCharacter
				else
					if thisCharacter is ">" then
						set curMode to "thru"
						set startChan to (curChan as number)
						set curChan to ""
					else if thisCharacter is "&" then
						if curMode is "thru" then
							set endChan to (curChan as number)
							set dummyList to my addSeq(startChan, endChan, selectedChannels)
							set selectedChannels to ""
							set selectedChannels to {}
							set selectedChannels to dummyList
							set startChan to ""
							set endChan to ""
						else if curMode is "and" then
							set the end of selectedChannels to (curChan as number)
						else if curMode is "not" then
							set dummyList to my deductChannel((curChan as number), selectedChannels)
							set selectedChannels to ""
							set selectedChannels to {}
							set selectedChannels to dummyList
						end if
						set curChan to ""
						set curMode to "and"
					else if thisCharacter is "-" then
						if curMode is "thru" then
							set endChan to (curChan as number)
							set dummyList to my addSeq(startChan, endChan, selectedChannels)
							set selectedChannels to ""
							set selectedChannels to {}
							set selectedChannels to dummyList
							set startChan to ""
							set endChan to ""
						else if curMode is "and" then
							set the end of selectedChannels to (curChan as number)
						else if curMode is "not" then
							set dummyList to my deductChannel((curChan as number), selectedChannels)
							set selectedChannels to ""
							set selectedChannels to {}
							set selectedChannels to dummyList
						end if
						set curChan to ""
						set curMode to "not"
					end if
				end if
			end if
		end repeat
		if curMode is "thru" then
			set endChan to (curChan as number)
			set dummyList to my addSeq(startChan, endChan, selectedChannels)
			set selectedChannels to ""
			set selectedChannels to {}
			set selectedChannels to dummyList
			set startChan to ""
			set endChan to ""
		else if curMode is "and" then
			set the end of selectedChannels to (curChan as number)
		else if curMode is "not" then
			set dummyList to my deductChannel((curChan as number), selectedChannels)
			set selectedChannels to ""
			set selectedChannels to {}
			set selectedChannels to dummyList
		end if
		set curChan to ""
		set numSelChans to count selectedChannels
		if numSelChans is less than 2 then
			display dialog "Please select at least two channels"
		else
			set chosenShape to choose from list {"cos", "half cos", "sin", "half sin"} ¬
				with title ¬
				"Fan-Chase-Generator" with prompt "You have selected the following " & numSelChans & " Channels to operate on: " & (selectedChannels as text) & (ASCII character 10) & (ASCII character 10) & ¬
				"Please select Fan shape:" & (ASCII character 10) & (ASCII character 10) ¬
				default items ¬
				"cos" OK button name ¬
				"Next" cancel button name ¬
				"Abort" without multiple selections allowed
			set chosenShape to (chosenShape as text)
			set chosenMode to choose from list {"static Fan in live", "static Fan into cue", "Fan Chase into cue sequence"} ¬
				with title ¬
				"Fan-Chase-Generator" with prompt ¬
				"What kind of action would you like to perform?" default items ¬
				"Fan Chase into cue sequence" OK button name ¬
				"Next" cancel button name ¬
				"Abort" without multiple selections allowed
			set chosenMode to (chosenMode as text)
			if chosenMode is not "static Fan in live" then
				set tmp to display dialog "Please enter the (first) cue number to record" default answer "901"
				set cueNo to the text returned of tmp
			end if
			set temp to display dialog "Please enter min and max intensity separated by a comma (each 0..100)" default answer "0,100"
			set text_user_entered to the text returned of temp
			set AppleScript's text item delimiters to {","}
			set minVal to ((the first text item of text_user_entered) as number)
			set maxVal to ((the second text item of text_user_entered) as number)
			set AppleScript's text item delimiters to ";"
			if chosenMode is not "Fan Chase into cue sequence" then
				my setStepInLive(1, 1, chosenShape, numSelChans, selectedChannels, minVal, maxVal)
			else
				set cueNo to (cueNo as number)
				set chosenRes to choose from list {"1x (amount steps = amount fixtures)", "2x (amount steps = 2x amount fixtures)", "3x (amount steps = 3x amount fixtures)", "4x (amount steps = 4x amount fixtures)"} ¬
					with title ¬
					"Fan-Chase-Generator" with prompt ¬
					"How fine should the step resolution be?" default items ¬
					"1x (amount steps = amount fixtures)" OK button name ¬
					"Next" cancel button name ¬
					"Abort" without multiple selections allowed
				set chosenRes to (chosenRes as text)
				if chosenRes is "1x (amount steps = amount fixtures)" then
					set stepMultiplier to 1
				else if chosenRes is "2x (amount steps = 2x amount fixtures)" then
					set stepMultiplier to 2
				else if chosenRes is "3x (amount steps = 3x amount fixtures)" then
					set stepMultiplier to 3
				else if chosenRes is "4x (amount steps = 4x amount fixtures)" then
					set stepMultiplier to 4
				end if
				set stepNo to 1
				set ofSteps to (stepMultiplier * (numSelChans - 1))
				repeat while stepNo ≤ ofSteps
					my setStepInLive(stepNo, stepMultiplier, chosenShape, numSelChans, selectedChannels, minVal, maxVal)
					set theDoCommand to "record: " & (cueNo as text)
					my execLXC(theDoCommand)
					set cueNo to cueNo + 1
					set stepNo to stepNo + 1
				end repeat
			end if
			if chosenMode is "static Fan into cue" then
				set theDoCommand to "record: " & (cueNo as text)
				my execLXC(theDoCommand)
			end if
		end if
	end tell
on error errMsg number errorNumber
	if the errorNumber is equal to 666 then
		display dialog "Oops, somewhat illegal character in channel selection… I can't understand: " & thisCharacter
	else
		display dialog ("An unknown error occurred:  " & errorNumber as text) & errMsg
	end if
	set AppleScript's text item delimiters to tid
end try

on addSeq(startChan, endChan, theList)
	if (endChan > startChan) then
		set changer to 1
	else if &#40;endChan < startChan&#41; then
		set changer to -1
	else
		set changer to 0
	end if
	set regChan to startChan
	repeat
		set the end of theList to regChan
		if changer is 0 then
			exit repeat
		else
			set regChan to &#40;regChan + changer&#41;
			if &#40;regChan &#8804; 0&#41; then
				exit repeat
			end if
			if regChan is endChan then
				set changer to 0
			end if
		end if
	end repeat
	return theList
end addSeq

on deductChannel&#40;theChannel, theList&#41;
	set theNewList to &#123;&#125;
	repeat with i from 1 to count theList
		if &#40;&#123;theList's item i&#125; as number&#41; is not &#40;theChannel as number&#41; then set the end of theNewList to &#40;&#123;theList's item i&#125; as number&#41;
	end repeat
	return theNewList
end deductChannel

on setStepInLive&#40;stepNo, stepMultiplier, chosenShape, numSelChans, selectedChannels, minVal, maxVal&#41;
	set i to &#40;stepNo - 1&#41; / stepMultiplier -- / ofSteps
	--set i to 0
	repeat with selChan in selectedChannels
		if chosenShape is "cos" then
			set y to &#40;&#40;&#40;&#40;my cosine_of&#40;&#40;i * pi&#41; / &#40;&#40;numSelChans - 1&#41; / 2&#41;&#41;&#41; + 1&#41; / 2&#41; * &#40;maxVal - minVal&#41;&#41; + minVal
		else if chosenShape is "half cos" then
			set y to &#40;&#40;&#40;&#40;my cosine_of&#40;&#40;i * pi&#41; / &#40;numSelChans - 1&#41;&#41;&#41; + 1&#41; / 2&#41; * &#40;maxVal - minVal&#41;&#41; + minVal
		else if chosenShape is "sin" then
			set y to &#40;&#40;&#40;&#40;my sine_of&#40;&#40;&#40;i - &#40;&#40;numSelChans - 1&#41; / 4&#41;&#41; * pi&#41; / &#40;&#40;numSelChans - 1&#41; / 2&#41;&#41;&#41; + 1&#41; / 2&#41; * &#40;maxVal - minVal&#41;&#41; + minVal
		else if chosenShape is "half sin" then
			set y to &#40;&#40;&#40;&#40;my sine_of&#40;&#40;&#40;i - &#40;&#40;numSelChans - 1&#41; / 2&#41;&#41; * pi&#41; / &#40;numSelChans - 1&#41;&#41;&#41; + 1&#41; / 2&#41; * &#40;maxVal - minVal&#41;&#41; + minVal
		end if
		set theDoCommand to &#40;selChan as text&#41; & "@" & &#40;my twoDigits&#40;y&#41; as text&#41;
		my execLXC&#40;theDoCommand&#41;
		set i to i + 1
		if i > &#40;numSelChans - 1&#41; then
			set i to i - &#40;numSelChans - 1&#41;
		end if
	end repeat
end setStepInLive

on twoDigits&#40;intensity&#41;
	if intensity < 10 then
		return "0" & &#40;intensity as text&#41;
	else
		return &#40;intensity as text&#41;
	end if
end twoDigits

on execLXC&#40;theDoCommand&#41;
	--	display dialog theDoCommand as text
	tell application "LXConsole"
		if the front document exists then
			activate
			tell the front document to doCommand string theDoCommand
		end if
	end tell
end execLXC

on cosine_of&#40;x&#41;
	
	set answer to 0
	set numerator to 1
	set denominator to 1
	set factor to -&#40;x ^ 2&#41;
	
	repeat with i from 2 to 40 by 2
		set answer to answer + numerator / denominator
		set numerator to numerator * factor
		set denominator to denominator * i * &#40;i - 1&#41;
	end repeat
	
	return answer
end cosine_of

on sine_of&#40;x&#41;
	
	set answer to 0
	set numerator to x
	set denominator to 1
	set factor to -&#40;x ^ 2&#41;
	
	repeat with i from 3 to 40 by 2
		set answer to answer + numerator / denominator
		set numerator to numerator * factor
		set denominator to denominator * i * &#40;i - 1&#41;
	end repeat
	
	return answer
end sine_of
Cheers,

Freddy
freadZdead
Posts: 211
Joined: Sat Jun 01, 2013 8:23 am
Location: Adelaide, Australia

Post by freadZdead »

P.S., to make it an effect, you obviously have to add the generated cues to an effect, and it makes it very effective as you can easily override fade and step times at this level :).

Claude, is there an easy way to somehow switch off the confirmation of overwriting cues when working with the doCommand applescript hook? and/or is there an easy way to mass-delete generated cues when you don't like them?
Cheers,

Freddy
admin
Site Admin
Posts: 1643
Joined: Mon Nov 05, 2007 1:26 am
Contact:

Post by admin »

There is no way to disable the overwrite warning. However, you can select multiple rows in the cue sheet and use Cue->Delete Cue to remove them all at once.
(This only works in the cue sheet, not the cue list)
freadZdead
Posts: 211
Joined: Sat Jun 01, 2013 8:23 am
Location: Adelaide, Australia

Post by freadZdead »

Thanks, that does the trick :)!
Cheers,

Freddy
Post Reply