From 08805d7464dd3e8930ce730f84a2056e31684042 Mon Sep 17 00:00:00 2001 From: Ben Connors Date: Fri, 22 Feb 2019 15:35:50 -0500 Subject: Add pre-rendering utilities - prstore uses pickle to store a pre-render to a file - prcons loads and renders the pickled pre-renders --- prstore.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 prstore.py (limited to 'prstore.py') diff --git a/prstore.py b/prstore.py new file mode 100755 index 0000000..06d1016 --- /dev/null +++ b/prstore.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +"""Pre-render functions into a file. + +Uses the pickle module to serialize the render. + +There are some caveats to this: + +- Audio filepaths are stored absolutely, so this should be run on the system that will be + running the show, or take care to ensure that the directory structure is identical +- Audio lengths are ignored +""" + +import pickle +import sys + +from blc.workspace import Workspace, PreRenderable + +if len(sys.argv) not in (3,4,): + print("Usage: %s [output file]" % sys.argv[0]) + sys.exit(1) + +minnx = 10 + +w = Workspace.load(sys.argv[1]) +func = w.functions[int(sys.argv[2])] +if not issubclass(type(func), PreRenderable): + raise ValueError("The given function may not be rendered") + +if len(sys.argv) == 4: + ofname = sys.argv[3] +else: + ofname = func.name+".pickle" + print("Storing to", ofname) + +with open(ofname, "wb") as f: + print("Rendering", func.name) + p = pickle.Pickler(f) + try: + render = func.render_all(minnx=minnx) + except ValueError: + print("Cannot render", func.name) + else: + print("Storing render") + p.dump(render) + print("Done!") -- cgit v1.2.3