Exemplo n.º 1
0
def myTest():
    """ a simple function that creates the necesary sockets and enters an enless
        loop sending and receiving OSC
    """
    osc.init()
    
##    osc.createListener() # this defaults to port 9001 as well
    osc.listen('127.0.0.1', 9001)

    # bind addresses to functions -> printStuff() function will be triggered everytime a
    # "/test" labeled message arrives
    osc.bind(printStuff, "/test")

    import time # in this example we will have a small delay in the while loop

    print 'ready to receive and send osc messages ...'
    
    while 1:
##        osc.sendMsg("/test", [444], "127.0.0.1", 9000) # send normal msg to a specific ip and port
        osc.sendMsg("/test", [444]) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 
        # create and send a bundle
        bundle = osc.createBundle()
        osc.appendToBundle(bundle, "/test/bndlprt1", [1, 2, 3]) # 1st message appent to bundle
        osc.appendToBundle(bundle, "/test/bndlprt2", [4, 5, 6]) # 2nd message appent to bundle
##        osc.sendBundle(bundle, "127.0.0.1", 9000) # send it to a specific ip and port

        osc.sendBundle(bundle) # !! it sends by default to localhost ip "127.0.0.1" and port 9000 
        #osc.getOSC(inSocket) # listen to incomming OSC in this socket
        time.sleep(0.5) # you don't need this, but otherwise we're sending as fast as possible.
        

    osc.dontListen() # finally close the connection bfore exiting or program
Exemplo n.º 2
0
def myTest():
    """ a simple function that creates the necesary sockets and enters an enless
        loop sending and receiving OSC
    """
    osc.init()

    ##    osc.createListener() # this defaults to port 9001 as well
    osc.listen('127.0.0.1', 40001)

    # bind addresses to functions -> printStuff() function will be triggered everytime a
    # "/test" labeled message arrives
    osc.bind(update, "/tuio/Get")

    import time  # in this example we will have a small delay in the while loop

    print ' ready to receive and send osc messages ... FROM SERVER', 40001

    while 1:
        #osc.sendMsg("/test", [], "127.0.0.1", 4001) # send normal msg to a specific ip and port

        time.sleep(
            0.5
        )  # you don't need this, but otherwise we're sending as fast as possible.

    osc.dontListen()  # finally close the connection bfore exiting or program
Exemplo n.º 3
0
def myTest():
    """ a simple function that creates the necesary sockets and enters an endless
        loop sending and receiving OSC
    """
    osc.init()

    import time

    i = 0
    while 1:
        i = i % 4
        print i
        osc.sendMsg("/x0", [i], "127.0.0.1", 9005)
        osc.sendMsg("/y0", [i + 1], "127.0.0.1", 9005)

        osc.sendMsg("/x1", [i + 2], "127.0.0.1", 9005)
        osc.sendMsg("/y1", [i + 3], "127.0.0.1", 9005)

        osc.sendMsg("/update", [1], "127.0.0.1", 9005)

        bundle = osc.createBundle()
        time.sleep(1)
        i += 1

    osc.dontListen()
Exemplo n.º 4
0
def myTest():
    """ a simple function that creates the necesary sockets and enters an endless
        loop sending and receiving OSC
    """
    osc.init()

    import time

    i = 0
    while 1:
        i = i % 4
        print i
        osc.sendMsg("/x0", [i], "127.0.0.1", 9005)
        osc.sendMsg("/y0", [i + 1], "127.0.0.1", 9005)

        osc.sendMsg("/x1", [i + 2], "127.0.0.1", 9005)
        osc.sendMsg("/y1", [i + 3], "127.0.0.1", 9005)

        osc.sendMsg("/update", [1], "127.0.0.1", 9005)

        bundle = osc.createBundle()
        time.sleep(1)
        i += 1

    osc.dontListen()
Exemplo n.º 5
0
 def __init__(self, patch=None, buffer=128, options={}, start=False, path=DEFAULT):
     """ Creates a network connection with PureData.
         When a patch (.pd file) is given and start=True, loads PD with the patch in the background.
         Otherwise, communication can be established with whatever patch is active in a running PD.
         The PD.send() method sends data to the patch running at a given host and port.
         The path defines the location of the PD executable.
         A number of default locations are searched as well:
         - the current folder,
         - /usr/local/bin/pd (Unix),
         - /Applications/Pd-extended.app/Contents/Resources/bin/pd (Mac OS X),
         - C:\Program Files\pd\bin\pd.exe (Windows).
     """
     path = path != DEFAULT and path or ""
     path = find(lambda x: os.path.exists(x), [
         path,
         os.path.join(path, PD_UNIX),
         os.path.join(path, PD_MACOSX),
         os.path.join(path, PD_WINDOWS),
         "usr/local/bin/" + PD_UNIX, 
         "/Applications/" + PD_MACOSX, 
         "C:\\Program Files\\" + PD_WINDOWS
     ])
     self._path     = path          # PD executable location.
     self._process  = None          # PD executable running in background.
     self._callback = {}            # [PDCallback, data] items indexed by path + host + port.
     self._options  = dict(options) # For PD-Extended 0.41- on Mac OS X, only works with -nogui.
     self._options.setdefault("-nogui", None)
     self._options.setdefault("-audiobuf", buffer)
     self._options.setdefault("-open", patch)
     if start:
         self.start()
     osc.init()
