Fan-Chase-Generator Script
Posted: Mon Mar 03, 2014 3:41 am
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 !
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 !
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 (endChan < startChan) 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 (regChan + changer)
if (regChan ≤ 0) 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(theChannel, theList)
set theNewList to {}
repeat with i from 1 to count theList
if ({theList's item i} as number) is not (theChannel as number) then set the end of theNewList to ({theList's item i} as number)
end repeat
return theNewList
end deductChannel
on setStepInLive(stepNo, stepMultiplier, chosenShape, numSelChans, selectedChannels, minVal, maxVal)
set i to (stepNo - 1) / stepMultiplier -- / ofSteps
--set i to 0
repeat with selChan in selectedChannels
if chosenShape is "cos" then
set y to ((((my cosine_of((i * pi) / ((numSelChans - 1) / 2))) + 1) / 2) * (maxVal - minVal)) + minVal
else if chosenShape is "half cos" then
set y to ((((my cosine_of((i * pi) / (numSelChans - 1))) + 1) / 2) * (maxVal - minVal)) + minVal
else if chosenShape is "sin" then
set y to ((((my sine_of(((i - ((numSelChans - 1) / 4)) * pi) / ((numSelChans - 1) / 2))) + 1) / 2) * (maxVal - minVal)) + minVal
else if chosenShape is "half sin" then
set y to ((((my sine_of(((i - ((numSelChans - 1) / 2)) * pi) / (numSelChans - 1))) + 1) / 2) * (maxVal - minVal)) + minVal
end if
set theDoCommand to (selChan as text) & "@" & (my twoDigits(y) as text)
my execLXC(theDoCommand)
set i to i + 1
if i > (numSelChans - 1) then
set i to i - (numSelChans - 1)
end if
end repeat
end setStepInLive
on twoDigits(intensity)
if intensity < 10 then
return "0" & (intensity as text)
else
return (intensity as text)
end if
end twoDigits
on execLXC(theDoCommand)
-- 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(x)
set answer to 0
set numerator to 1
set denominator to 1
set factor to -(x ^ 2)
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 * (i - 1)
end repeat
return answer
end cosine_of
on sine_of(x)
set answer to 0
set numerator to x
set denominator to 1
set factor to -(x ^ 2)
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 * (i - 1)
end repeat
return answer
end sine_of