Created
November 20, 2015 20:40
-
-
Save iamevn/0902601561c7edcb096c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
script_name="Clip Transform Points" | |
script_description="first and last lines selected should have clips with the same number of points. transforms each point's position from first to last line over the selected lines (WARNING: wipes out any clip on intermediate lines" | |
script_author="iamevn" | |
script_version="0.1" | |
script_namespace="evn.ClipTransformPoints" | |
function transform(subs, sel) | |
--[[ | |
so here's the plan: | |
A - acceleration (default 1) | |
N - number of lines selected | |
]]-- | |
A = 1.0 | |
S = 1 | |
N = #sel | |
inverseClip = string.match(subs[sel[S]].text, "\\iclip%(.-%)") ~= nil | |
initialClip = string.match(subs[sel[S]].text, "\\i?clip%((.-)%)") | |
initialTable = {} | |
for s in string.gmatch(initialClip, "%S+") do | |
table.insert(initialTable, s) | |
end | |
finalClip = string.match(subs[sel[N]].text, "\\i?clip%((.-)%)") | |
finalTable = {} | |
for s in string.gmatch(finalClip, "%S+") do | |
table.insert(finalTable, s) | |
end | |
for index, line_idx in ipairs(sel) do | |
progress = (index - S) / (N - S) | |
progress = math.pow(progress, A) | |
lineTable = {} | |
for key, s in ipairs(initialTable) do | |
if tonumber(s) == nil then | |
table.insert(lineTable, s) | |
else | |
IVAL = initialTable[key] | |
FVAL = finalTable[key] | |
value = (1 - progress) * IVAL + progress * FVAL | |
table.insert(lineTable, value) | |
end | |
end | |
body = "" | |
for i, s in ipairs(lineTable) do | |
if #body == 0 then | |
body = body .. s | |
else | |
body = body .. " " .. s | |
end | |
end | |
line = subs[line_idx] | |
line.text = string.gsub(line.text, "\\i?clip%(.-%)", "") | |
if inverseClip then | |
line.text = string.gsub(line.text, "}", "\\iclip(" .. body .. ")}") | |
else | |
line.text = string.gsub(line.text, "}", "\\clip(" .. body .. ")}") | |
end | |
subs[line_idx] = line | |
end | |
end | |
--[[ | |
validates that the first and last lines have "matching" clips | |
(matching in the sense that they have the same number of points | |
and the same sorts of lines in the same places) | |
]]-- | |
function validate(subs, sel) | |
if #sel < 3 then | |
return false | |
end | |
initialClip = string.match(subs[sel[1]].text, "\\i?clip%((.-)%)") | |
finalClip = string.match(subs[sel[#sel]].text, "\\i?clip%((.-)%)") | |
if initialClip == nil or finalClip == nil then | |
return false | |
end | |
initialTable = {} | |
for s in string.gmatch(initialClip, "%S+") do | |
table.insert(initialTable, s) | |
end | |
finalTable = {} | |
for s in string.gmatch(finalClip, "%S+") do | |
table.insert(finalTable, s) | |
end | |
if #initialTable ~= #finalTable then | |
return false | |
end | |
for i = 1, #initialTable do | |
a = initialTable[i] | |
b = finalTable[i] | |
if tonumber(a) == nil and tonumber(b) == nil then | |
if a ~= b then | |
return false | |
end | |
elseif tonumber(a) ~= nil and tonumber(b) ~= nil then | |
--everything's good | |
else | |
return false | |
end | |
end | |
return true | |
end | |
aegisub.register_macro(script_name, script_description, transform, validate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(I should probably have it split the line(s) into frame by frame things but you can do that with other scripts just fine already.)