Exemplo n.º 6
0
Arquivo: tuio.py Projeto: azoon/pymt
 def start(self):
     '''Start the tuio provider'''
     osc.init()
     self.oscid = osc.listen(self.ip, self.port)
     for oscpath in TuioTouchProvider.__handlers__:
         self.touches[oscpath] = {}
         osc.bind(self._osc_tuio_cb, oscpath)
Exemplo n.º 7
0
def send_osc(ip = default_IP, port = default_PORT, loop = default_LOOP, command = []):
    """Function, send a list of OSC commands."""
    osc.init()
    bundle = osc.createBundle()
    for item in command:
        osc.appendToBundle(bundle, '/sl/%s/hit' % loop, ['%s' % item])
    osc.sendBundle(bundle, '%s' % ip, int(port))
def main():
	osc.init()
	i = 0
	while(1):
		osc.sendMsg("/beat",[i],"127.0.0.1",9001)
		i = i + 1
		time.sleep(1)
Exemplo n.º 9
0
def python_fu_sendosc( inImage, inDrawable,
                       bFlatten=True,
                       netAddr="127.0.0.1",
                       port=57120):
    global outSocket
    ## save options for use with the guiless version
    shelf['oscport'] = [port]
    shelf['oscnetaddr'] = [netAddr]
    shelf['oscbflatten'] = [bFlatten]

    width = inDrawable.width
    height = inDrawable.height
    
    if bFlatten == True:
        inImage.disable_undo()
        flatImage = inImage.duplicate()
        flatImage.flatten()
        pr = flatImage.active_layer.get_pixel_rgn(0,0,width,height,False)
    else:
        pr = inDrawable.get_pixel_rgn(0,0,width,height,False)

    ## start communication and send specs
    osc.init()
    osc.sendMsg("/gimp/spec",
                [width, height, pr.bpp],
                netAddr, port)

    ## create an extra socket for the binary messages
    outSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    prp = pr[0:width,0:height]
    ## print(osc.hexDump(prp))
    gimp.progress_init("Sending image...")

    ## empirical maximum size: 65487 (2 ** 16 - 49)
    ## UDP-Datagram-Limit:
    ## The practical limit for the data length which is imposed by the
    ## underlying IPv4 protocol is 65,507 bytes.
    ## http://en.wikipedia.org/wiki/User_Datagram_Protocol#Packet_structure
    maxSize = 8000
    imgSize = width * height * pr.bpp
    for index in range( int(math.ceil(imgSize / float(maxSize))) ):
        m = osc.OSCMessage()
        m.address = "/gimp"
        m.append(index)
        if (((index + 1) * maxSize) > imgSize):
            m.append(prp[(index * maxSize):],'b')
        else:
            m.append(prp[(index * maxSize):((index + 1) * maxSize)],'b')
        outSocket.sendto( m.getBinary(), (netAddr, port))
        ## introduce latency to not loose packages
        time.sleep(0.02)

    ## end communication
    osc.sendMsg("/gimp", [-1], netAddr, port)
    ## clean up
    if bFlatten == True:
        inImage.enable_undo()
        gimp.delete(flatImage)
Exemplo n.º 10
0
def myTest():
    osc.init()
    osc.listen('192.168.11.15', 8000)  #local IP; listen on port 8000
    osc.bind(recvMsg, "/echo")
    # enable reporting of all adc channels
    osc.sendMsg("/echo", [0], '192.168.11.200', 8888)  # Arduino's IP and Port
    while 1:
        time.sleep(0.1)
Exemplo n.º 11
0
    def __init__(self, host='127.0.0.1', port=3333):
        self.host = host
        self.port = port
        self.current_frame = 0
        self.last_frame = 0

        osc.init()
        self.cursors = {} 
Exemplo n.º 12
0
def myTest():
	osc.init()
	osc.listen('192.168.11.15', 8000) #local IP; listen on port 8000
	osc.bind(recvMsg,"/echo")
	# enable reporting of all adc channels
	osc.sendMsg("/echo",[0],'192.168.11.200',8888) # Arduino's IP and Port
	while 1:
		time.sleep(0.1)
Exemplo n.º 13
0
def main(port):
    osc.init()

    # start tkinter
    frame = Frame(port)
    frame.port = port
    frame.pack()
    frame.mainloop()
Exemplo n.º 14
0
def main():
	osc.init()
	osc.listen("127.0.0.1",9001)
	osc.bind(heartBeat, "/beat")
	while(1):
		global last_beat
		time_diff = (time.clock() - last_beat)
		print time_diff;
		time.sleep(0.1);
Exemplo n.º 15
0
def main(port):
    osc.init()
    listener = osc.createListener("",port)

    import time

    while 1:
        time.sleep(0.1)
        osc.getOSC(listener)
    def init_osc(self):
        osc.init()
        self.oscid = osc.listen(ipAddr='127.0.0.1', port=self.receive_port)

        osc.bind(self.oscid, self.receive_osc_message, b'/stdout')
        osc.bind(self.oscid, self.receive_osc_message, b'/stderr')
        osc.bind(self.oscid, self.receive_osc_message, b'/interpreter')
        osc.bind(self.oscid, self.receive_osc_message, b'/pong')
        osc.bind(self.oscid, self.receive_osc_message, b'/requestinput')
Exemplo n.º 17
0
 def __init__(self, host="localhost", port=6666):
     osc.init()
     self.host=host
     self.port=int(port)
     print "reporting to %s:%d" % (self.host, self.port)
     self.hm=hooklib.HookManager()
     self.hm.KeyDown = self.OnKeyboardEvent
     self.hm.KeyUp = self.OnKeyboardEvent
     self.hm.HookKeyboard()
Exemplo n.º 18
0
def main():
    osc.init()
    try:
        for i in range(0, 3):
            osc.sendMsg("/tetris/level", [i, 60], "localhost", 9001)
        pass
    except Exception, ex:
        print "EXCEPTION!"
        print ex
Exemplo n.º 19
0
	def __init__(self, default = 0, address = "/value", port = 9900):
		if not PStaticViaOSC.initialised:
			import osc

			osc.init()
			osc.listen(port = port)

		self.value = default
		self.address = address
		osc.bind(self.recv, address)
Exemplo n.º 20
0
	def listen(self, prefix = "/global", port = 9900):
		if not PStaticGlobal.listening:
			import osc

			osc.init()
			osc.listen(port = port)
			PStaticGlobal.listening = True

		self.prefix = prefix
		osc.bind(self.recv, prefix)
Exemplo n.º 21
0
    def __init__(self, default=0, address="/value", port=9900):
        if not PStaticViaOSC.initialised:
            import osc

            osc.init()
            osc.listen(port=port)

        self.value = default
        self.address = address
        osc.bind(self.recv, address)
Exemplo n.º 22
0
    def __init__(self):
        osc.init()
        osc.listen('localhost', 9001)
        osc.listen('10.211.55.2', 9001)

        self._threads = []
        self._threads.append(g_drinkControlThread)
        self._threads.append(g_ambxThread)
        self._threads.append(g_tranceVibratorThread)
        [thread.start() for thread in self._threads]
Exemplo n.º 23
0
Arquivo: synthlab.py Projeto: imc/pymt
 def __init__(self, **kwargs):
     super(Workspace,self).__init__( **kwargs)
     osc.init()
     self.modules = [Module(filename = 'sl-addSynth+.svg', category = 'source', instance = 1),
                     Module(filename = 'sl-addSynth+.svg', category = 'source', instance = 2),
                     Module(filename = 'sl-speaker.svg', category = 'output', instance = 1),
                     Module(filename = 'sl-speaker.svg', category = 'output', instance = 2),
                     Module(filename = 'sl-distort+.svg', category = 'effect', instance = 1),
                     Module(filename = 'sl-lfo+.svg', category = 'controller', instance = 1)]
     for m in self.modules:
         self.add_widget(m)
Exemplo n.º 24
0
 def __init__(self):
     osc.init()
     bundle = osc.createBundle()
     self.set_laser(False)
     for servo in servos:
         servo['range'] = self._range(servo)
         osc.appendToBundle(
             bundle,
             "/digitalout/%i/speed" % servo['address'],
             [servo['speed']]
         )
     osc.sendBundle(bundle, BOARD_ADDRESS, BOARD_PORT)
def myTest():
    """ a simple function that creates the necesary sockets and enters an enless
        loop sending and receiving OSC
    """
    osc.init()
    osc.bind(printStuff, "/gainSlider")
    inSocket = osc.createListener("127.0.0.1", 9001)

    import time

    while 1:
        osc.getOSC(inSocket)

    osc.dontListen()
def myTest():
    """ a simple function that creates the necesary sockets and enters an enless
        loop sending and receiving OSC
    """
    osc.init()
    osc.bind(printStuff, "/gainSlider")
    inSocket = osc.createListener("127.0.0.1", 9001)

    import time

    while 1:
        osc.getOSC(inSocket)

    osc.dontListen()
Exemplo n.º 27
0
def main(argv=None):
    osc.init()

    b = Bartris()
    t = Tetris()
    a = amBXtris()
    t.add_event_handler(a)
    t.add_event_handler(b)
    t.init_game()
    try:
        while(1):
            t.run_game()
    except QuitException, e:
        return 0
