コード例 #1
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()
コード例 #2
0
ファイル: appTemplate.py プロジェクト: jstoner/boogiepants
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
コード例 #3
0
ファイル: recive.py プロジェクト: felipeCeler/reactbar
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
コード例 #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()
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()
コード例 #7
0
    def listen(self):
        """ a simple function that creates the necesary sockets and enters an enless
            loop sending and receiving OSC
        """

        print 'ready to receive and send osc messages ...', self.port

        while 1:

            #osc.sendMsg("/test", [], "127.0.0.1", 3333) # 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 before exiting or program
コード例 #8
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 = 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()
コード例 #9
0
 def optionsPress(self, pos):
     xval = int(round(pos[0] / 32))
     yval = int(round(pos[1] / 32))
     
     bpmRect     = ((20,2),(31,11))
     connectRect = ((22,12),(29,13))
     playRect    = ((22,15),(29,17))
     
     if 18 < xval < 31 and 1 < yval < 11:
     
         if yval < 4:
             if 18 < xval < 23:
                 self.changeBpm(100)
             elif 22 < xval < 27:
                 self.changeBpm(10)
             elif 27 < xval < 31:
                 self.changeBpm(1)
         elif yval > 8:
             if 18 < xval < 23:
                 self.changeBpm(-100)
             elif 22 < xval < 27:
                 self.changeBpm(-10)
             elif 27 < xval < 31:
                 self.changeBpm(-1)
             
     elif 20 < xval < 29 and 14 < yval < 18:
         if self.globalplay == 0:
             self.globalplay = 1
         else:
             self.globalplay = 0
         sendOSCMessage('/global_play', [self.globalplay])
     
     elif 20 < xval < 29 and 11 < yval < 15:
         if self.connected == 0:
             sendOSCMessage('/track_info', ['bang'])
     
     elif xval > 29 and yval < 1:
         osc.dontListen()
         pygame.quit()
         sys.exit()
コード例 #10
0
    def optionsPress(self, pos):
        xval = int(round(pos[0] / 32))
        yval = int(round(pos[1] / 32))

        bpmRect = ((20, 2), (31, 11))
        connectRect = ((22, 12), (29, 13))
        playRect = ((22, 15), (29, 17))

        if 18 < xval < 31 and 1 < yval < 11:

            if yval < 4:
                if 18 < xval < 23:
                    self.changeBpm(100)
                elif 22 < xval < 27:
                    self.changeBpm(10)
                elif 27 < xval < 31:
                    self.changeBpm(1)
            elif yval > 8:
                if 18 < xval < 23:
                    self.changeBpm(-100)
                elif 22 < xval < 27:
                    self.changeBpm(-10)
                elif 27 < xval < 31:
                    self.changeBpm(-1)

        elif 20 < xval < 29 and 14 < yval < 18:
            if self.globalplay == 0:
                self.globalplay = 1
            else:
                self.globalplay = 0
            sendOSCMessage('/global_play', [self.globalplay])

        elif 20 < xval < 29 and 11 < yval < 15:
            if self.connected == 0:
                sendOSCMessage('/track_info', ['bang'])

        elif xval > 29 and yval < 1:
            osc.dontListen()
            pygame.quit()
            sys.exit()
コード例 #11
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()
コード例 #12
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()
コード例 #13
0
def runTouchApp(ip="127.0.0.1",port=3333):
    TouchEventLoop(ip,port).run()
    osc.dontListen()
コード例 #14
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()
コード例 #15
0
ファイル: demogame.py プロジェクト: aturley/spaceshooter
def on_close():
    osc.dontListen()
コード例 #16
0
ファイル: tuio.py プロジェクト: OpenWerkplek/pymt
 def stop(self):
     '''Stop the tuio provider'''
     osc.dontListen(self.oscid)
コード例 #17
0
ファイル: mario_server.py プロジェクト: qdot/bartris
 def close(self):
     osc.dontListen()
     for thread in self._threads:
         thread.should_run = False
