summaryrefslogtreecommitdiff
path: root/prstore.py
blob: 06d10160908cca931e5ff35dc44a787bb419869f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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 <workspace file> <prerenderable id> [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!")