Exemplo n.º 28
0
    def __init__(self, host, port):
        self.client = {}
        self.host = host
        self.port = port
        osc.init()

        ##    osc.createListener() # this defaults to port 9001 as well

        osc.listen(self.host, self.port)

        # bind addresses to functions -> printStuff() function will be triggered everytime a
        # "/test" labeled message arrives
        osc.bind(self.update, "/tuio/Set")
        osc.bind(self.sendClients, "/tuio/Get")
        osc.bind(self.send, "/tuio/msg")
def myTest():
    """ a simple function that creates the necesary sockets and enters an endless
        loop sending and receiving OSC
    """
    osc.init()

    import time

    i = 1
    while 1:
        j = ((i + 1) % 2) * 100
        print j
        osc.sendMsg("/gainSlider", [j], "127.0.0.1", 9001)
        bundle = osc.createBundle()
        time.sleep(1)
        i += 1

    osc.dontListen()
Exemplo n.º 30
0
 def __init__(self,
              patch=None,
              buffer=128,
              options={},
              start=False,
              path=DEFAULT):
     """ Creates a network connection with PureData.
         When a patch (.pd file) is given and start=True, loads PD with the patch in the background.
         Otherwise, communication can be established with whatever patch is active in a running PD.
         The PD.send() method sends data to the patch running at a given host and port.
         The path defines the location of the PD executable.
         A number of default locations are searched as well:
         - the current folder,
         - /usr/bin/pdextended (Unix, preferred),
         - /usr/local/bin/pd (Unix),
         - /Applications/Pd-extended.app/Contents/Resources/bin/pd (Mac OS X),
         - C:\Program Files\pd\bin\pd.exe (Windows).
         Command-line options can be given as a dictionary, e.g.
         PD(options={'-alsa': None})
     """
     path = path != DEFAULT and path or ""
     path = _find(lambda x: os.path.exists(x), [
         path,
         os.path.join(path, PD_UNIX1),
         os.path.join(path, PD_UNIX2),
         os.path.join(path, PD_MACOSX),
         os.path.join(path, PD_WINDOWS), "usr/bin/" + PD_UNIX1,
         "usr/local/bin/" + PD_UNIX1, "usr/bin/" + PD_UNIX2,
         "usr/local/bin/" + PD_UNIX2, "/Applications/" + PD_MACOSX,
         "C:\\Program Files\\" + PD_WINDOWS
     ])
     self._path = path  # PD executable location.
     self._process = None  # PD executable running in background.
     self._callback = {
     }  # [PDCallback, data] items indexed by path + host + port.
     self._options = dict(
         options
     )  # For PD-Extended 0.41- on Mac OS X, only works with -nogui.
     self._options.setdefault("-nogui", None)
     self._options.setdefault("-audiobuf", buffer)
     self._options.setdefault("-open", patch)
     if start:
         self.start()
     osc.init()
Exemplo n.º 31
0
 def __init__(self, address='127.0.0.1', port=9000, prefix='/wii/1'):
     if osc.outSocket == 0:  # Only init once.
         osc.init()
     self.address = address
     self.port = port
     self.listener = osc.createListener(address, port)
     osc.bind(self._wii_pry, "/wii/1/accel/pry")
     osc.bind(self._wii_xyz, "/wii/1/accel/xyz")
     osc.bind(self._wii_a, "/wii/1/button/A")
     osc.bind(self._wii_b, "/wii/1/button/B")
     self.prefix = prefix
     self.pitch = 0.0
     self.roll = 0.0
     self.yaw = 0.0
     self.accel = 0.0
     self.x = 0.0
     self.y = 0.0
     self.z = 0.0
     self.a = False
     self.b = False
Exemplo n.º 32
0
 def __init__(self, address='127.0.0.1', port=9000, prefix='/wii/1'):
     if osc.outSocket == 0: # Only init once.
         osc.init()
     self.address = address
     self.port = port
     self.listener = osc.createListener(address, port)
     osc.bind(self._wii_pry, "/wii/1/accel/pry")
     osc.bind(self._wii_xyz, "/wii/1/accel/xyz")
     osc.bind(self._wii_a, "/wii/1/button/A")
     osc.bind(self._wii_b, "/wii/1/button/B")
     self.prefix = prefix
     self.pitch = 0.0
     self.roll = 0.0
     self.yaw = 0.0
     self.accel = 0.0
     self.x = 0.0
     self.y = 0.0
     self.z = 0.0
     self.a = False
     self.b = False
