Fix for styles table in auto3, broken karaoke-splitter...

Originally committed to SVN as r1163.
This commit is contained in:
Niels Martin Hansen 2007-05-04 01:43:00 +00:00
parent 6087314600
commit 81b8660348
5 changed files with 112 additions and 2 deletions
aegisub
auto3
automation

View file

@ -105,6 +105,8 @@ namespace Automation4 {
Auto3Filter(const wxString &_name, const wxString &_description, Auto3Interpreter *_script); Auto3Filter(const wxString &_name, const wxString &_description, Auto3Interpreter *_script);
void ProcessSubs(AssFile *subs, wxWindow *export_dialog); void ProcessSubs(AssFile *subs, wxWindow *export_dialog);
virtual ~Auto3Filter() { }
}; };

View file

@ -241,6 +241,8 @@ namespace Automation4 {
public: public:
static int LuaRegister(lua_State *L); static int LuaRegister(lua_State *L);
virtual ~LuaFeatureFilter() { }
void ProcessSubs(AssFile *subs, wxWindow *export_dialog); void ProcessSubs(AssFile *subs, wxWindow *export_dialog);
}; };

View file

@ -674,8 +674,8 @@ static void MakeStylesTable(lua_State *L, struct Auto3Interpreter *script)
lua_settable(L, -3); lua_settable(L, -3);
} }
// Finally, make 'n' key in table // Finally, make -1 key in table (because the name 'n' might clash with a style name)
lua_pushstring(L, "n"); lua_pushnumber(L, -1);
lua_pushnumber(L, n); lua_pushnumber(L, n);
lua_settable(L, -3); lua_settable(L, -3);
} }

View file

@ -9,7 +9,11 @@ name = "Reading data demonstration"
description = "This is a demonstration of how to access the various data passed to an Automation script. It loops over the data structures provided, and dumps them to the debug console." description = "This is a demonstration of how to access the various data passed to an Automation script. It loops over the data structures provided, and dumps them to the debug console."
configuration = {} configuration = {}
include "karaskel-base.auto3"
function process_lines(meta, styles, lines, config) function process_lines(meta, styles, lines, config)
karaskel.parse_syllable_data(meta, styles, lines)
-- This makes an alias for the aegisub.output_debug function. Remember that functions are first-class values in Lua. -- This makes an alias for the aegisub.output_debug function. Remember that functions are first-class values in Lua.
-- The 'local' keyword makes the 'out' variable local to this function -- The 'local' keyword makes the 'out' variable local to this function
local out = aegisub.output_debug local out = aegisub.output_debug

View file

@ -67,6 +67,107 @@ function karaskel.trace(s)
end end
end end
-- parse_syllable_data
-- Generates the line.karaoke table
-- This was moved to Lua code from the C++ code for various technical reasons
function karaskel.parse_syllable_data(meta, styles, lines)
for i = 0, lines.n-1 do
local l = lines[i]
local ltext = l.text
local indrawing = false
l.karaoke = { n = 0 }
local cursyl = {
duration = 0,
kind = "",
text = "",
text_stripped = ""
}
l.text_stripped = ""
while ltext ~= "" do
-- Find text part up until next tag start
local tagstart = string.find(ltext, "{")
local textpart
if not tstart then
-- No tag start was found, rest of line is text
textpart = ltext
ltext = ""
else
-- Tag start was found, cut text part out
textpart = string.sub(ltext, 1, tagstart)
ltext = string.sub(ltext, tagstart+1) -- skip over opening brace
end
-- Append text to relevant strings
if not indrawing then
l.text_stripped = l.text_stripped .. textpart
cursyl.text_stripped = cursyl.text_stripped .. textpart
end
cursyl.text = cursyl.text .. textpart
-- If we're out of line text, we're done
if ltext == "" then
break
end
-- Now find the tag group end
local tagend = string.find(ltext, "}")
local tagpart
if not tagend then
tagpart = string.sub(ltext, tagstart+1)
ltext = ""
else
tagpart = string.sub(ltext, 1, tagend)
ltext = string.sub(ltext, tagend+1)
end
-- Look for interesting tags (karaoke and drawing)
while tagpart ~= "" do
local tagstart, tagend, tag, param = string.find(tagpart, "\\([kKp]%a*)(%d+)")
if tag and string.find(tag, "^[kK]") then
-- Karaoke tag, split stuff up
-- If the kara tag wasn't the first thing in the group, prepend previous stuff
if tagstart > 1 then
cursyl.text = cursyl.text .. "{" .. string.sub(tagpart, 1, tagstart) .. "}"
end
-- Store last tag to table and prepare new one
l.karaoke[l.karaoke.n] = cursyl
l.karaoke.n = l.karaoke.n + 1
cursyl = {
duration = param,
kind = tag,
text = "",
text_stripped = ""
}
-- Remove up to and including this tag from the tagpart
tagpart = string.sub(tagpart, tagend)
elseif tag and tag == "p" then
-- Switch drawing-mode on/off
indrawing = param > 0
else
-- No more interesting tags here
cursyl.text = cursyl.text .. "{" .. tagpart .. "}"
break
end
end
end
l.karaoke[l.karaoke.n] = cursyl
l.karaoke.n = l.karaoke.n + 1
end
end
-- precalc_syllable_data -- precalc_syllable_data
-- Adds various extra fields to the line and syllable tables -- Adds various extra fields to the line and syllable tables
-- See the implementation and/or Aegisub help file for more information -- See the implementation and/or Aegisub help file for more information
@ -277,6 +378,7 @@ function karaskel.process_lines(meta, styles, lines, config)
karaskel.trace("new skeleton") karaskel.trace("new skeleton")
karaskel.trace("skel_process_lines") karaskel.trace("skel_process_lines")
-- Do a little pre-calculation for each line and syllable -- Do a little pre-calculation for each line and syllable
karaskel.parse_syllable_data(meta, styles, lines)
karaskel.precalc_syllable_data(meta, styles, lines) karaskel.precalc_syllable_data(meta, styles, lines)
karaskel.trace("skel_process_lines:2") karaskel.trace("skel_process_lines:2")
-- A var for the new output -- A var for the new output