| blc - Simple program for rendering QLC+ workspaces properly/without crashing. Developed into BLC2.
git clone https://benconnors.ca/git-repos/blc |
prcons.py (2061B) - raw
1 #!/usr/bin/env python3 2 3 """Basic console interface for running pre-rendered functions. 4 5 Supports either pre-rendering a function from a workspace or loading a pickled pre-render from 6 the disk. 7 """ 8 9 import pickle 10 import sys 11 import time 12 13 from blc.workspace import Workspace, PreRenderable 14 from blc.audio import DefaultAudioPlayer 15 from blc.output import LightingOutput 16 17 __version__ = "0.0.1" 18 19 class DummyOutput(LightingOutput): 20 """Output that prints changed values to the console.""" 21 def set_values(self, values): 22 for c,v in values: 23 univ, addr = c 24 if self.values[addr] != v: 25 print("U%1d C%3d to %3d" % (univ, addr, v)) 26 self.values[addr] = v 27 28 def __init__(self): 29 self.values = {c: 0 for c in range(1,513)} 30 31 minnx = 10 32 aminnx = minnx/1000 33 34 print("PRCons v%s" % __version__) 35 print() 36 if len(sys.argv) == 3: 37 w = Workspace.load(sys.argv[1]) 38 f = w.functions[int(sys.argv[2])] 39 40 if not issubclass(type(f), PreRenderable): 41 raise ValueError("Function must be PreRenderable!") 42 43 print("Rendering...") 44 render = f.render_all(minnx=minnx) 45 elif len(sys.argv) == 2: 46 print("Loading from %s..." % sys.argv[1]) 47 with open(sys.argv[1], "rb") as f: 48 render = pickle.load(f) 49 else: 50 print("Usage: %s <workspace> <function id>" % sys.argv[0]) 51 print(" %s <pickled render>" % sys.argv[0]) 52 sys.exit(1) 53 54 input("Ready, press enter to start: ") 55 print("Starting show") 56 output = DummyOutput() 57 for n, (values, acues) in enumerate(render, 1): 58 values = list(values) 59 acues = list(acues) 60 print("Step", n) 61 start = time.monotonic() 62 while values or acues: 63 t = 1000*(time.monotonic() - start) 64 while values and values[0][0] < t: 65 output.set_values(values.pop(0)[1]) 66 while acues and acues[0][0] < t: 67 fname = acues.pop(0)[2] 68 print("Playing", fname) 69 DefaultAudioPlayer(fname).play() 70 time.sleep(aminnx) 71 print("Done step", n) 72 input("Press enter to continue: ")