Exemplo n.º 33
0
def myTest():
    """ a simple function that creates the necesary sockets and enters an enless
        loop sending and receiving OSC
    """
    osc.init()

    inSocket = osc.createListener('127.0.0.1',
                                  9001)  # in this case just using one socket
    ##    inSocket = osc.createListener() # this defaults to port 9001 as well

    # bind addresses to functions -> printStuff() function will be triggered everytime a
    # "/test" labeled message arrives
    osc.bind(printStuff, "/test")

    import time  # in this example we will have a small delay in the while loop

    print 'ready to receive and send osc messages ...'

    while 1:
        ##        osc.sendMsg("/test", [444], "127.0.0.1", 9000) # send normal msg to a specific ip and port
        osc.sendMsg("/test", [
            444
        ])  # !! it sends by default to localhost ip "127.0.0.1" and port 9000

        # create and send a bundle
        bundle = osc.createBundle()
        osc.appendToBundle(bundle, "/test/bndlprt1",
                           [1, 2, 3])  # 1st message appent to bundle
        osc.appendToBundle(bundle, "/test/bndlprt2",
                           [4, 5, 6])  # 2nd message appent to bundle
        ##        osc.sendBundle(bundle, "127.0.0.1", 9000) # send it to a specific ip and port

        osc.sendBundle(
            bundle
        )  # !! it sends by default to localhost ip "127.0.0.1" and port 9000

        osc.getOSC(inSocket)  # listen to incomming OSC in this socket

        time.sleep(
            0.5
        )  # you don't need this, but otherwise we're sending as fast as possible.
Exemplo n.º 34
0
def main():
    osc.init()
    try:
        random.seed()
        while 1:
            a = ((random.randint(0,100) % 100) / 100.0, (random.randint(0,100) % 100) / 100.0, (random.randint(0,100) % 100) / 100.0)
            print a
            b = [int(x * 255) for x in a]
            print b
            c = [random.randint(0, 40)]
            print c
            for i in range(0, 3):
                osc.sendMsg("/tetris/level", [i , a[i]], "localhost", 9001)
            osc.sendMsg("/tetris/line", b, "localhost", 9001)
            osc.sendMsg("/mario/speed", c, "localhost", 9001)
            time.sleep(1.5)
    except KeyboardInterrupt, e:
        osc.sendMsg("/tetris/line", [0,0,0], "localhost", 9001)
        osc.sendMsg("/mario/speed", [0], "localhost", 9001)

        pass
Exemplo n.º 35
0
def main():
    
    import osc
    import time
    
    osc.init()
    
    
    while 1:
        print "acquiring new Data"
        
        valueDict = getRSSData()
        
        msgArray = [
            "temp", valueDict["Temperature"], "hum", valueDict["Humidity"], "wind", valueDict["WindSpeed"], "press", valueDict["Pressure"]
        ]
        
        print msgArray
        for j in range(0, 59):
            osc.sendMsg("/weather", msgArray, "127.0.0.1", 57120) # send normal msg
            time.sleep(10)
def main():

    import osc
    import time

    osc.init()

    while 1:
        print "acquiring new Data"

        valueDict = getRSSData()

        msgArray = [
            "temp", valueDict["Temperature"], "hum", valueDict["Humidity"],
            "wind", valueDict["WindSpeed"], "press", valueDict["Pressure"]
        ]

        print msgArray
        for j in range(0, 59):
            osc.sendMsg("/weather", msgArray, "127.0.0.1",
                        57120)  # send normal msg
            time.sleep(10)
Exemplo n.º 37
0
def main():
    
    import osc
    import time
    
    osc.init()
    
    sleepTime = 10
    """reacquisition of data every"""
    reacquisitionCycle = 5
    """ x sleepTime seconds."""
    
    """for i in range(0, 100):"""
    while 1:
        
        print "acquiring new Data"
        
        """Bielefeld"""
        """valueDict = getData("IBIELEFE4")""" 

        """Helsinki, Kannelmaki"""
        """valueDict = getData("IUUSIMAA2")"""

        """Helsinki, Vuosaari"""
        """valueDict = getData("IUUSIMAA12")"""

        """Amsterdam, Westhaven"""
        valueDict = getData("INHAMSTE8")
        
        # print valueDict
        
        msgArray = [
            "temp", valueDict["TemperatureC"], "hum", valueDict["Humidity"], "wind", valueDict["WindSpeedKMH"], "press", valueDict["PressurehPa"]
        ]
        
        for j in range(0, reacquisitionCycle):
                    print msgArray
                    osc.sendMsg("/weather", msgArray, "127.0.0.1", 57120) # send normal msg
                    time.sleep(sleepTime)
Exemplo n.º 38
0
def main():
    
    import osc
    import time
    
    osc.init()
    
    
    for i in range(0, 100):
        
        print "acquiring new Data"
        
        valueDict = getData()
        # print valueDict
        
        msgArray = [
            "temp", valueDict["TemperatureC"], "hum", valueDict["Humidity"], "wind", valueDict["WindSpeedKMH"], "press", valueDict["PressurehPa"]
        ]
        
        for j in range(0, 5*60):
            print msgArray
            time.sleep(1)
def main():

    import osc
    import time

    osc.init()

    for i in range(0, 100):

        print "acquiring new Data"

        valueDict = getData()
        # print valueDict

        msgArray = [
            "temp", valueDict["TemperatureC"], "hum", valueDict["Humidity"],
            "wind", valueDict["WindSpeedKMH"], "press",
            valueDict["PressurehPa"]
        ]

        for j in range(0, 5 * 60):
            print msgArray
            time.sleep(1)
Exemplo n.º 40
0
	def __init__(self, scale, basefreq):
		osc.init()
		pygame.init()

		self.size = self.width, self.height = 300, 300
		self.screen = pygame.display.set_mode(self.size)
		self.scale = scale
		self.basefreq = basefreq

		self.keyorder = [96, 9,
				 49, 113, 97, 122,
				 50, 119, 115, 120,
				 51, 101, 100, 99,
				 52, 114, 102, 118,
				 53, 116, 103, 98,
				 54, 121, 104, 110,
				 55, 117, 106, 109,
				 56, 105, 107, 44,
				 57, 111, 108, 46,
				 48, 112, 59, 47,
				 45, 91, 39,
				 61, 93, 13,
				 8, 92]
def main():

    import osc
    import time

    osc.init()

    sleepTime = 10
    """reacquisition of data every"""
    reacquisitionCycle = 5
    """ x sleepTime seconds."""
    """for i in range(0, 100):"""
    while 1:

        print "acquiring new Data"
        """Bielefeld"""
        """valueDict = getData("IBIELEFE4")"""
        """Helsinki, Kannelmaki"""
        """valueDict = getData("IUUSIMAA2")"""
        """Helsinki, Vuosaari"""
        """valueDict = getData("IUUSIMAA12")"""
        """Amsterdam, Westhaven"""
        valueDict = getData("INHAMSTE8")

        # print valueDict

        msgArray = [
            "temp", valueDict["TemperatureC"], "hum", valueDict["Humidity"],
            "wind", valueDict["WindSpeedKMH"], "press",
            valueDict["PressurehPa"]
        ]

        for j in range(0, reacquisitionCycle):
            print msgArray
            osc.sendMsg("/weather", msgArray, "127.0.0.1",
                        57120)  # send normal msg
            time.sleep(sleepTime)
Exemplo n.º 42
0
# GNU General Public License for more details.

import BaseHTTPServer
import logging
import csv
import sys
import osc
import json
import random

LOG_FILENAME = '/tmp/polosc.out'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)
logging.info("")
logging.info("***STARTING***")

osc.init()

class PoloHandler (BaseHTTPServer.BaseHTTPRequestHandler):
    def write_response(self):
        if self.server.mappings.has_key(self.path):
            logging.debug("path '%s' is mapped"%(self.path))
            self.send_response(200)
            self.send_header("Content-type", "text/html")
            self.end_headers()
            self.wfile.write(self.server.mappings[self.path])
        elif self.path == "/getrandom":
            logging.debug("got request for a random number")
            random_int = random.randint(0, 0xFFFFFFFF)
            logging.debug("sending %x"%(random_int))
            self.send_response(200)
            self.send_header("Content-type", "text/html")
Exemplo n.º 43
0
    try:
        ipAddress = msg[0][2]
        x = msg[0][3]
        y = msg[0][4]
        global current_state
        current_state.shoot_end_handler(ipAddress, x, y)
    except Exception, e:
        print e


def add_player(ipAddress):
    players[ipAddress] = Player(ipAddress, random.randint(0, 639),
                                random.randint(0, 479), 0, 0)


def player_exists(ipAddress):
    return players.has_key(ipAddress)


if __name__ == "__main__":
    setup()
    osc.init()
    osc.listen('127.0.0.1', 9002)
    osc.bind(move_start_handler, '/movestart')
    osc.bind(move_end_handler, '/moveend')
    osc.bind(shoot_start_handler, '/shootstart')
    osc.bind(shoot_end_handler, '/shootend')
    pyglet.clock.schedule(update)
    current_state.enter()
    pyglet.app.run()
