|
5 | 5 | import subprocess
|
6 | 6 | import signal
|
7 | 7 | import argparse
|
| 8 | +import socket |
| 9 | +from time import sleep |
8 | 10 |
|
| 11 | +# Argument handling |
9 | 12 | parser = argparse.ArgumentParser(description="Run a specific chroma animation script.")
|
10 | 13 | parser.add_argument('animation',
|
11 | 14 | metavar='animation',
|
12 | 15 | help='One of these animations: '+string.join(os.listdir('animations/'),', '),
|
13 | 16 | choices=os.listdir('animations/'))
|
14 |
| - |
15 | 17 | args = parser.parse_args()
|
16 |
| - |
17 | 18 | animation = args.animation
|
18 | 19 |
|
19 |
| -p = subprocess.Popen(['python','animations/%s/main.py'%animation]) |
| 20 | +# Open emulator if there's no OSC responsive on that port already |
| 21 | +try: |
| 22 | + sys.path.append("./osc") |
| 23 | + from osc import OSCClient,OSCMessage |
| 24 | + s=OSCClient() |
| 25 | + s.connect(('localhost',11661)) |
| 26 | + # asychronous, so send a bunch to get a potential exception. |
| 27 | + for x in range(10): |
| 28 | + s.send(OSCMessage("poop")) |
| 29 | +except Exception,e: |
| 30 | + if '[Errno 61]' in str(e): |
| 31 | + print "Starting emulator, since it doesn't seem to be running yet." |
| 32 | + os.system('emulator/lights_emulator > /dev/null &') |
| 33 | + emu_up = False |
| 34 | + while not emu_up: |
| 35 | + try: |
| 36 | + # asychronous, so send a bunch to get a potential exception. |
| 37 | + for x in range(10): |
| 38 | + s.send(OSCMessage("poop")) |
| 39 | + emu_up = True |
| 40 | + except Exception,e: |
| 41 | + if not '[Errno 61]' in str(e): |
| 42 | + emu_up = True |
| 43 | + else: |
| 44 | + sleep(0.1) |
| 45 | + |
| 46 | +# Start the animation with osc added to the path. |
| 47 | +p = subprocess.Popen(['env','PYTHONPATH=./osc:$PYTHONPATH','python','animations/%s/main.py'%animation]) |
20 | 48 |
|
21 | 49 | print "Running animation %s"%animation
|
22 | 50 |
|
|
0 commit comments