コード例 #18
0
ファイル: tuio.py プロジェクト: fajran/kivy
 def stop(self):
     '''Stop the tuio provider'''
     osc.dontListen(self.oscid)
コード例 #19
0
#
#
clock = pygame.time.Clock()
size = x,y = screen.get_size()
turret = Turret( (x/2,y/2) )
bullets = []
targets = [ Target( (100,0), (0.25, 3.5) ) ]
hitTarget = False

while 1:
    clock.tick(60)

    for event in pygame.event.get():
        if event.type == pygame.QUIT or \
          (event.type == KEYDOWN and event.key == K_ESCAPE): 
            osc.dontListen()
            pygame.quit()
            sys.exit()


    if hitTarget:
        screen.fill((255,0,0))
        hitTarget = False
    else:
        screen.fill(BLACK)

    for finger in livingFingers:
        x = fingers[finger][X] * size[0]
        y = fingers[finger][Y] * size[1]
        pygame.draw.circle(screen, WHITE, (x,y), 5 )
        dir = numpy.array([x,y]) - turret.position
コード例 #20
0
ファイル: demogame.py プロジェクト: tjkoifoly/spaceshooter
def on_close():
    osc.dontListen()
コード例 #21
0
ファイル: receiveosc.py プロジェクト: mortuosplango/gimposc
def python_fu_receiveosc( inImage, inDrawable, netAddr="127.0.0.1",
                       port=57130):
    global receiving,newSpecs,pic
    inImage.disable_undo()
    gimp.progress_init("receiving...")
    receiving = 1
    startingTime = time.time()
    # get right port for sc
    if shelf.has_key('oscnetaddr'):
        sendAddr = shelf['oscnetaddr'][0]
    else:
        sendAddr = "127.0.0.1"
    if shelf.has_key('oscport'):
        sendPort = shelf['oscport'][0]
    else:
        sendPort = 57120
    ## init osc listeners
    osc.init()
    osc.listen(netAddr, port)
    osc.bind(python_fu_receiveosc_storeSpecs, "/gimp/spec")
    osc.bind(python_fu_receiveosc_receiveImage, "/gimp/pic")
    osc.bind(python_fu_receiveosc_displayImage, "/gimp/end")
    ## ping sc to send image
    osc.sendMsg("/gimp/ping", [-1], sendAddr, sendPort)
    ## loop until done
    while receiving:
        #print("ping", len(pic))
        if receiving == 3:
            time.sleep(1)
            gimp.progress_update(96)
            newPic = []
            newLayer = gimp.Layer(inImage,
                                  "fromOSC",
                                  newSpecs[0],
                                  newSpecs[1],
                                  RGB_IMAGE, 100, NORMAL_MODE)
            inImage.add_layer(newLayer, 0)
            pdb.gimp_edit_fill(newLayer, BACKGROUND_FILL)
            newPic = newLayer.get_pixel_rgn(0,0,
                                            newSpecs[0],newSpecs[1], True)
            #newPic = pic
            print(len(pic))
            ## remove all brightness values
            ## convert from int to chr-values
            ## if newSpecs[2] == 4:
            ##     for index in range(len(pic)):
            ##         if index%4 == 3:
            ##             pic[index] = 255
            ##         elif index == 0:
            ##             picAsStr = chr(pic[index])
            ##         else:
            ##             picAsStr = picAsStr + chr(pic[index])
            ## set the pixel region to pic
            #print(pic)
            newPic[0:newSpecs[0],0:newSpecs[1]] = pic
            newLayer.flush()
            newLayer.update(0,0,newSpecs[0],newSpecs[1])
            print("flushed & updated")
            receiving = 0
        elif time.time() - startingTime > 20:
            print("time's up")
            receiving = 0
        else:
            gimp.progress_update(int(18 * (time.time() - startingTime)))
            #time.sleep(0.2)
    osc.dontListen()
    inImage.enable_undo()
    gimp.displays_flush()
    gimp.extension_ack()