Exemplo n.º 44
0
def myTest():
    """ a simple function that creates the necesary sockets and enters an enless
        loop sending and receiving OSC
    """
    osc.init()

    import time
    
    # Setup the keyboard
    ser = serial.Serial(port='/dev/tty.usbserial-A6007kFY',baudrate= 115200,bytesize=8,parity='N',stopbits=1)
    ser.open()
    print ser.portstr
    ser.write("q") #initiate continuous ASCII mode (active keys only)

    # Build a regexp to recognize a line that looks like:
    #
    # (0,10) => 158
    #
    regexp = re.compile('.*\(([0-9]*),([0-9]*)\) => ([0-9]*)')

    # Main loop
    i = 1
    while 1:
	line = ser.readline()
	r = regexp.match(line)
	if r is not None:
		#print "****" + r.group(1) + " " + r.group(2) + " " + r.group(3) +  "****"
                row = int(r.group(1))
                col = int(r.group(2))
                pressure = int(r.group(3)) / 10
                address = "/generickey"

	


                if (row == 1) and (col == 9):
                    address = "/key1"
                if row == 5 and col == 8:
                    address = "/key2"
                if row == 0 and col == 6:
                    address = "/key3"
		if row == 5 and col == 9: 
		    address = "/key4" 
		if row == 4 and col == 8: 
		    address = "/key5" 
		if row == 1 and col == 6: 
		    address = "/key6"
		if row == 4 and col == 9: 
		    address = "/key7"
		if row == 3 and col == 8: 
		    address = "/key8" 
		if row == 4 and col == 6: 
		    address = "/key9" 
		if row == 1 and col == 11: 
		    address = "/keym" 
		if row == 5 and col == 3: 
		    address = "/keyd" 
		if row == 5 and col == 2: 
		    address = "/keys"
		if row == 0 and col == 17: 
		    address = "/keyleft"		
		if row == 0 and col == 18: 
		    address = "/keydown"		
		if row == 0 and col == 10: 
		    address = "/keyright"		
		if row == 1 and col == 18: 
		    address = "/keyup"		

                if pressure < 20:
                    pressure = 0
		pressure /= 85.0;

		if address == "/key1": 
		   address = "/Fanout/mixsrc/Series/branch1/Panorama/pan/mrs_real/angle" 
		   pressure *= -0.785
		if address == "/key2": 
		   address = "/Fanout/mixsrc/Series/branch1/Panorama/pan/mrs_real/angle" 
		   pressure = 0
		if address == "/key3": 
		   address = "/Fanout/mixsrc/Series/branch1/Panorama/pan/mrs_real/angle" 
		   pressure *= 0.785;

		if address == "/key4": 
		   address = "/Fanout/mixsrc/Series/branch2/Panorama/pan/mrs_real/angle" 
		   pressure *= -0.785
		if address == "/key5": 
		   address = "/Fanout/mixsrc/Series/branch2/Panorama/pan/mrs_real/angle" 
		   pressure = 0
		if address == "/key6": 
		   address = "/Fanout/mixsrc/Series/branch2/Panorama/pan/mrs_real/angle" 
		   pressure *= 0.785;


		if address == "/key7": 
		   address = "/Fanout/mixsrc/Series/branch3/Panorama/pan/mrs_real/angle" 
		   pressure *= -0.785
		if address == "/key8": 
		   address = "/Fanout/mixsrc/Series/branch3/Panorama/pan/mrs_real/angle" 
		   pressure = 0
		if address == "/key9": 
		   address = "/Fanout/mixsrc/Series/branch3/Panorama/pan/mrs_real/angle" 
		   pressure *= 0.785;

		if address == "/keym": 
		   pressure *= 100;
		if address == "/keys": 
		   pressure *= 100;
		if address == "/keyd":
		   pressure *= 20;


		if address == "/keyleft": 
		   pressure *= -255;
		if address == "/keyright":
		   pressure *= 255;
		if address == "/keyup": 
		   pressure *= 180;
		if address == "/keydown":
		   pressure *= -180;

                print "**** address=" + address + " row=" + str(row) + " col=" + str(col) + " pressure=" + str(pressure) + " ****"

                osc.sendMsg(address, [pressure], "127.0.0.1", 9000)
#         bundle = osc.createBundle()
        #time.sleep(0.5)
        i += 1

    osc.dontListen()
    ser.close()
Exemplo n.º 45
0
    def __init__(self):
        osc.init()
        self.source = Source(CAMERAID)
        #self.source.print_info()
        self.threshold_value = THRESH
        self.hc = cv.Load(HAARCASCADE)
        self.ms = cv.CreateMemStorage()

        self.orig = self.source.grab_frame()

        self.width = self.orig.width
        self.height = self.orig.height
        self.size = (self.width, self.height)
        self.smallheight = WORKING_HEIGHT
        self.smallwidth = int(self.width * self.smallheight / self.height *
                              1.0)
        self.smallsize = (self.smallwidth, self.smallheight)

        # alloc mem for images
        self.small = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 3)
        self.visualize = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 3)
        self.bw = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 1)
        self.hsv = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 3)
        self.hue = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 1)
        self.sat = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 1)
        self.bp = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 1)
        self.th = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 1)
        self.morphed = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 1)
        self.temp = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 1)
        self.temp3 = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 3)
        self.result = cv.CreateImage(self.smallsize, cv.IPL_DEPTH_8U, 3)
        self.hist_image = cv.CreateImage((320, 200), cv.IPL_DEPTH_8U, 1)

        # make matrix for erode/dilate
        MORPH_SIZE = 3
        center = (MORPH_SIZE / 2) + 1
        self.morpher_small = cv.CreateStructuringElementEx(
            cols=MORPH_SIZE,
            rows=MORPH_SIZE,
            anchor_x=center,
            anchor_y=center,
            shape=cv.CV_SHAPE_ELLIPSE)
        MORPH_SIZE = 11
        center = (MORPH_SIZE / 2) + 1
        self.morpher = cv.CreateStructuringElementEx(cols=MORPH_SIZE,
                                                     rows=MORPH_SIZE,
                                                     anchor_x=center,
                                                     anchor_y=center,
                                                     shape=cv.CV_SHAPE_ELLIPSE)

        # alloc mem for face histogram
        self.face_hist = cv.CreateHist([HUEBINS, SATBINS], cv.CV_HIST_ARRAY,
                                       [[0, 180], [0, 255]], 1)

        # alloc mem for background histogram
        self.bg_hist = cv.CreateHist([HUEBINS, SATBINS], cv.CV_HIST_ARRAY,
                                     [[0, 180], [0, 255]], 1)

        # video writer
        if STORE:
            self.writer = cv.CreateVideoWriter(OUTPUT,
                                               cv.CV_FOURCC(
                                                   'M', 'J', 'P', 'G'),
                                               15,
                                               cv.GetSize(self.combined),
                                               is_color=1)

        # make window
        cv.NamedWindow('Skin Detection')
        cv.CreateTrackbar('Threshold', 'Skin Detection', self.threshold_value,
                          255, self.change_threshold)
