Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- addfade = {--[[
- Adds fadings to the start or the and of selected lines,
- with or without using \fad.
- Also supports \k-tagged karaoke lines.
- 1.1
- 01-06-2011
- FichteFoll
- ]]}
- -- Variables
- script_name = "Add Fadings"
- script_description = "Adds (alpha) fadings to selected lines, also karaoke."
- script_author = "FichteFoll"
- script_version = "1.1"
- script_modified = "1st June 2011"
- addfade.script_name = script_name
- addfade.script_description = script_description
- addfade.script_author = script_author
- addfade.script_version = script_version
- addfade.script_modified = script_modified
- -- Dlg
- addfade.config = {
- { -- 1
- class = "label",
- x = 0, y = 0, width = 1, height = 1,
- label = "Fadein:"
- },
- { -- 2
- class = "intedit", name = "fadein",
- x = 1, y = 0, width = 1, height = 1,
- value = 0, hint = "Amount of time to add before; in ms"
- },
- { -- 3
- class = "label",
- x = 0, y = 1, width = 1, height = 1,
- label = "Fadeout:"
- },
- { -- 4
- class = "intedit", name = "fadeout",
- x = 1, y = 1, width = 1, height = 1,
- value = 0, hint = "Amount of time to append behind; in ms"
- },
- { -- 5
- class = "checkbox", name = "fade",
- x = 0, y = 2, width = 2, height = 1,
- value = true, label = "Fade transparency"
- }
- }
- -- Add the fadings
- addfade.process = function(subs,sel,config)
- for x, i in ipairs(sel) do
- local l = subs[i]
- if l.class == "dialogue" and not l.comment then
- local kara = l.text:match("{[^}]-\\k(%d+).-}")
- l.start_time = l.start_time - config.fadein
- l.end_time = l.end_time + config.fadeout
- if config.fade then
- local prevfadein, prevfadeout = l.text:match("{[^}]-\\fad%((%d+),(%d+)%)")
- if prevfadein and prevfadeout then
- l.text = l.text:gsub("({[^}]-\\fad)%((%d+),(%d+)%)",
- string.format("%%1(%d,%d)",tonumber(prevfadein)+config.fadein, tonumber(prevfadeout)+config.fadeout), 1)
- else
- l.text = string.format("{\\fad(%d,%d)}", config.fadein, config.fadeout) .. l.text
- end
- end
- if kara and config.fadein >= 10 then
- l.text = l.text:gsub("({[^}]-\\k%d*.*})", "{\\k".. config.fadein/10 .."}%1", 1)
- end
- end
- subs[i] = l
- end
- end
- -- Macro callback
- addfade.load_macro = function(subs,sel)
- local result, config
- repeat
- result, config = aegisub.dialog.display(addfade.config)
- if not result then return end
- until (config.fadein >= 0 and config.fadeout >= 0) and (config.fadein ~= 0 or config.fadeout ~= 0)
- addfade.process(subs,sel,config)
- aegisub.set_undo_point("\""..addfade.script_name.."\"")
- end
- --#####################################################################################--
- -----------------------------------------------------------------------------------------
- --#####################################################################################--
- remfade = {--[[
- Removes fadings at start or end of selected lines,
- by adjusting \fad or just cutting down.
- Also supports \k-tagged karaoke lines but may be
- brocken with non-faded lines.
- 1.1
- 02-06-2011
- FichteFoll
- ]]}
- -- Variables
- script_name = "Remove Fadings"
- script_description = "Removes (alpha) fadings of selected lines."
- script_author = "FichteFoll"
- script_version = "1.1"
- script_modified = "2nd June 2011"
- remfade.script_name = script_name
- remfade.script_description = script_description
- remfade.script_author = script_author
- remfade.script_version = script_version
- remfade.script_modified = script_modified
- -- Dlg
- remfade.config = {
- { -- 1
- class = "label",
- x = 0, y = 0, width = 1, height = 1,
- label = "Fadein:"
- },
- { -- 2
- class = "intedit", name = "fadein",
- x = 1, y = 0, width = 1, height = 1,
- value = 0, hint = "Amount of time to remove at the start; in ms"
- },
- { -- 3
- class = "label",
- x = 0, y = 1, width = 1, height = 1,
- label = "Fadeout:"
- },
- { -- 4
- class = "intedit", name = "fadeout",
- x = 1, y = 1, width = 1, height = 1,
- value = 0, hint = "Amount of time to remove at the end; in ms"
- },
- { -- 5
- class = "checkbox", name = "auto",
- x = 0, y = 2, width = 2, height = 1,
- value = 1, label = "Auto",hint = "Just removes previous fadeings"
- }
- }
- -- Remove the fadings
- remfade.process = function(subs, sel, config)
- for x, i in ipairs(sel) do
- local l = subs[i]
- if l.class == "dialogue" and not l.comment then
- local before, prevfadein, prevfadeout, after = l.text:match("{([^}]-)\\fad%((%d+),(%d+)%)(.-)}")
- prevfadein, prevfadeout = tonumber(prevfadein), tonumber(prevfadeout)
- local newfadein, newfadeout = 0, 0
- if config.auto then
- local kara_before, kara, kara_after = l.text:match("{([^}]-)\\k(%d+)(.-)}{[^}]-\\k%d+.-}")
- local kara = tonumber(kara)
- if prevfadein and prevfadein > 0 and prevfadeout and prevfadeout > 0 then
- newfadein, newfadeout = prevfadein, prevfadeout
- if before:len() > 0 or after:len() > 0 then
- aegisub.log("found some weird stuff that should not be there\n")
- l.text = l.text:gsub("({[^}]-)\\fad%((%d+),(%d+)%)", "%1", 1)
- else
- l.text = l.text:gsub("{\\fad%((%d+),(%d+)%)}", "", 1)
- end
- end
- if kara and kara > 0 then
- if kara*10 < prevfadein then
- newfadein = kara*10
- if kara_before:len() > 0 or kara_after:len() > 0 then
- l.text = l.text:gsub("({[^}]-)\\k%d+(.-}{[^}]-\\k%d+.-})", "%1%2", 1)
- else
- l.text = l.text:gsub("{\\k%d+}({[^}]-\\k%d+.-})", "%1", 1)
- end
- end
- end
- l.start_time = l.start_time + newfadein
- l.end_time = l.end_time - newfadeout
- else
- local kara = tonumber(l.text:match("{[^}]-\\k(%d+).-}"))
- l.start_time = l.start_time + config.fadein
- l.end_time = l.end_time - config.fadeout
- if prevfadein and prevfadein > 0 and prevfadeout and prevfadeout > 0 then
- local newfadein, newfadeout = prevfadein - config.fadein, prevfadeout - config.fadeout
- if newfadein > 0 or newfadeout > 0 then
- l.text = l.text:gsub("({[^}]-\\fad)%((%d+),(%d+)%)",
- string.format("%%1(%d,%d)", (newfadein > 0 and newfadein or 0), (newfadeout > 0 and newfadeout or 0)), 1)
- else
- l.text = l.text:gsub("({[^}]-)\\fad%((%d+),(%d+)%)", "%1", 1)
- end
- end
- if kara then
- local newkara = kara-config.fadein / 10
- if newkara > 0 then
- l.text = l.text:gsub("({[^}]-)\\k%d+(.-})", "%1\\k".. kara/10 .."%2", 1)
- else
- local spacer, kara2 = l.text:match("{[^}]-\\k%d+.-}(.-){[^}]-\\k(%d+).-}")
- local newkara2 = tonumber(kara2) + newkara -- supposed to be negative here
- if newkara2 > 0 and spacer:len() > 0 then
- l.text = l.text:gsub("({[^}]-)\\k%d+(.-}.-{[^}]-)\\k%d+(.-})", "%1\\k0%2\\k".. newkara2/10 .."%3", 1)
- elseif newkara2 > 0 then
- l.text = l.text:gsub("({[^}]-)\\k%d+(.-}.-{[^}]-)\\k%d+(.-})", "%1%2\\k".. newkara2/10 .."%3", 1)
- elseif spacer:len() == 0 then
- l.text = l.text:gsub("({[^}]-)\\k%d+(.-}.-{[^}]-\\k%d+.-})", "%1%2", 1)
- else
- -- no idea what to do in this case...
- end
- end
- end
- end
- end
- subs[i] = l
- end
- end
- -- Macro callback
- remfade.load_macro = function(subs,sel)
- local result, config
- -- Check for default values in first line
- for x, i in ipairs(sel) do
- local l = subs[i]
- if l.class == "dialogue" and not l.comment then
- local prevfadein, prevfadeout = l.text:match("{[^}]-\\fad%((%d+),(%d+)%)")
- prevfadein, prevfadeout = tonumber(prevfadein), tonumber(prevfadeout)
- local kara = tonumber(l.text:match("{[^}]-\\k(%d+).-}{[^}]-\\k%d+.-}"))
- if kara and kara > 0 then
- remfade.config[2].value = kara*10
- elseif prevfadein and prevfadein > 0 then
- remfade.config[2].value = prevfadein
- end
- if prevfadeout and prevfadeout > 0 then remfade.config[4].value = prevfadeout end
- break
- end
- end
- -- Show dialog
- repeat
- result, config = aegisub.dialog.display(remfade.config)
- if not result then return end
- until (config.fadein >= 0 and config.fadeout >= 0) and (config.fadein ~= 0 or config.fadeout ~= 0)
- remfade.process(subs, sel, config)
- aegisub.set_undo_point("\""..remfade.script_name.."\"")
- end
- -- Register macros
- aegisub.register_macro(addfade.script_name, addfade.script_description, addfade.load_macro)
- aegisub.register_macro(remfade.script_name, remfade.script_description, remfade.load_macro)
- -- Display
- script_name = "Fadings"
- script_description = "Adds and removes (alpha) fadings of selected lines, also karaoke."
Advertisement
Add Comment
Please, Sign In to add comment