From eaaef5460a95d2de1dddc847f6c3bbcb2aef8047 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 25 Jan 2011 00:33:46 -0500 Subject: Adding an OSC input. --- LightInstallation.py | 2 + behaviors/DebugBehavior.py | 2 +- behaviors/MrmrSetColor.py | 21 ++++ behaviors/Square.py | 15 +-- config/6thFloorOSC.xml | 285 +++++++++++++++++++++++++++++++++++++++++++++ config/osc.xml | 10 ++ inputs/OSCInput.py | 22 ++++ oscserver.py | 36 ++++++ pixelcore/PixelStrip.py | 3 - 9 files changed, 385 insertions(+), 11 deletions(-) mode change 100644 => 100755 LightInstallation.py create mode 100644 behaviors/MrmrSetColor.py create mode 100644 config/6thFloorOSC.xml create mode 100644 config/osc.xml create mode 100644 inputs/OSCInput.py create mode 100755 oscserver.py diff --git a/LightInstallation.py b/LightInstallation.py old mode 100644 new mode 100755 index b582bd2..06852e4 --- a/LightInstallation.py +++ b/LightInstallation.py @@ -1,3 +1,5 @@ +#!/usr/bin/python + from xml.etree.ElementTree import ElementTree from pixelcore.Screen import * from pixelcore.PixelStrip import * diff --git a/behaviors/DebugBehavior.py b/behaviors/DebugBehavior.py index 34f4106..17383db 100644 --- a/behaviors/DebugBehavior.py +++ b/behaviors/DebugBehavior.py @@ -4,5 +4,5 @@ import pdb class DebugBehavior(Behavior): def processResponse(self, sensorInputs, recursiveInputs): if sensorInputs != []: - main_log.debug('Sensor Inputs: ' + str(sensorInputs)) + main_log.error('Sensor Inputs: ' + str(sensorInputs)) return ([], []) diff --git a/behaviors/MrmrSetColor.py b/behaviors/MrmrSetColor.py new file mode 100644 index 0000000..97b9fb7 --- /dev/null +++ b/behaviors/MrmrSetColor.py @@ -0,0 +1,21 @@ +from operationscore.Behavior import * +from logger import main_log +#import util.ColorOps as color +import colorsys +import pdb +class MrmrSetColor(Behavior): + def behaviorInit(self): + self.h=0 + self.s=0 + self.v=0 + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + for data in sensorInputs: + if data['Path'].find('horizontal') != -1: + self.h = data['Value'] / 2.78 + elif data['Path'].find('vertical') != -1: + self.s = data['Value'] / 1000.0 + else: + main_log.error('Sensor Inputs: ' + str(sensorInputs)) + ret.append({'Color':[i*255 for i in colorsys.hsv_to_rgb(self.h,self.s,self.v)]}) + return (ret, []) diff --git a/behaviors/Square.py b/behaviors/Square.py index aef3622..ecd000c 100644 --- a/behaviors/Square.py +++ b/behaviors/Square.py @@ -2,11 +2,12 @@ from operationscore.Behavior import * class Square(Behavior): def processResponse(self, sensorInputs, recursiveInputs): for sensory in sensorInputs:#TODO: consider replicating the dict - xLoc = sensory['Location'][0] - yLoc = sensory['Location'][1] - width = self['Width'] - #sensory['Location'] = 'True' - sensory['Location'] =\ - '{x}<'+str(xLoc+width)+',{x}>'+str(xLoc-width)+\ - ',{y}<'+str(yLoc+width)+',{y}>'+str(yLoc-width) + if 'Location' in sensory: + xLoc = sensory['Location'][0] + yLoc = sensory['Location'][1] + width = self['Width'] + #sensory['Location'] = 'True' + sensory['Location'] =\ + '{x}<'+str(xLoc+width)+',{x}>'+str(xLoc-width)+\ + ',{y}<'+str(yLoc+width)+',{y}>'+str(yLoc-width) return (sensorInputs, recursiveInputs) diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml new file mode 100644 index 0000000..0a27fda --- /dev/null +++ b/config/6thFloorOSC.xml @@ -0,0 +1,285 @@ + + + + + simplemap + + + + layouts/60StripLayout.xml + + + + + pixelmappers.SimpleMapper + + simplemap + 20 + + + + pixelmappers.GaussianMapper + + gaussmap + 30 + 0.1 + 10 + 1 + + + + + + renderers/60StripSeq.xml + + + renderers/Pygame.xml + + + + + inputs.OSCInput + + osc + 1234 + + + + inputs.PygameInput + + pygame + 10 + + + + + inputs/MouseFollower.xml + + + inputs.RandomLocs + + randomLoc + + + + + + behaviors.EchoBehavior + + echo + 0 + False + + + + + mrmrcolor + + behaviors.MrmrSetColor + + + behaviors/RedShift.xml + + + behaviors/RandomColor.xml + + + behaviors/PixelDecay.xml + + + behaviors/SingleFrame.xml + + + behaviors/PixelDecay.xml + + .01 + + + + behaviors.XYMove + + xymove + 5 + 2 + + + + behaviors.RestrictLocation + + xbounce + {val}*-1 + XStep + {x}<0 or {x}>800 + + + + behaviors.RestrictLocation + + ybounce + {val}*-1 + YStep + {y}<0 or {y}>200 + + + + behaviors.BehaviorChain + + movebounce + + xymove + ybounce + xbounce + + + + + behaviors.BehaviorChain + + xymover + + pygame + + + colorchange + mover + decay + + {'mover':'movebounce'} + True + gaussmap + + + + behaviors.DebugBehavior + + debug + 0 + + pygame + + + + + behaviors.AllPixelsLeft + + pixelsleft + + + + behaviors.Square + + square + 20 + + + + behaviors.AllPixels + + allpixels + + + + behaviors/LoopAndDie.xml + + 50 + + + + behaviors.BehaviorChain + + runcolordecay + + pygame + + + colorchange + running + decay + + {'running':'acceleratedie'} + False + gaussmap + + + + behaviors.BehaviorChain + + randomwalk + + pygame + + + colorchange + mover + decay + + {'mover':'redwalk'} + False + gaussmap + + + + behaviors.ResponseMover + + mover + + + + behaviors.BehaviorChain + + redwalk + + randmovement + redshift + + + + + behaviors.RandomWalk + + randmovement + 2 + + + + behaviors/Accelerate.xml + + + behaviors.BehaviorChain + + acceleratedie + + accelerate + recursivedecay + + + + + behaviors.BehaviorChain + + mousechaser + + followmouse + tcp + osc + + + mrmrcolor + square + singleframe + + True + + + + behaviors/RunningBehavior.xml + + + diff --git a/config/osc.xml b/config/osc.xml new file mode 100644 index 0000000..6efea40 --- /dev/null +++ b/config/osc.xml @@ -0,0 +1,10 @@ + + inputs.OSCInput + + osc + 1234 + + + + behaviors.MrmrSetColor + diff --git a/inputs/OSCInput.py b/inputs/OSCInput.py new file mode 100644 index 0000000..a998490 --- /dev/null +++ b/inputs/OSCInput.py @@ -0,0 +1,22 @@ +from operationscore.Input import * +import liblo +from logger import main_log + + +class OSCInput(Input): + def inputInit(self): + HOST = '' # Symbolic name meaning all available interfaces + PORT = self['Port'] # Arbitrary non-privileged port + self.server = liblo.Server(PORT) + self.server.add_method(None,None, self.fallback) +# except liblo.ServerError, err: + # main_log.error(str(err)) + + def fallback(self,path,args,types, src): + self.respond({'Path':path,'Type':types[0],'Value':args[0]}) + def sensingLoop(self): + self.server.recv(100) + pass#(data,address) = self.sock.recvfrom(1024) + #dataDict = {'data':data, 'address':address} + #self.respond(dataDict) + diff --git a/oscserver.py b/oscserver.py new file mode 100755 index 0000000..6763f41 --- /dev/null +++ b/oscserver.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import liblo, sys + +# create server, listening on port 1234 +try: + server = liblo.Server(1234) +except liblo.ServerError, err: + print str(err) + sys.exit() + +def foo_bar_callback(path, args): + i, f = args + print "received message '%s' with arguments '%d' and '%f'" % (path, i, f) + +def foo_baz_callback(path, args, types, src, data): + print "received message '%s'" % path + print "blob contains %d bytes, user data was '%s'" % (len(args[0]), data) + +def fallback(path, args, types, src): + print "got unknown message '%s' from '%s'" % (path, src.get_url()) + for a, t in zip(args, types): + print "argument of type '%s': %s" % (t, a) + +# register method taking an int and a float +server.add_method("/foo/bar", 'if', foo_bar_callback) + +# register method taking a blob, and passing user data to the callback +server.add_method("/foo/baz", 'b', foo_baz_callback, "blah") + +# register a fallback for unhandled messages +server.add_method(None, None, fallback) + +# loop and dispatch messages every 100ms +while True: + server.recv(100) diff --git a/pixelcore/PixelStrip.py b/pixelcore/PixelStrip.py index 662b8fe..647991d 100644 --- a/pixelcore/PixelStrip.py +++ b/pixelcore/PixelStrip.py @@ -14,9 +14,6 @@ class PixelStrip: self.pixels = [Pixel(l) for l in pixelLocations] def __iter__(self): return self.pixels.__iter__() - def render(self, surface): - [l.render(surface) for l in self.pixels] - #step def allOn(self, time): [l.turnOnFor(time) for l in self.pixels] #TODO: add test-on method to #pixels -- cgit v1.2.3 From 7557819216cd7d9acd9a4f97d686d6ec84740655 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 25 Jan 2011 13:48:39 -0500 Subject: renamed osc server for test --- testosc.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 testosc.py diff --git a/testosc.py b/testosc.py new file mode 100755 index 0000000..6763f41 --- /dev/null +++ b/testosc.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import liblo, sys + +# create server, listening on port 1234 +try: + server = liblo.Server(1234) +except liblo.ServerError, err: + print str(err) + sys.exit() + +def foo_bar_callback(path, args): + i, f = args + print "received message '%s' with arguments '%d' and '%f'" % (path, i, f) + +def foo_baz_callback(path, args, types, src, data): + print "received message '%s'" % path + print "blob contains %d bytes, user data was '%s'" % (len(args[0]), data) + +def fallback(path, args, types, src): + print "got unknown message '%s' from '%s'" % (path, src.get_url()) + for a, t in zip(args, types): + print "argument of type '%s': %s" % (t, a) + +# register method taking an int and a float +server.add_method("/foo/bar", 'if', foo_bar_callback) + +# register method taking a blob, and passing user data to the callback +server.add_method("/foo/baz", 'b', foo_baz_callback, "blah") + +# register a fallback for unhandled messages +server.add_method(None, None, fallback) + +# loop and dispatch messages every 100ms +while True: + server.recv(100) -- cgit v1.2.3 From 51d58d511d474cb01339d504624b9418c75869e3 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 25 Jan 2011 15:28:25 -0500 Subject: TouchOSC-specific behavior --- behaviors/TouchOSC.py | 33 +++++++++++++++++++++++++++++++++ config/6thFloorOSC.xml | 11 ++++++----- inputs/OSCInput.py | 2 +- testosc.py | 2 +- 4 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 behaviors/TouchOSC.py diff --git a/behaviors/TouchOSC.py b/behaviors/TouchOSC.py new file mode 100644 index 0000000..1c41b5e --- /dev/null +++ b/behaviors/TouchOSC.py @@ -0,0 +1,33 @@ +from operationscore.Behavior import * +from logger import main_log +#import util.ColorOps as color +import colorsys +import pdb +import util.ComponentRegistry as compReg +class TouchOSC(Behavior): + def behaviorInit(self): + self.h=0 + self.s=0 + self.v=0 + self.xy = (-1,-1) + def processResponse(self, sensorInputs, recursiveInputs): + ret = [] + for data in sensorInputs: + if data['Path'] == '/1/fader1': + try: + self.h = data['Value'][0]*360.0 + except: + pdb.set_trace() + elif data['Path'] == '/1/fader2': + self.s = data['Value'][0] + elif data['Path'] == '/1/fader3': + self.v = data['Value'][0] + elif data['Path'] == '/1/xy': + val=data['Value'] + ssize = compReg.getComponent('Screen').getSize()[-2:] #896 x 310 + self.xy = (val[1]*ssize[0], (1.0-val[0])*ssize[1]) + else: + main_log.error('Sensor Inputs: ' + str(sensorInputs)) + ret.append({'Color':[i*255 for i in colorsys.hsv_to_rgb(self.h,self.s,self.v)],'Location':self.xy}) + + return (ret, []) diff --git a/config/6thFloorOSC.xml b/config/6thFloorOSC.xml index 0a27fda..792fd0c 100644 --- a/config/6thFloorOSC.xml +++ b/config/6thFloorOSC.xml @@ -41,7 +41,8 @@ inputs.OSCInput osc - 1234 + 12345 + 10 @@ -80,9 +81,9 @@ - mrmrcolor + touchosc - behaviors.MrmrSetColor + behaviors.TouchOSC behaviors/RedShift.xml @@ -266,12 +267,12 @@ mousechaser - followmouse + tcp osc - mrmrcolor + touchosc square singleframe diff --git a/inputs/OSCInput.py b/inputs/OSCInput.py index a998490..f867fb5 100644 --- a/inputs/OSCInput.py +++ b/inputs/OSCInput.py @@ -13,7 +13,7 @@ class OSCInput(Input): # main_log.error(str(err)) def fallback(self,path,args,types, src): - self.respond({'Path':path,'Type':types[0],'Value':args[0]}) + self.respond({'Path':path,'Type':types,'Value':args}) def sensingLoop(self): self.server.recv(100) pass#(data,address) = self.sock.recvfrom(1024) diff --git a/testosc.py b/testosc.py index 6763f41..cea03f4 100755 --- a/testosc.py +++ b/testosc.py @@ -4,7 +4,7 @@ import liblo, sys # create server, listening on port 1234 try: - server = liblo.Server(1234) + server = liblo.Server(12345) except liblo.ServerError, err: print str(err) sys.exit() -- cgit v1.2.3