diff --git a/automation/autoload/kara-templater.lua b/automation/autoload/kara-templater.lua index 3c992f074..f032e1433 100644 --- a/automation/autoload/kara-templater.lua +++ b/automation/autoload/kara-templater.lua @@ -256,6 +256,47 @@ function apply_templates(meta, styles, subs, templates) } tenv.tenv = tenv + tenv.retime = function(mode, addstart, addend) + local line, syl = tenv.line, tenv.syl + local newstart, newend = line.start_time, line.end_time + addstart = addstart or 0 + addend = addend or 0 + if mode == "syl" then + newstart = line.start_time + syl.start_time + addstart + newend = line.start_time + syl.end_time + addend + elseif mode == "presyl" then + newstart = line.start_time + syl.start_time + addstart + newend = line.start_time + syl.start_time + addend + elseif mode == "postsyl" then + newstart = line.start_time + syl.end_time + addstart + newend = line.start_time + syl.end_time + addend + elseif mode == "preline" then + newstart = line.start_time + addstart + newend = line.start_time + addend + elseif mode == "postline" then + newstart = line.end_time + addstart + newend = line.end_time + addend + elseif mode == "start2syl" then + newstart = line.start_time + addstart + newend = line.start_time + syl.start_time + addend + elseif mode == "syl2end" then + newstart = line.start_time + syl.end_time + addstart + newend = line.end_time + addend + elseif mode == "set" or mode == "abs" then + newstart = addstart + newend = addend + elseif mode == "sylpct" then + newstart = line.start_time + syl.start_time + addstart*syl.duration/100 + newend = line.start_time + syl.start_time + addend*syl.duration/100 + -- wishlist: something for fade-over effects, + -- "time between previous line and this" and + -- "time between this line and next" + end + line.start_time = newstart + line.end_time = newend + return "" + end + -- run all run-once code snippets for k, t in pairs(templates.once) do assert(t.code, "WTF, a 'once' template without code?") @@ -375,8 +416,7 @@ function apply_line(meta, styles, subs, line, templates, tenv) tenv.orgline = line tenv.line = nil tenv.syl = nil - tenv.char = nil - tenv.furi = nil + tenv.basesyl = nil -- Apply all line templates aegisub.debug.out(5, "Running line templates\n") diff --git a/automation/tests/kara-templater-retime.ass b/automation/tests/kara-templater-retime.ass new file mode 100644 index 000000000..c9176540d --- /dev/null +++ b/automation/tests/kara-templater-retime.ass @@ -0,0 +1,29 @@ +[Script Info] +Title: Default Aegisub file +ScriptType: v4.00+ +WrapStyle: 0 +PlayResX: 640 +PlayResY: 480 +Video Aspect Ratio: 0 +Video Zoom: 8 +Video Position: 500 +Last Style Storage: Default +Video File: ?dummy:50.000000:1000:640:480:226:221:236:c + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: Default,Arial,50,&H00FFFFFF,&H0000FFFF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,2,0,5,10,10,10,0 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Comment: 0,0:00:00.00,0:00:00.00,Default,,0000,0000,0000,template noblank,!retime("abs",1000,2000)!{\pos($x,$y)\1c&H0000FF&} +Comment: 0,0:00:00.00,0:00:00.00,Default,,0000,0000,0000,template noblank,!retime("preline",-100)!{\pos($x,$y)\1c&H000000&} +Comment: 0,0:00:00.00,0:00:00.00,Default,,0000,0000,0000,template noblank,!retime("start2syl")!{\pos($x,$y)\1c&HFF0000&} +Comment: 0,0:00:00.00,0:00:00.00,Default,,0000,0000,0000,template noblank,!retime("presyl",-200,0)!{\pos($x,$y)\1a&HFF&\3c&H0000FF&} +Comment: 0,0:00:00.00,0:00:00.00,Default,,0000,0000,0000,template noblank,!retime("syl")!{\pos($x,$y)\1c&H00FF00&} +Comment: 0,0:00:00.00,0:00:00.00,Default,,0000,0000,0000,template noblank,!retime("postsyl",0,200)!{\pos($x,$y)\1a&HFF&\3c&H00FF00&} +Comment: 0,0:00:00.00,0:00:00.00,Default,,0000,0000,0000,template noblank,!retime("syl2end",200,0)!{\pos($x,$y)\1c&HFF00FF&} +Comment: 0,0:00:00.00,0:00:00.00,Default,,0000,0000,0000,template noblank,!retime("postline",0,100)!{\pos($x,$y)\1c&H00FFFF&} +Comment: 0,0:00:00.00,0:00:00.00,Default,,0000,0000,0000,template noblank,!retime("sylpct",50,100)!{\pos($center,$middle)\an5\1a&HFF&\3c&HFFFFFF&\fscy300\t(\3a&HFF&)} +Dialogue: 0,0:00:10.00,0:00:11.00,Default,,0000,0000,0000,,{\k30}ha{\k20}hi{\k50}ho +Dialogue: 0,0:00:11.00,0:00:16.00,Default,,0000,0000,0000,, \ No newline at end of file diff --git a/docs/auto4-kara-templater-retime-explanation.png b/docs/auto4-kara-templater-retime-explanation.png new file mode 100644 index 000000000..5af9f06b2 Binary files /dev/null and b/docs/auto4-kara-templater-retime-explanation.png differ