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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/usr/bin/env python3
"""Basic console interface for running pre-rendered functions.
Supports either pre-rendering a function from a workspace or loading a pickled pre-render from
the disk.
"""
import pickle
import sys
import time
from blc.workspace import Workspace, PreRenderable
from blc.audio import DefaultAudioPlayer
from blc.output import LightingOutput
__version__ = "0.0.1"
class DummyOutput(LightingOutput):
"""Output that prints changed values to the console."""
def set_values(self, values):
for c,v in values:
univ, addr = c
if self.values[addr] != v:
print("U%1d C%3d to %3d" % (univ, addr, v))
self.values[addr] = v
def __init__(self):
self.values = {c: 0 for c in range(1,513)}
minnx = 10
aminnx = minnx/1000
print("PRCons v%s" % __version__)
print()
if len(sys.argv) == 3:
w = Workspace.load(sys.argv[1])
f = w.functions[int(sys.argv[2])]
if not issubclass(type(f), PreRenderable):
raise ValueError("Function must be PreRenderable!")
print("Rendering...")
render = f.render_all(minnx=minnx)
elif len(sys.argv) == 2:
print("Loading from %s..." % sys.argv[1])
with open(sys.argv[1], "rb") as f:
render = pickle.load(f)
else:
print("Usage: %s <workspace> <function id>" % sys.argv[0])
print(" %s <pickled render>" % sys.argv[0])
sys.exit(1)
input("Ready, press enter to start: ")
print("Starting show")
output = DummyOutput()
for n, (values, acues) in enumerate(render, 1):
values = list(values)
acues = list(acues)
print("Step", n)
start = time.monotonic()
while values or acues:
t = 1000*(time.monotonic() - start)
while values and values[0][0] < t:
output.set_values(values.pop(0)[1])
while acues and acues[0][0] < t:
fname = acues.pop(0)[2]
print("Playing", fname)
DefaultAudioPlayer(fname).play()
time.sleep(aminnx)
print("Done step", n)
input("Press enter to continue: ")
|