Skip to content
This repository was archived by the owner on Aug 3, 2025. It is now read-only.

Commit ee33d7a

Browse files
author
Jake McGinty
committed
run.py now starts up emulator if it doesn't detect OSC is listening at the time of running. Also, will push ./osc to the PYTHONPATH so animations aren't required to add it themselves. Much cleaner this way.
1 parent 8bcd8a0 commit ee33d7a

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

run.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,46 @@
55
import subprocess
66
import signal
77
import argparse
8+
import socket
9+
from time import sleep
810

11+
# Argument handling
912
parser = argparse.ArgumentParser(description="Run a specific chroma animation script.")
1013
parser.add_argument('animation',
1114
metavar='animation',
1215
help='One of these animations: '+string.join(os.listdir('animations/'),', '),
1316
choices=os.listdir('animations/'))
14-
1517
args = parser.parse_args()
16-
1718
animation = args.animation
1819

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])
2048

2149
print "Running animation %s"%animation
2250

0 commit comments

Comments
 (0)