Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 0add71ca rédigé par Kubat's avatar Kubat
Parcourir les fichiers

LUA: Add a sample lua script, a proposition of how to create a script

parent 09d2d89b
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!9Lua cpp expose
--[[
Sample script to have a Vivy script specification. Note that all things in
a script should be "local" or you won't be saved if you break something
else in Vivy...
--]]
--[[
Get the global variables from the Vivy runtime, like the video dimensions
or duration, etc.
--]]
local global = vivy:global()
--[[
Get other script, here the util script. You can pass an author in case of
ambiguity. The standard scripts are available under the "std" author, thus
you can't register scripts in the name of "std". If there is ambiguity, an
error will be displayed by Vivy. If the tuple (script, author, revision) is
not unique, you will get an error on register time.
--]]
local utils = vivy:get_script{script = "utils", author = "std"}
local utils = vivy:get_script{script = "utils"}
-- Create a new script.
local script = vivy:new_script{
name = "sample_script",
author = "Vivy",
revision = "rev-1254",
opt = {
option1 = false,
pre_time = -900,
post_time = 300,
color1 = vivy:new_color("#314159")
},
description = [[
Sample script use for the specifications.
]]
}
-- A local function
local function triple_copy_syl (syl)
return { syl:copy(), syl:copy(), syl:copy() }
end
--[[
All functions take as first parameter the opt structure. This is really
usefull when calling multiple scripts on the same Vivy document with a
document defined options.
--]]
local set_retime = vivy:new_job{
name = "retime_lines",
iterate = "line",
callback = function (opt, line)
line.start_time += opt.pre_time
line.end_time += opt.post_time
return line
end
}
local demultiply_syllabes = vivy:new_job{
name = "create_syllabes",
iterate = "syl",
callback = function (opt, syl)
local new_syls = triple_copy_syl(syl)
new_syls[1].start_time = syl.line.start_time
new_syls[1].end_time = syl.start_time
new_syls[3].end_time = syl.line.end_time
new_syls[3].start_time = syl.end_time
-- You can return a table, the runtime will unroll it and add all the
-- elements to the new ASS AST.
return new_syls
end
}
-- Register the callbacks. Will be called in that order
script:add_jobs({
set_retime, -- Retime lines
demultiply_syllabes, -- Aegisub's syllabe
utils:get_job("color_after_read_3") -- 3-patern syls, apply color{1,2}
})
-- Register the script.
vivy:register_script(script)
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter