Page 1 of 1

Lua code to generate many macro files

Posted: 26 Jun 2020, 14:35
by kimwida
Sometimes you need to make many macro files which are doing smiliar things.
This is my lua code to generate them and you can use any programming language instead of lua.

Code: Select all

FileName = "Chase XFade"
MacroName = "% XFade"
MacroId = "Chase_XFade"

Window = "PlaybackWindow"
Page = 0
Slot = {}

--PlaybackSpeed : .Float : 120.0(120bpm)
--ChaseSpeedMultiplier : .Double : 2.0(x2)
--ChaseXFade : .Float : 1.0(100%)
--ChaseFixtureOverlap : .Float : 1.0(100%)

Item = "ChaseXFade"
Type = ".Float"
Content = {"0.0","0.5","0.9","1.0"}
Legend = {"0","50","90","100"}
--make temp Slots
--Slot = {0,1,2,3,4,5}
for i = 1, 60 do
   Slot[i] = i-1
end
--calculate size of slot
SizeOfSlot = 0
i = 1
while Slot[i] do
   SizeOfSlot = SizeOfSlot + 1
   i = i + 1
end
SizeOfContent = 0
i = 1
while Content[i] do
   SizeOfContent = SizeOfContent + 1
   i = i + 1
end
--macro saving location
filename = "C:\\Users\\kimwida\\Documents\\Titan\\Macros\\" .. FileName ..".xml"
local file = io.open(filename, "w")

FileTxt = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
FileTxt = FileTxt .."<avolites.macros>\n"

for j = 1, SizeOfContent do
   FileTxt = FileTxt .."  <macro id=\"" .. MacroId .. Content[j] .. "\">\n"
   FileTxt = FileTxt .."    <name>" .. Legend[j] .. " " .. MacroName .. "</name>\n"
   FileTxt = FileTxt .."    <sequence>\n"
   for i = 1, SizeOfSlot do
      FileTxt = FileTxt .."       <step pause=\"0.001\">Handles.SetSourceHandleFromHandle(Handles.GetHandle(\"" .. Window .. "\"," .. Page .. "," .. Slot[i] .. ")) </step>\n"
      FileTxt = FileTxt .."       <step pause=\"0.001\">ActionScript.SetProperty(\"Playbacks.Editor.SelectedPlayback\", Handles.SourceHandle)</step>\n"
      FileTxt = FileTxt .."       <step pause=\"0.001\">ActionScript.SetProperty" .. Type .. "(\"Playbacks.Editor.Times." .. Item .. "\"," .. Content[j] .. ")</step>\n"
   end
   FileTxt = FileTxt .."       <step pause=\"0.001\">Handles.ClearSelection()</step>\n"
   FileTxt = FileTxt .."       <step pause=\"0.001\">ActionScript.SetProperty(\"Playbacks.Editor.SelectedPlayback\", null)</step>\n\n"
   FileTxt = FileTxt .."    </sequence>\n"
   FileTxt = FileTxt .."  </macro>\n"
end
FileTxt = FileTxt .."</avolites.macros>\n"
io.output(file)
io.write(FileTxt)
io.close(file)