diff options
author | garret <garret@airmail.cc> | 2021-07-10 16:24:32 +0100 |
---|---|---|
committer | garret <garret@airmail.cc> | 2021-07-10 16:24:32 +0100 |
commit | 659ed31a8c771d2855774cd0e3bb33f8f8d6a4f7 (patch) | |
tree | 687b9d9cc0e0a4e8c39b3fc7095b87a0836ee05b | |
parent | 3d75bf9c451deb2f8b0fb6140c7d3da630545b54 (diff) | |
download | aegisub-scripts-659ed31a8c771d2855774cd0e3bb33f8f8d6a4f7.tar.gz aegisub-scripts-659ed31a8c771d2855774cd0e3bb33f8f8d6a4f7.tar.bz2 aegisub-scripts-659ed31a8c771d2855774cd0e3bb33f8f8d6a4f7.zip |
add k->a
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | karaoke2alpha.lua | 65 |
2 files changed, 71 insertions, 0 deletions
@@ -60,6 +60,12 @@ Replaces `--` with `—`. I do not have an em-dash key on my keyboard. +### K-Timing -> Alpha Timing + +does what it says on the tin. + +originally created to convert stuff that should've been alpha-timed in the first place, but also makes new alpha-timing easier + ### Scenebleed Detector Finds scenebleeds in the selected lines, and marks them with an effect (`bleed`). diff --git a/karaoke2alpha.lua b/karaoke2alpha.lua new file mode 100644 index 0000000..602554f --- /dev/null +++ b/karaoke2alpha.lua @@ -0,0 +1,65 @@ +script_name="K-Timing -> Alpha Timing" +script_description="does what it says on the tin.\noriginally to convert stuff that should've been alpha-timed in the first place, but could also make new alpha-timing easier" +script_author = "garret" +script_version = "2021-07-10" +include("utils.lua") + +-- logging stuff, for testing +--[[inspect = require 'inspect' +function log(level, msg) + if type(level) ~= "number" then + level = msg + level = 4 + end + if type(msg) == "table" then + msg = inspect(msg) + end + aegisub.log(level, tostring(msg) .. "\n") +end]] + +function get_visible(parsed_line, index) + local res = "" + for i=1,index do -- for every syl up to the current one + res = res..parsed_line[i].text -- add to the result + end + return res +end + +function get_invisible(parsed_line, index) + local res = "" + for i=index+1,#parsed_line do -- for every syl from the next one to the end + res = res..parsed_line[i].text -- add to result + end + return res +end + +function main(sub, sel) + for i=#sel,1,-1 do + local line=sub[sel[i]] + local parsed = aegisub.parse_karaoke_data(line) + for j=1,#parsed do + visible = get_visible(parsed, j) + invisible = get_invisible(parsed, j) + if invisible ~= nil then + text = visible.."{\\alpha&HFF&}"..invisible + else + text = visible + end + local syl = parsed[j] + local new = util.copy(line) + new.text = text + new.start_time = syl.start_time + line.start_time -- just the syl on its own returns the offset from the line + if j ~= #parsed then + new.end_time = syl.end_time + line.start_time + else + new.end_time = line.end_time + end + sub.insert(sel[i]+j,new) -- 1 line after for first syl, 2 for 2nd syl, etc + end + line.comment = true + sub[sel[i]]=line + end + aegisub.set_undo_point(script_name) +end + +aegisub.register_macro(script_name, script_description, main) |