diff options
author | garret <garret@airmail.cc> | 2021-08-09 00:38:03 +0100 |
---|---|---|
committer | garret <garret@airmail.cc> | 2021-08-09 00:38:03 +0100 |
commit | cb9169f2d5671223db7c9d8e4b384cb3075ff676 (patch) | |
tree | 2f0f46c9a746402c859fe026bc03ae022d76dfbc /karaoke2alpha.lua | |
parent | a69f8996eff102eb00726d7a5bd31278c048e557 (diff) | |
download | aegisub-scripts-cb9169f2d5671223db7c9d8e4b384cb3075ff676.tar.gz aegisub-scripts-cb9169f2d5671223db7c9d8e4b384cb3075ff676.tar.bz2 aegisub-scripts-cb9169f2d5671223db7c9d8e4b384cb3075ff676.zip |
minor bugfix, add comments, improve (?) code readability, semver
Diffstat (limited to 'karaoke2alpha.lua')
-rw-r--r-- | karaoke2alpha.lua | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/karaoke2alpha.lua b/karaoke2alpha.lua index 602554f..3e89139 100644 --- a/karaoke2alpha.lua +++ b/karaoke2alpha.lua @@ -1,21 +1,22 @@ 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_description="does what it says on the tin." script_author = "garret" -script_version = "2021-07-10" +script_version = "1.0.1" include("utils.lua") -- logging stuff, for testing ---[[inspect = require 'inspect' +--[[inspect = require 'inspect' -- luarocks install inspect function log(level, msg) - if type(level) ~= "number" then - level = msg - level = 4 + if type(level) ~= "number" then -- if no actual level provided + msg = level -- set the non-level as the message + level = 4 -- set log level - i'm using this for debugging, so 4 is relatively sane imo end if type(msg) == "table" then - msg = inspect(msg) + msg = inspect(msg) -- actually see what's in the table end aegisub.log(level, tostring(msg) .. "\n") end]] +-- i should really put this stuff in a separate file or something but cba function get_visible(parsed_line, index) local res = "" @@ -34,30 +35,32 @@ function get_invisible(parsed_line, index) 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 + for x=#sel,1,-1 do + local line=sub[sel[x]] + local parsed = aegisub.parse_karaoke_data(line) -- magic function that gets all the stuff about the karaoke + for i=1,#parsed do -- for every syl in the karaoke + visible = get_visible(parsed, i) + invisible = get_invisible(parsed, i) + if invisible ~= "" then -- if there's still invisible stuff left + text = visible.."{\\alpha&HFF&}"..invisible -- add an alpha tag and slap the invisible stuff on the end + else -- if it's all visible + text = visible -- don't need the alpha any more end - local syl = parsed[j] + local syl = parsed[i] local new = util.copy(line) - new.text = text + new.text = text -- make a new line for this syl + -- set line start time 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 + -- set line end time + if i ~= #parsed then -- if there's still invisible stuff left + new.end_time = syl.end_time + line.start_time -- end time is the syl's else - new.end_time = line.end_time + new.end_time = line.end_time -- end time is the whole line's (i don't think this actually makes a difference but may as well) end - sub.insert(sel[i]+j,new) -- 1 line after for first syl, 2 for 2nd syl, etc + sub.insert(sel[x] + i,new) -- add new lines (+1 line for first syl, +2 for 2nd syl, etc) end - line.comment = true - sub[sel[i]]=line + line.comment = true -- don't want to see the karaoke any more + sub[sel[x]]=line end aegisub.set_undo_point(script_name) end |