New karaoke skeleton, in the style of (but not compatible with) Auto3 karaskel-adv; untested as usual
Originally committed to SVN as r1429.
This commit is contained in:
parent
42f47ed7eb
commit
a5fdb048a4
1 changed files with 129 additions and 33 deletions
|
@ -535,47 +535,143 @@ end
|
||||||
-- otherwise the original line is converted to a comment
|
-- otherwise the original line is converted to a comment
|
||||||
-- General prototype of an fx function: function(subs, meta, styles, line, fxdata)
|
-- General prototype of an fx function: function(subs, meta, styles, line, fxdata)
|
||||||
-- fxdata are extra data after the effect name in the Effect field
|
-- fxdata are extra data after the effect name in the Effect field
|
||||||
function karaskel.fx_library_main(subs)
|
local fx_library_registered = false
|
||||||
aegisub.progress.task("Collecting header info")
|
function karaskel.use_fx_library_furi(use_furigana, macrotoo)
|
||||||
meta, styles = karaskel.collect_head(subs)
|
local function fx_library_main(subs)
|
||||||
|
aegisub.progress.task("Collecting header info")
|
||||||
aegisub.progress.task("Processing subs")
|
meta, styles = karaskel.collect_head(subs, use_furigana)
|
||||||
local i, maxi = 1, #subs
|
|
||||||
while i <= maxi do
|
|
||||||
aegisub.progress.set(i/maxi*100)
|
|
||||||
local l = subs[i]
|
|
||||||
|
|
||||||
if l.class == "dialogue" then
|
aegisub.progress.task("Processing subs")
|
||||||
aegisub.progress.task(l.text)
|
local i, maxi = 1, #subs
|
||||||
karaskel.preproc_line(subs, meta, styles, l)
|
while i <= maxi do
|
||||||
local keep = true
|
aegisub.progress.set(i/maxi*100)
|
||||||
local fx, fxdata = string.headtail(l.effect)
|
local l = subs[i]
|
||||||
if fx == "" then fx = "none" end
|
|
||||||
if _G["fx_" .. fx] then
|
if l.class == "dialogue" then
|
||||||
-- note to casual readers: _G is a special global variable that points to the global environment
|
aegisub.progress.task(l.text)
|
||||||
-- specifically, _G["_G"] == _G
|
karaskel.preproc_line(subs, meta, styles, l)
|
||||||
keep = _G["fx_" .. fx](subs, meta, styles, l, fxdata)
|
local keep = true
|
||||||
end
|
local fx, fxdata = string.headtail(l.effect)
|
||||||
if not keep then
|
if fx == "" then fx = "none" end
|
||||||
l = subs[i]
|
if _G["fx_" .. fx] then
|
||||||
l.comment = true
|
-- note to casual readers: _G is a special global variable that points to the global environment
|
||||||
subs[i] = l
|
-- specifically, _G["_G"] == _G
|
||||||
|
keep = _G["fx_" .. fx](subs, meta, styles, l, fxdata)
|
||||||
|
end
|
||||||
|
if not keep then
|
||||||
|
l = subs[i]
|
||||||
|
l.comment = true
|
||||||
|
subs[i] = l
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
i = i + 1
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
-- Register an fx_library type karaoke
|
if fx_library_registered then return end
|
||||||
karaskel.fx_library_registered = false
|
aegisub.register_filter(script_name or "fx_library", script_description or "Apply karaoke effects (fx_library skeleton)", 2000, fx_library_main)
|
||||||
function karaskel.use_fx_library(macrotoo)
|
|
||||||
if karaskel.fx_library_registered then return end
|
|
||||||
aegisub.register_filter(script_name or "fx_library", script_description or "Apply karaoke effects (fx_library skeleton)", 2000, karaskel.fx_library_main)
|
|
||||||
if macrotoo then
|
if macrotoo then
|
||||||
local function fxlibmacro(subs)
|
local function fxlibmacro(subs)
|
||||||
karaskel.fx_library_main(subs)
|
fx_library_main(subs)
|
||||||
aegisub.set_undo_point(script_name or "karaoke effect")
|
aegisub.set_undo_point(script_name or "karaoke effect")
|
||||||
end
|
end
|
||||||
aegisub.register_macro(script_name or "fx_library", script_description or "Apply karaoke effects (fx_library skeleton)", fxlibmacro)
|
aegisub.register_macro(script_name or "fx_library", script_description or "Apply karaoke effects (fx_library skeleton)", fxlibmacro)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function karaskel.use_fx_library(macrotoo)
|
||||||
|
return karaskel.use_fx_library_furi(false, macrotoo)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- A skeleton that approximately simulates the Auto3 "advanced" one.
|
||||||
|
-- Build a Auto3-like list of dialogue lines and also add linked list refs to lines.
|
||||||
|
-- Call user-defined do_line function for each line, if it exists.
|
||||||
|
-- The default do_line function will call the do_syllable function for each line,
|
||||||
|
-- if the function exists.
|
||||||
|
-- The function names called are constant.
|
||||||
|
local classic_adv_registered = false
|
||||||
|
function karaskel.use_classic_adv(use_furigana, macrotoo)
|
||||||
|
local function classic_adv_main(subs)
|
||||||
|
|
||||||
|
local function default_do_syllable(subs, meta, styles, lines, line, syl)
|
||||||
|
-- do nothing
|
||||||
|
end
|
||||||
|
|
||||||
|
local sylfunc = (type(_G.do_syllable)=="function" and _G.do_syllable) or default_do_syllable
|
||||||
|
local furifunc = (type(_G.do_furigana)=="function" and _G.do_furigana) or default_do_syllable
|
||||||
|
|
||||||
|
local function default_do_line(subs, meta, styles, lines, line)
|
||||||
|
for i = 0, line.kara.n do
|
||||||
|
sylfunc(subs, meta, styles, lines, line, line.kara[i])
|
||||||
|
end
|
||||||
|
if use_furigana then
|
||||||
|
for i = 0, line.furi.n do
|
||||||
|
furifunc(subs, meta, styles, lines, line, line.furi[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
aegisub.progress.task("Collecting header info")
|
||||||
|
local meta, styles = karaskel.collect_head(subs, use_furigana)
|
||||||
|
|
||||||
|
-- Collect lines
|
||||||
|
aegisub.progress.task("Collecting subtitle lines")
|
||||||
|
local lines = { n=0 }
|
||||||
|
local prevline = nil
|
||||||
|
local i = 1
|
||||||
|
local curorgline, maxorglines = 1, #subs
|
||||||
|
while i <= #subs do
|
||||||
|
aegisub.progress.set(curorgline/maxorglines*100)
|
||||||
|
local l = subs[i]
|
||||||
|
if l.class == "dialogue" then
|
||||||
|
-- Link prev of this one
|
||||||
|
l.prev = prevline
|
||||||
|
l.next = nil
|
||||||
|
-- Line next of prev one
|
||||||
|
if prevline then
|
||||||
|
prevline.next = l
|
||||||
|
end
|
||||||
|
-- Insert into array
|
||||||
|
lines.n = lines.n + 1
|
||||||
|
lines[lines.n] = l
|
||||||
|
-- Update prev
|
||||||
|
prevline = l
|
||||||
|
-- Delete from file
|
||||||
|
subs[i] = nil
|
||||||
|
else
|
||||||
|
-- Only increase for non-dialogue lines
|
||||||
|
-- (Dialogue lines are deleted, so every other lines moves one down)
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
curorgline = curorgline + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
aegisub.progress.task("Processing subtitles")
|
||||||
|
local linefunc = default_do_line
|
||||||
|
if type(_G.do_line)=="function" then
|
||||||
|
linefunc = function(subs, meta, styles, lines, line)
|
||||||
|
return _G.do_line(subs, meta, styles, lines, line, default_do_line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i = 1, lines.n do
|
||||||
|
aegisub.progress.set(i/lines.n*100)
|
||||||
|
linefunc(subs, meta, styles, lines, lines[i])
|
||||||
|
end
|
||||||
|
|
||||||
|
aegisub.progress.task("Finished")
|
||||||
|
aegisub.progress.set(100)
|
||||||
|
end
|
||||||
|
|
||||||
|
if classic_adv_registered then return end
|
||||||
|
aegisub.register_filter(script_name or "classic_adv", script_description or "Apply karaoke effects (classic_adv skeleton)", 2000, classic_adv_main)
|
||||||
|
|
||||||
|
if macrotoo then
|
||||||
|
local function classic_adv_macro(subs)
|
||||||
|
classic_adv_main(subs)
|
||||||
|
aegisub.set_undo_point(script_name or "karaoke effect")
|
||||||
|
end
|
||||||
|
aegisub.register_macro(script_name or "classic_adv", script_description or "Apply karaoke effects (classic_adv skeleton)", classic_adv_macro)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue