From 71b14ecc7428943a343ac72e996bb5153d637a8b Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 15 Apr 2013 15:42:52 -0700 Subject: [PATCH] Select the right things in the select overlaps macro. Closes #1594. --- .../automation/autoload/select-overlaps.lua | 67 +++++++------------ .../automation/autoload/select-overlaps.moon | 41 ++++++++++++ 2 files changed, 67 insertions(+), 41 deletions(-) create mode 100644 aegisub/automation/autoload/select-overlaps.moon diff --git a/aegisub/automation/autoload/select-overlaps.lua b/aegisub/automation/autoload/select-overlaps.lua index e6bf44f79..0d9b6808c 100644 --- a/aegisub/automation/autoload/select-overlaps.lua +++ b/aegisub/automation/autoload/select-overlaps.lua @@ -1,46 +1,31 @@ --- Copyright (c) 2010, Thomas Goyne --- --- Permission to use, copy, modify, and distribute this software for any --- purpose with or without fee is hereby granted, provided that the above --- copyright notice and this permission notice appear in all copies. --- --- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES --- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF --- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR --- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES --- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN --- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF --- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - local tr = aegisub.gettext - -script_name = tr"Select overlaps" -script_description = tr"Select lines which begin while another non-comment line is active" +script_name = tr("Select overlaps") +script_description = tr("Select lines which begin while another non-comment line is active") script_author = "Thomas Goyne" -script_version = "1" - -function select_overlaps(subs) - -- filter subtitles lines to just dialogue lines and sort them by time - local dialogue = {} - for i = 1,#subs do - local line = subs[i] - if line.class == "dialogue" then - line.i = i - 1 - table.insert(dialogue, line) - end +script_version = "2" +local select_overlaps +select_overlaps = function(subs) + local dialogue = { } + for i, line in ipairs(subs) do + if line.class == "dialogue" then + line.i = i + table.insert(dialogue, line) end - table.sort(dialogue, function(a,b) return a.start_time < b.start_time end) - - local end_time = 0 - local overlaps = {} - for i,line in ipairs(dialogue) do - if line.start_time >= end_time then - end_time = line.end_time - else - table.insert(overlaps, line.i) - end + end + table.sort(dialogue, function(a, b) + return a.start_time < b.start_time or (a.start_time == b.start_time and a.i < b.i) + end) + local end_time = 0 + local overlaps = { } + local _list_0 = dialogue + for _index_0 = 1, #_list_0 do + local line = _list_0[_index_0] + if line.start_time >= end_time then + end_time = line.start_time + else + table.insert(overlaps, line.i) end - return overlaps + end + return overlaps end - -aegisub.register_macro(script_name, script_description, select_overlaps) +return aegisub.register_macro(script_name, script_description, select_overlaps) diff --git a/aegisub/automation/autoload/select-overlaps.moon b/aegisub/automation/autoload/select-overlaps.moon new file mode 100644 index 000000000..7b9d3ae70 --- /dev/null +++ b/aegisub/automation/autoload/select-overlaps.moon @@ -0,0 +1,41 @@ +-- Copyright (c) 2013, Thomas Goyne +-- +-- Permission to use, copy, modify, and distribute this software for any +-- purpose with or without fee is hereby granted, provided that the above +-- copyright notice and this permission notice appear in all copies. +-- +-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +-- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +-- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +-- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +tr = aegisub.gettext + +export script_name = tr"Select overlaps" +export script_description = tr"Select lines which begin while another non-comment line is active" +export script_author = "Thomas Goyne" +export script_version = "2" + +select_overlaps = (subs) -> + -- filter subtitles lines to just dialogue lines and sort them by time + dialogue = {} + for i, line in ipairs subs + if line.class == "dialogue" + line.i = i + table.insert dialogue, line + table.sort dialogue, (a,b) -> + a.start_time < b.start_time or (a.start_time == b.start_time and a.i < b.i) + + end_time = 0 + overlaps = {} + for line in *dialogue + if line.start_time >= end_time + end_time = line.start_time + else + table.insert overlaps, line.i + overlaps + +aegisub.register_macro script_name, script_description, select_overlaps