diff options
Diffstat (limited to 'anim/tools')
| -rw-r--r-- | anim/tools/chart.py | 73 |
1 files changed, 63 insertions, 10 deletions
diff --git a/anim/tools/chart.py b/anim/tools/chart.py index 998e704..720e356 100644 --- a/anim/tools/chart.py +++ b/anim/tools/chart.py @@ -1,13 +1,19 @@ #!/usr/bin/env python3 """The designer's motion instrument (design/motion/motion.py: timing chart, -five rule checks, contact sheets), told where canim's panels are now. +rule checks, contact sheets), told where canim's panels are now and what +each scene's captions say. chart.py chart|auto|sheet|onion|track VIDEO ... as motion.py takes them -The video's file name (fib-1080.mp4 -> fib) picks its regions. +The video's file name (fib-1080.mp4 -> fib) picks its regions, and its +captions: the strings `scenes/NAME.zig` says (`says.line`), in order. The +CAPTION check (motion.py's) gets one more line here: a caption up for less +than its reading time, 90 f and 3.6 f a character as shown. """ -import os, sys -sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "design", "motion")) +import os, re, sys +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(HERE, "..", "..", "design", "motion")) +import numpy as np import motion W = motion.W @@ -33,11 +39,11 @@ def split(drawing, view, source, disasm, slots, backtrace=0): out["backtrace"] = (976, right + ph(17) + 12 + ph(slots) + 12, 880, ph(backtrace)) return out -# The clock is under the name the instrument gives to words that are not panels ("head"): -# its progress line moves with every step and must not count as a panel starting. The -# minimap (1664 to 1856 by 912 to 1020) is in no region: it mirrors the panels' changes, -# and the instrument has no name for a secondary region. -words = {"head": (0, 888, 1656, 46), "caption": (0, 934, 1656, 146)} +# The words that are not panels (motion.WORDS): the clock (its count, ranged right at 1648, +# changes in a frame by design), the caption (its 1400 from the margin), and the minimap at +# the caption band's right end, secondary action. The caption's box starts under the clock's count +# and the run's step counter (912 to 934). +words = {"clock": (0, 888, 1656, 46), "caption": (0, 940, 1464, 140), "minimap": (1664, 912, 192, 108)} none, beside, subject = split(0, 0, 14, 17, 8, 4), split(152, 152, 8, 17, 8), split(296, 200, 10, 9, 6) motion.REGIONS.update({ "fib": {**subject, **words}, @@ -52,7 +58,54 @@ motion.REGIONS.update({ "gallery": {**beside, **words}, }) _regions_for = motion.regions_for -motion.regions_for = lambda video, name: _regions_for(video, name or os.path.basename(video).split("-")[0].split(".")[0]) +scene = lambda video: os.path.basename(video).split("-")[0].split(".")[0] +motion.regions_for = lambda video, name: _regions_for(video, name or scene(video)) + +STRING = r'"((?:[^"\\]|\\.)*)"' + +def captions(name): + """The scene's captions in the order it says them: each `says.line(s, "...")`, and each + string of an array a `for` loop says.""" + path = os.path.join(HERE, "..", "scenes", name + ".zig") + if not os.path.exists(path): + return None + src = open(path).read() + arrays = {m.group(1): re.findall(STRING, m.group(2), re.S) for m in re.finditer(r"const (\w+) = \[_\]\[\]const u8\{(.*?)\};", src, re.S)} + out = [] + for m in re.finditer(r"says\.line\(s, " + STRING + r"\)|for \((\w+)\)", src): + if m.group(1) is not None: + out.append(m.group(1)) + elif m.group(2) in arrays: + out.extend(arrays[m.group(2)]) + return out + +def shown(text): + """Characters as the caption shows them: no backticks, no line break, an escape one.""" + text = re.sub(r"\\(.)", r"\1", text.replace("\\n", "")) + return len(text.replace("`", "")) + +_lint = motion.lint +def lint(names, counts, soft, sizes, fps, ev): + out = [line for line in _lint(names, counts, soft, sizes, fps, ev) if line != " none"] + said = captions(lint.scene) if lint.scene else None + cap = names.index("caption") if "caption" in names else None + if said is not None and cap is not None: + on = motion.busy(counts, soft) + changes = [(a, b) for a, b in motion.runs(on[:, cap]) if b - a >= 3] + ends = [c[0] for c in changes[1:]] + [len(on)] + # An arrival is a change after which the caption is up longer than the gap between leaving and arriving. + arrivals = [(b, nxt - b - 1) for (a, b), nxt in zip(changes, ends) if nxt - b - 1 > 6] + if len(arrivals) != len(said): + out.append(f" CAPTION ? {len(arrivals)} captions arrive in the video, the scene says {len(said)}: reading times not checked") + else: + short = [f"{b / fps:.2f} ({up} f of {90 + 3.6 * shown(t):.0f})" for (b, up), t in zip(arrivals, said) if up < 90 + 3.6 * shown(t)] + if short: + out.append(f" CAPTION {len(short):3d} up under its reading time, 90 f + 3.6 f a character: " + ", ".join(short[:4]) + (" ..." if len(short) > 4 else "")) + return out or [" none"] +motion.lint = lint +lint.scene = None if __name__ == "__main__": + video = next((a for a in sys.argv[2:] if a.endswith(".mp4")), None) + lint.scene = scene(video) if video else None motion.main() if hasattr(motion, "main") else sys.exit("design/motion/motion.py has no main()") |
