Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.25 KB | None | 0 0
  1. --[[
  2. Presets to Macros v1.5.3
  3. Created by Jason Giaffo (HoboLX)
  4. Contact: GiaffoDesigns@gmail.com
  5. Last updated August 21, 2016
  6.  
  7. Takes presets and groups and turns them into macros you can use
  8. --]]
  9.  
  10.  
  11.  
  12. --local shortcut variables
  13. local text = gma.textinput
  14. local cmd = gma.cmd
  15. local getHandle = gma.show.getobj.handle
  16.  
  17.  
  18. --FUNCTIONS
  19. function getLabel(str)
  20.   return gma.show.getobj.label(getHandle(str))
  21. end
  22.  
  23. function getClass(str)
  24.   return gma.show.getobj.class(getHandle(str))
  25. end
  26.  
  27. function checkSpace(poolType, start, length, displayMessage) --checks if range of pool spaces is empty
  28.   local finish = start + length - 1 --set our finishing point
  29.   local errorMessage = poolType..' space conflict: please run plugin with a new '..poolType..' start slot'
  30.   local emptyStatus = true
  31.   for i = start, finish do
  32.     if getClass(poolType..' '..tostring(i)) ~= nil then --if space is not empty
  33.       emptyStatus = false
  34.       if displayMessage == true then --return error message if this condition has been set
  35.         gma.feedback(errorMessage)
  36.         gma.echo(errorMessage)
  37.       end
  38.       break
  39.     end
  40.   end
  41.   return emptyStatus
  42. end
  43.  
  44. function match(a, b)            --checks to see if a and b match or (if strings) if one contains the other, ignoring capitalization
  45.   if a == b then return true    --used for user input of preset type by text rather than number
  46.   elseif type(a) == 'string' and type(b) == 'string' then
  47.     if string.find(string.lower(a), string.lower(b)) ~= nil or
  48.        string.find(string.lower(b), string.lower(a)) ~= nil then
  49.       return true
  50.     else return false
  51.     end
  52.   else return false;
  53.   end
  54. end
  55.  
  56. function table.find(t, target, i, j) --traverses table (t) to find the target using the match function defined above
  57.   if i == nil then i = 1 end --set default values if optional variables not entered
  58.   if j == nil then j = #t end
  59.   for n = i, j do
  60.     if match(t[n], target) == true then
  61.       return n;
  62.     end
  63.   end
  64.   return nil
  65. end
  66.  
  67.  
  68. return function() --START OF PLUGIN
  69.  
  70. --COLOR/PRESET SELECTION--
  71. local presetTypes = {'Dimmer', 'Position', 'Gobo', 'Color', 'Beam', 'Focus', 'Control', 'Shapers', 'Video'};
  72. presetTypes[0] = 'All'
  73.  
  74. local displayMessage = {'Color (4), Position (2), etc.', 'please use number or name of preset type'}
  75. local x = 1 --will determine which display message is used during plugin usage
  76.  
  77. local pType --declare local variable so assignment in loop is not lost
  78. local pTypeNum
  79.  
  80. while true do --insert function as a loop in case of invalid inputs
  81.   local presetInput = text('Preset Type', displayMessage[x])  --USER INPUT FOR PRESET TYPE
  82.   if match(presetInput, 'colour') == true then --because who doesn't like Easter eggs?
  83.     gma.echo('Brit detected')
  84.     while match(presetInput, 'color') == false do
  85.       presetInput = text('Spell it correctly', 'You British scum...')
  86.     end
  87.   end
  88.  
  89.   if (tonumber(presetInput) ~= nil) and (#presetInput == 1) then  --matches based on number input
  90.     pType = presetTypes[tonumber(presetInput)]
  91.     pTypeNum = presetInput
  92.   elseif string.find(presetInput, '%a') == 1 then  --matches based on first three letters of text input
  93.     local inputAbbr = string.match(presetInput, '%a%a%a')
  94.     pTypeNum = tostring(table.find(presetTypes, inputAbbr, 0))
  95.     pType = presetTypes[tonumber(pTypeNum)]
  96.   end
  97.  
  98.   if pType and pTypeNum then break --ends loop if values have been assigned
  99.   else x = 2 end --changes text displayed if loop is performed
  100. end
  101.  
  102. --POPULATE PRESET LIST--
  103. local pNum = {} --list where numbers of preset pool items will be stored
  104. local pName = {} --list where names of preset pool items will be stored
  105.  
  106. local displayMessage = {'HIT ENTER WHEN DONE', 'ONLY NUMERICAL INPUT SUPPORTED'}
  107. local loopct = 1
  108. local x = 1
  109.  
  110. while true do
  111.   local t = text(pType..' #'..loopct, displayMessage[x])
  112.   if t == displayMessage[x] then
  113.     break  --will terminate loop if ENTER is hit without a new value
  114.   elseif tonumber(t) ~= nil then
  115.     pNum[loopct] = t
  116.     pName[loopct] = getLabel('Preset '..pTypeNum..'.'..t)
  117.     loopct = loopct + 1
  118.     x = 1 --resets the display message to the original line
  119.   elseif t == nil then--allows X button to end plugin rather than continue loop
  120.     goto EOF
  121.   else    --restarts loop with error message displayed instead
  122.     x = 2
  123.   end
  124. end
  125.  
  126.  
  127. --POPULATE GROUP LIST--
  128. local grpNum = {} --list where numbers of group pool items will be stored
  129. local grpName = {} --list where names of group pool items will be stored
  130.  
  131. local loopct = 1
  132. local x = 1
  133.  
  134. while true do
  135.   local t = text('Group #'..loopct, displayMessage[x])
  136.   if t == displayMessage[x] then
  137.     break  --will terminate loop if ENTER is hit without a new value
  138.   elseif tonumber(t) ~= nil then
  139.     grpNum[loopct] = t
  140.     grpName[loopct] = getLabel('Group '..t)
  141.     loopct = loopct + 1
  142.     x = 1 --resets the display message to the original line
  143.   elseif t == nil then --allows X button to end plugin rather than continue loop
  144.     goto EOF
  145.   else    --restarts loop with error message displayed instead
  146.     x = 2
  147.   end
  148. end
  149.  
  150.  
  151. gma.echo('List creation completed:')
  152. gma.echo('Groups: '..tostring(#grpNum))
  153. gma.echo(pType..'s: '..tostring(#pNum))
  154.  
  155. --MACRO AND SEQUENCE STARTING POINTS
  156. local seqStart = tonumber(text('Starting Sequence #', 'CHECK SPACE BEFORE INPUT')) --establish starting point
  157. while checkSpace('Sequence', seqStart, #grpNum, false) == false do               --check if enough space is present
  158.   seqStart = tonumber(text('New Starting Sequence #', 'INSUFFICIENT SPACE'))     --new starting point if not enough space
  159. end
  160.  
  161. local macroLength = (#grpNum + 1) * #pNum + 1 --accounts for length of sequence, appearance, and uninstall macros
  162. local macStart = tonumber(text('Starting Macro #', 'CHECK SPACE BEFORE INPUT'))  --establish starting point
  163. while checkSpace('Macro', macStart, macroLength, false) == false do              --check if enough space is present
  164.   macStart = tonumber(text('New Starting Macro #', 'INSUFFICIENT SPACE'))        --new starting point if not enough space
  165. end
  166.  
  167. --PRESETS TO SEQUENCE CUES BY GROUP AND CREATE MACROS--
  168. local macCurrent = macStart
  169. local seqCurrent = seqStart
  170.  
  171. for i = 1, #grpNum do
  172.   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
  173.   macGroup.start = macStart + (#pNum * (i-1))
  174.   macGroup.final = macStart + (#pNum * i) - 1
  175.   for j = 1, #pNum do
  176.     cmd('Group '..grpNum[i]..' At Preset '..pTypeNum..'.'..pNum[j]) --group at preset
  177.     cmd('Store Sequence '..seqCurrent..' Cue '..j) --store to sequence and cue
  178.    
  179.     cmd('Label Sequence '..seqCurrent..' \"'..grpName[i]..' '..pType..'\"'); --label sequence
  180.     cmd('Label Sequence '..seqCurrent..' Cue '..j..' \"'..grpName[i]..' '..pName[j]..'\"');  --label cue w/ name tables
  181.    
  182.     cmd('Store Macro '..macCurrent);   --create macro
  183.     cmd('Store Macro 1.'..macCurrent..'.1');   --create macro LINE
  184.     cmd('Store Macro 1.'..macCurrent..'.2');
  185.     cmd('Store Macro 1.'..macCurrent..'.3');
  186.    
  187.     cmd('Assign Macro 1.'..macCurrent..'.1 /cmd="Goto Sequence '..seqCurrent..' Cue '..j..'"');   --fill macro lines
  188.     cmd('Assign Macro 1.'..macCurrent..'.2 /cmd=\"Off Macro '..macGroup.start..' Thru '..macGroup.final..' - '..macCurrent..'\"');
  189.     cmd('Assign Macro 1.'..macCurrent..'.2 /wait=2');
  190.     cmd('Label Macro '..macCurrent..'"'..grpName[i]..' '..pName[j]..'"');   --label macro
  191.    
  192.     cmd('ClearAll'); --clear your programmer
  193.    
  194.     macCurrent = macCurrent + 1 --move to next macro number
  195.     gma.sleep(0.05) --to ease processing power conflicts
  196.   end  
  197.   seqCurrent = seqCurrent + 1 --move to next sequence number
  198. end
  199.  
  200. local seqEnd = seqCurrent --save value for final sequence used
  201.  
  202. --COLUMN APPEARANCE MACROS--
  203. local macCurrent = macStart + (#grpNum * #pNum) --resets variable at the position after all color macros based on the number of possible combinations
  204. local macAppStart = macCurrent --save value for starting appearance macro number
  205.  
  206. for i = 1, #pNum do --iterate for number of colors/presets
  207.   cmd('Store Macro '..macCurrent) --create macro
  208.   cmd('Store Macro 1.'..macCurrent..'.1') --create macro line 1
  209.   cmd('Label Macro '..macCurrent..' \"Appearance '..pName[i]..'\"') --label macro "Appearance (color name)"
  210.   local t = 'Macro '..(macStart+i-1) --text which will be saved in appearance macro
  211.  
  212.   if #grpNum > 1 then --
  213.     local index = i - 1
  214.     for j = 1, (#grpNum-1) do
  215.       index = index + #pNum --number of next macro referencing same color
  216.       t = t..' + '..(macStart + index) --appends the number to the macro line for setting appearance
  217.     end
  218.   end
  219.    
  220.   cmd('Assign Macro 1.'..macCurrent..'.1 /cmd = \"Appearance '..t..'\"') --assign text to macro line
  221.   macCurrent = macCurrent + 1;
  222. end
  223.  
  224. local macAppEnd = macCurrent - 1 --create reference value for final appearance macro
  225. cmd('Appearance Macro '..macAppStart..' thru '..macAppEnd..' /r=100 /g=100 /b=100') --set all appearance macros to white
  226.  
  227. --UNINSTALL MACRO--
  228. cmd('Store Macro 1.'..macCurrent);
  229. cmd('Label Macro 1.'..macCurrent..'\"UNINSTALL COLOR MACROS\"');
  230. cmd('Store Macro 1.'..macCurrent..'.1');
  231. cmd('Store Macro 1.'..macCurrent..'.2');
  232. cmd('Assign Macro 1.'..macCurrent..'.1 /cmd=\"Delete Sequence '..seqStart..' Thru '..seqEnd..'\"');
  233. cmd('Assign Macro 1.'..macCurrent..'.2 /cmd=\"Delete Macro '..macStart..' Thru '..macCurrent..'\"');
  234.  
  235.  
  236. ::EOF:: --tag for goto functions
  237. end  --END OF PLUGIN
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement