From bf09c18f0c6ff4b14f4fad1909f9839d0a3aeca2 Mon Sep 17 00:00:00 2001 From: odrling Date: Sat, 3 Aug 2019 20:42:33 +0200 Subject: [PATCH] add karaoke-adjust-1sec with mugenizer --- README.md | 11 +++++ karaoke-adjust-1sec.lua | 104 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 karaoke-adjust-1sec.lua diff --git a/README.md b/README.md index 7fb41a3..435fc63 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,14 @@ becomes shimese {\c&H003D45FF&\3c&H00020261&\4c&H00020261&}atsuki yume no {\c&H002092FD&\3c&H00003364&\4c&H00003364&}makuake wo +Karaoke 1sec adjust lead-in +--------------------------- + +Adds a `{\k100}` at the beginning of your line so your line appears 1s earlier (and people will be able to sing). + +Mugenizer +--------- + +Select all the lines of your karaoke, launch the Mugenizer and it will remove our lead-ins and add mugen's karaoke script. +Then in "Automation" you can run "Apply karaoke template" and you're ready to submit your karaoke to Mugen. + diff --git a/karaoke-adjust-1sec.lua b/karaoke-adjust-1sec.lua new file mode 100644 index 0000000..dae8cfc --- /dev/null +++ b/karaoke-adjust-1sec.lua @@ -0,0 +1,104 @@ +local tr = aegisub.gettext + +script_name = tr"Karaoke 1sec adjust lead-in" +script_description = tr"Adjust karaoke leadin to 1sec" +script_author = "Flore" +script_version = "1.00" + +include("cleantags.lua") + +leadinmsec = 1000 --lead in time can be changed here + +ktag = "\\[kK][fo]?%d+" --pattern used to detect karaoke tags + + +function hasleadin(line)--check if there is an existing lead in (2 consecutive bracket with karaoke tags at the start of the line) + return line.text:find("^{[^{}]-" .. ktag .. "[^{}]-}%s*{[^{}]-" .. ktag .. "[^{}]-}") +end + + +function removeleadin(line) + if not hasleadin(line) then + return line + end + + leadin = tonumber( line.text:match("^{[^{}]-\\[kK][fo]?(%d+)[^{}]-}%s*{[^{}]-" .. ktag .. "[^{}]-}") ) --read lead-in value + line.text = line.text:gsub("^({[^{}]-)\\[kK][fo]?%d+(.-}%s*{[^{}]-" .. ktag .. ".-})","%1%2") --remove lead in + + line.text = cleantags(line.text) --clean tags + + line.start_time = line.start_time + leadin*10 --adjust start time + + --aegisub.log(line.text) + + return line +end + + +function adjust_1sec(subs, sel) + + for _, i in ipairs(sel) do + local line = subs[i] + + line.text = cleantags(line.text) + + if( line.text:find(ktag)) then--don't do anything if there is no ktags in this line + + --start by removing existing lead-in + while hasleadin(line) do + if aegisub.progress.is_cancelled() then return end + line = removeleadin(line) + end + + --then add our lead in + + if line.start_time >= leadinmsec then + line.text = string.format("{\\k%d}%s",leadinmsec/10, line.text) + line.start_time = line.start_time - leadinmsec + + else --if line starts too early to put the needed lead in, make the line start at time 0 and fill with appropriate lead in + line.text = string.format("{\\k%d}%s",line.start_time/10, line.text) + line.start_time = 0 + end + + subs[i] = line + end + end + + aegisub.set_undo_point(tr"1sec adjust lead-in") +end + +function mugenizer(subs, sel) + local first = true + local line + + for _, i in ipairs(sel) do + + -- add mugen's magic line + if first then + line = subs[i] + line.comment = true + line.start_time = 0 + line.end_time = 0 + line.effect = "template pre-line all keeptags" + line.text = '!retime("line",$start < 900 and -$start or -900,200)!{!$start < 900 and "\\\\k" .. ($start/10) or "\\\\k90"!\\fad(!$start < 900 and $start or 300!,200)}' + subs.insert(i, line) + line.text = cleantags(line.text) + first = false + end + + line = subs[i] + if (line.text:find(ktag)) then--don't do anything if there is no ktags in this line + while hasleadin(line) do + if aegisub.progress.is_cancelled() then return end + line = removeleadin(line) + end + + subs[i] = line + end + + end +end + +aegisub.register_macro(script_name, script_description, adjust_1sec) +aegisub.register_macro(tr"Mugenizer", tr"Mugenize your subs", mugenizer)