Exemplo n.º 46
0
 def __init__(self,  ip='127.0.0.1', port=3333):
         osc.init()
         osc.listen(ip, port)
         osc.bind(self.osc_2dcur_Callback, "/tuio/2Dcur")
         osc.bind(self.osc_2dobj_Callback, "/tuio/2Dobj")
Exemplo n.º 47
0
 def __init__(self, ipAddress):
     osc.init()
     self.address = ipAddress
     self.port = 7000
     self.frame = 0
     print("address : ", ipAddress)
Exemplo n.º 48
0
def main():

    global mainObj

    global sendIP
    global sendPort

    configFile = open('OSCadr.cfg', 'r')
    for line in configFile:
        line = line.split()
        if line[0] == "sendPort":
            sendPort = int(line[1])
        if line[0] == "sendIP":
            sendIP = line[1]
        if line[0] == "listenIP":
            listenIP = line[1]
        if line[0] == "listenPort":
            listenPort = int(line[1])

    pygame.init()

    osc.init()
    osc.listen(listenIP, listenPort)

    mainObj = Globject()

    clock = pygame.time.Clock()

    osc.bind(mainObj.curve.editCurve, '/curve/gui_curve/edit')
    osc.bind(mainObj.curve.editMidi, '/curve/midi_params')
    osc.bind(mainObj.curve.editLengths, '/curve/curve_lengths')
    osc.bind(mainObj.curve.editPlayStates, '/curve/play_states')

    osc.bind(mainObj.grid16.editGrid, '/grid16/pattern_grid/edit')
    osc.bind(mainObj.grid16.editMidi, '/grid16/midi_params')
    osc.bind(mainObj.grid16.editPatternSeqLength, '/grid16/pattern_seq/length')
    osc.bind(mainObj.grid16.editPatternSeq, '/grid16/pattern_seq')

    osc.bind(mainObj.grid32.editGrid, '/grid32/pattern_grid/edit')
    osc.bind(mainObj.grid32.editMidi, '/grid32/midi_params')
    osc.bind(mainObj.grid32.editPatternSeqLength, '/grid32/pattern_seq/length')
    osc.bind(mainObj.grid32.editPatternSeq, '/grid32/pattern_seq')

    osc.bind(mainObj.menu.trackInfo, '/main/track_info')

    osc.bind(mainObj.menu.seqStepNumber, '/main/stepnumber')

    loop = True
    while loop:
        clock.tick(60)

        for event in pygame.event.get():
            if event.type == QUIT:
                loop = False
            if event.type == pygame.MOUSEBUTTONUP:
                mousePosition = pygame.mouse.get_pos()
                mainObj.modeObject.mouseInput('up', mousePosition)

            if event.type == pygame.MOUSEBUTTONDOWN:
                mousePosition = pygame.mouse.get_pos()
                mainObj.modeObject.mouseInput('down', mousePosition)

            if event.type == pygame.MOUSEMOTION:
                mousePosition = pygame.mouse.get_pos()
                mainObj.modeObject.mouseInput('drag', mousePosition)

        mainObj.drawStuff()

    osc.dontListen()
    pygame.quit()
    sys.exit()
Exemplo n.º 49
0
print "starting..."
print(sys.argv)

# create etc object
# this holds all the data (mode and preset names, knob values, midi input, sound input, current states, etc...)
# it gets passed to the modes which use the audio midi and knob values
etc = etc_system.System()

# load shift params from file
etc.recall_shift_params()

# just to make sure
etc.clear_flags()

# setup osc and callbacks
osc.init(etc)

# setup alsa sound
sound.init(etc, AOUT_JACK)

# init pygame, this has to happen after sound is setup
# but before the graphics stuff below
pygame.init()
clocker = pygame.time.Clock() # for locking fps

print "pygame version " + pygame.version.ver

# on screen display and other screen helpers
osd.init(etc)
osc.send("/led", 7) # set led to running