class ColorsOut: def __init__(self, streamclass="something"): self.client = OSCClient() self.client.connect(("localhost", 11661)) self.title = "Something went wrong" try: print "argv[0] " + sys.argv[0] print "getcwd " + os.getcwd() path = os.getcwd() + "/" + sys.argv[0] path = path.replace("main.py", "") manifest = open(path + "manifest.json") data = simplejson.load(manifest) self.title = data["name"] self.creator = data["creator"] self.description = data["description"] manifest.close() except: print "Hey we died" self.framenumber = 0 self.streamclass = streamclass def write(self, pixels): #pixels = self.crazyMofoingReorderingOfLights(pixels) chroma = ChromaMessage(pixels, self.title, self.streamclass, self.framenumber, self.creator, self.description) message = chroma.toOSC("/setcolors") #print "Sending message %s"%str(pixels) self.client.send(message) self.framenumber += 1
class ColorsOut: def __init__(self, streamclass="something"): self.client = OSCClient() self.client.connect( ("localhost",11661) ) self.title = "Something went wrong" try: print "argv[0] "+sys.argv[0] print "getcwd "+os.getcwd() path = os.getcwd()+"/"+sys.argv[0] path = path.replace("main.py","") manifest = open(path+"manifest.json") data = simplejson.load(manifest) self.title = data["name"] self.creator = data["creator"] self.description = data["description"] manifest.close() except: print "Hey we died" self.framenumber = 0 self.streamclass = streamclass def write(self, pixels): #pixels = self.crazyMofoingReorderingOfLights(pixels) chroma = ChromaMessage(pixels, self.title, self.streamclass, self.framenumber, self.creator, self.description) message = chroma.toOSC("/setcolors") self.client.send( message ) self.framenumber += 1
class ColorsOut: def __init__(self): self.client = OSCClient() self.client.connect( ("localhost",11661) ) def write(self, pixels): message = OSCMessage("/setcolors") pixels = self.crazyMofoingReorderingOfLights(pixels) message.append(pixels) self.client.send( message ) def diff(self, pixels): message = OSCMessage("/diffcolors") message.append(pixels) self.client.send( message ) def crazyMofoingReorderingOfLights(self, pixels): pixels2 = pixels[:] #make a copy so we don't kerplode someone's work """ what are we expecting? we want the back left (by the couches) of the room to be pixel 0, and by the front is the last row whereas in reality, it's the opposite. here is the order it'd be nice to have them in: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 this is the actual order: 23 22 21 20 19 16 17 18 15 14 13 12 11 10 9 8 3 2 5 4 6 *0**1**7* *=not there """ actualorder = [23,22,21,20,19,16,17,18,15,14,13,12,11,10,9,8,3,2,5,4,6,0,1,7] badcolors = [3,2,5,4,6,0,1,7] for i in range(len(actualorder)): (r,g,b) = pixels[i] r = max(0.0, min(r, 1023.0)) g = max(0.0, min(g, 1023.0)) b = max(0.0, min(b, 1023.0)) pixels2[actualorder[i]] = (r,g,b) for i in range(len(badcolors)): pixels2[badcolors[i]] = (0.0,0.0,0.0) return pixels2
class ColorsOut: def __init__(self, title="demo", streamclass="something"): self.client = OSCClient() self.client.connect( ("localhost",11661) ) self.title = title self.framenumber = 0 self.streamclass = streamclass def write(self, pixels): #pixels = self.crazyMofoingReorderingOfLights(pixels) chroma = ChromaMessage(pixels, self.title, self.streamclass, self.framenumber) message = chroma.toOSC("/setcolors") self.client.send( message ) self.framenumber += 1
metavar='animation', help='One of these animations: ' + string.join(os.listdir('animations/'), ', '), choices=os.listdir('animations/')) args = parser.parse_args() animation = args.animation # Open emulator if there's no OSC responsive on that port already try: sys.path.append("./osc") from osc import OSCClient, OSCMessage s = OSCClient() s.connect(('localhost', 11661)) # asychronous, so send a bunch to get a potential exception. for x in range(10): s.send(OSCMessage("poop")) except Exception, e: if '[Errno 61]' in str(e): print "Starting emulator, since it doesn't seem to be running yet." os.system('emulator/lights_emulator > /dev/null &') emu_up = False while not emu_up: try: # asychronous, so send a bunch to get a potential exception. for x in range(10): s.send(OSCMessage("poop")) emu_up = True except Exception, e: if not '[Errno 61]' in str(e): emu_up = True else:
from osc import OSCMessage, OSCBundle, OSCClient, OSCServer message = OSCMessage(address='/message/address') # argument can be string, int, float, bool and binary message.add('Some text argument') message.add(3) message.add(0.75) message.add(True) # create osc bundle and add a message bundle = OSCBundle() bundle.add(message) # create client and send to 127.0.0.1:8000 client = OSCClient('127.0.0.1', 8000) client.send(message) client.send(bundle) # bind server and listen for incoming messages at 127.0.0.1:8000 server = OSCServer('127.0.0.1', 8000) server.serve_forever()
parser.add_argument('animation', metavar='animation', help='One of these animations: '+string.join(os.listdir('animations/'),', '), choices=os.listdir('animations/')) args = parser.parse_args() animation = args.animation # Open emulator if there's no OSC responsive on that port already try: sys.path.append("./osc") from osc import OSCClient,OSCMessage s=OSCClient() s.connect(('localhost',11661)) # asychronous, so send a bunch to get a potential exception. for x in range(10): s.send(OSCMessage("poop")) except Exception,e: if '[Errno 61]' in str(e): print "Starting emulator, since it doesn't seem to be running yet." os.system('emulator/lights_emulator > /dev/null &') emu_up = False while not emu_up: try: # asychronous, so send a bunch to get a potential exception. for x in range(10): s.send(OSCMessage("poop")) emu_up = True except Exception,e: if not '[Errno 61]' in str(e): emu_up = True else:
#!/usr/bin/python from osc import OSCServer, OSCClient, OSCMessage import sys if __name__ == "__main__": if len(sys.argv) < 2: print """ sendcommand.py: sends commands to the running oscapi.py daemon. usage: ./sendcommand.py command available commands: reloadconfig - reloads config.py in the octoapi - usually reordering the lights """ sys.exit(-1) messagename = sys.argv[1] client = OSCClient() client.connect( ("localhost",11661) ) message = OSCMessage('/'+messagename) for param in sys.argv[2:]: message.append(param) client.send( message )