Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Presets to Macros v1.5.3
- Created by Jason Giaffo (HoboLX)
- Contact: GiaffoDesigns@gmail.com
- Last updated August 21, 2016
- Takes presets and groups and turns them into macros you can use
- --]]
- --local shortcut variables
- local text = gma.textinput
- local cmd = gma.cmd
- local getHandle = gma.show.getobj.handle
- --FUNCTIONS
- function getLabel(str)
- return gma.show.getobj.label(getHandle(str))
- end
- function getClass(str)
- return gma.show.getobj.class(getHandle(str))
- end
- function checkSpace(poolType, start, length, displayMessage) --checks if range of pool spaces is empty
- local finish = start + length - 1 --set our finishing point
- local errorMessage = poolType..' space conflict: please run plugin with a new '..poolType..' start slot'
- local emptyStatus = true
- for i = start, finish do
- if getClass(poolType..' '..tostring(i)) ~= nil then --if space is not empty
- emptyStatus = false
- if displayMessage == true then --return error message if this condition has been set
- gma.feedback(errorMessage)
- gma.echo(errorMessage)
- end
- break
- end
- end
- return emptyStatus
- end
- function match(a, b) --checks to see if a and b match or (if strings) if one contains the other, ignoring capitalization
- if a == b then return true --used for user input of preset type by text rather than number
- elseif type(a) == 'string' and type(b) == 'string' then
- if string.find(string.lower(a), string.lower(b)) ~= nil or
- string.find(string.lower(b), string.lower(a)) ~= nil then
- return true
- else return false
- end
- else return false;
- end
- end
- function table.find(t, target, i, j) --traverses table (t) to find the target using the match function defined above
- if i == nil then i = 1 end --set default values if optional variables not entered
- if j == nil then j = #t end
- for n = i, j do
- if match(t[n], target) == true then
- return n;
- end
- end
- return nil
- end
- return function() --START OF PLUGIN
- --COLOR/PRESET SELECTION--
- local presetTypes = {'Dimmer', 'Position', 'Gobo', 'Color', 'Beam', 'Focus', 'Control', 'Shapers', 'Video'};
- presetTypes[0] = 'All'
- local displayMessage = {'Color (4), Position (2), etc.', 'please use number or name of preset type'}
- local x = 1 --will determine which display message is used during plugin usage
- local pType --declare local variable so assignment in loop is not lost
- local pTypeNum
- while true do --insert function as a loop in case of invalid inputs
- local presetInput = text('Preset Type', displayMessage[x]) --USER INPUT FOR PRESET TYPE
- if match(presetInput, 'colour') == true then --because who doesn't like Easter eggs?
- gma.echo('Brit detected')
- while match(presetInput, 'color') == false do
- presetInput = text('Spell it correctly', 'You British scum...')
- end
- end
- if (tonumber(presetInput) ~= nil) and (#presetInput == 1) then --matches based on number input
- pType = presetTypes[tonumber(presetInput)]
- pTypeNum = presetInput
- elseif string.find(presetInput, '%a') == 1 then --matches based on first three letters of text input
- local inputAbbr = string.match(presetInput, '%a%a%a')
- pTypeNum = tostring(table.find(presetTypes, inputAbbr, 0))
- pType = presetTypes[tonumber(pTypeNum)]
- end
- if pType and pTypeNum then break --ends loop if values have been assigned
- else x = 2 end --changes text displayed if loop is performed
- end
- --POPULATE PRESET LIST--
- local pNum = {} --list where numbers of preset pool items will be stored
- local pName = {} --list where names of preset pool items will be stored
- local displayMessage = {'HIT ENTER WHEN DONE', 'ONLY NUMERICAL INPUT SUPPORTED'}
- local loopct = 1
- local x = 1
- while true do
- local t = text(pType..' #'..loopct, displayMessage[x])
- if t == displayMessage[x] then
- break --will terminate loop if ENTER is hit without a new value
- elseif tonumber(t) ~= nil then
- pNum[loopct] = t
- pName[loopct] = getLabel('Preset '..pTypeNum..'.'..t)
- loopct = loopct + 1
- x = 1 --resets the display message to the original line
- elseif t == nil then--allows X button to end plugin rather than continue loop
- goto EOF
- else --restarts loop with error message displayed instead
- x = 2
- end
- end
- --POPULATE GROUP LIST--
- local grpNum = {} --list where numbers of group pool items will be stored
- local grpName = {} --list where names of group pool items will be stored
- local loopct = 1
- local x = 1
- while true do
- local t = text('Group #'..loopct, displayMessage[x])
- if t == displayMessage[x] then
- break --will terminate loop if ENTER is hit without a new value
- elseif tonumber(t) ~= nil then
- grpNum[loopct] = t
- grpName[loopct] = getLabel('Group '..t)
- loopct = loopct + 1
- x = 1 --resets the display message to the original line
- elseif t == nil then --allows X button to end plugin rather than continue loop
- goto EOF
- else --restarts loop with error message displayed instead
- x = 2
- end
- end
- gma.echo('List creation completed:')
- gma.echo('Groups: '..tostring(#grpNum))
- gma.echo(pType..'s: '..tostring(#pNum))
- --MACRO AND SEQUENCE STARTING POINTS
- local seqStart = tonumber(text('Starting Sequence #', 'CHECK SPACE BEFORE INPUT')) --establish starting point
- while checkSpace('Sequence', seqStart, #grpNum, false) == false do --check if enough space is present
- seqStart = tonumber(text('New Starting Sequence #', 'INSUFFICIENT SPACE')) --new starting point if not enough space
- end
- local macroLength = (#grpNum + 1) * #pNum + 1 --accounts for length of sequence, appearance, and uninstall macros
- local macStart = tonumber(text('Starting Macro #', 'CHECK SPACE BEFORE INPUT')) --establish starting point
- while checkSpace('Macro', macStart, macroLength, false) == false do --check if enough space is present
- macStart = tonumber(text('New Starting Macro #', 'INSUFFICIENT SPACE')) --new starting point if not enough space
- end
- --PRESETS TO SEQUENCE CUES BY GROUP AND CREATE MACROS--
- local macCurrent = macStart
- local seqCurrent = seqStart
- for i = 1, #grpNum do
- local macGroup = {} --this will hold the numbers of the first and last macros referencing the same group for use in line 2 of the macro
- macGroup.start = macStart + (#pNum * (i-1))
- macGroup.final = macStart + (#pNum * i) - 1
- for j = 1, #pNum do
- cmd('Group '..grpNum[i]..' At Preset '..pTypeNum..'.'..pNum[j]) --group at preset
- cmd('Store Sequence '..seqCurrent..' Cue '..j) --store to sequence and cue
- cmd('Label Sequence '..seqCurrent..' \"'..grpName[i]..' '..pType..'\"'); --label sequence
- cmd('Label Sequence '..seqCurrent..' Cue '..j..' \"'..grpName[i]..' '..pName[j]..'\"'); --label cue w/ name tables
- cmd('Store Macro '..macCurrent); --create macro
- cmd('Store Macro 1.'..macCurrent..'.1'); --create macro LINE
- cmd('Store Macro 1.'..macCurrent..'.2');
- cmd('Store Macro 1.'..macCurrent..'.3');
- cmd('Assign Macro 1.'..macCurrent..'.1 /cmd="Goto Sequence '..seqCurrent..' Cue '..j..'"'); --fill macro lines
- cmd('Assign Macro 1.'..macCurrent..'.2 /cmd=\"Off Macro '..macGroup.start..' Thru '..macGroup.final..' - '..macCurrent..'\"');
- cmd('Assign Macro 1.'..macCurrent..'.2 /wait=2');
- cmd('Label Macro '..macCurrent..'"'..grpName[i]..' '..pName[j]..'"'); --label macro
- cmd('ClearAll'); --clear your programmer
- macCurrent = macCurrent + 1 --move to next macro number
- gma.sleep(0.05) --to ease processing power conflicts
- end
- seqCurrent = seqCurrent + 1 --move to next sequence number
- end
- local seqEnd = seqCurrent --save value for final sequence used
- --COLUMN APPEARANCE MACROS--
- local macCurrent = macStart + (#grpNum * #pNum) --resets variable at the position after all color macros based on the number of possible combinations
- local macAppStart = macCurrent --save value for starting appearance macro number
- for i = 1, #pNum do --iterate for number of colors/presets
- cmd('Store Macro '..macCurrent) --create macro
- cmd('Store Macro 1.'..macCurrent..'.1') --create macro line 1
- cmd('Label Macro '..macCurrent..' \"Appearance '..pName[i]..'\"') --label macro "Appearance (color name)"
- local t = 'Macro '..(macStart+i-1) --text which will be saved in appearance macro
- if #grpNum > 1 then --
- local index = i - 1
- for j = 1, (#grpNum-1) do
- index = index + #pNum --number of next macro referencing same color
- t = t..' + '..(macStart + index) --appends the number to the macro line for setting appearance
- end
- end
- cmd('Assign Macro 1.'..macCurrent..'.1 /cmd = \"Appearance '..t..'\"') --assign text to macro line
- macCurrent = macCurrent + 1;
- end
- local macAppEnd = macCurrent - 1 --create reference value for final appearance macro
- cmd('Appearance Macro '..macAppStart..' thru '..macAppEnd..' /r=100 /g=100 /b=100') --set all appearance macros to white
- --UNINSTALL MACRO--
- cmd('Store Macro 1.'..macCurrent);
- cmd('Label Macro 1.'..macCurrent..'\"UNINSTALL COLOR MACROS\"');
- cmd('Store Macro 1.'..macCurrent..'.1');
- cmd('Store Macro 1.'..macCurrent..'.2');
- cmd('Assign Macro 1.'..macCurrent..'.1 /cmd=\"Delete Sequence '..seqStart..' Thru '..seqEnd..'\"');
- cmd('Assign Macro 1.'..macCurrent..'.2 /cmd=\"Delete Macro '..macStart..' Thru '..macCurrent..'\"');
- ::EOF:: --tag for goto functions
- end --END OF PLUGIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement