当前位置: 首页>>代码示例>>Python>>正文


Python OSCServer.addDefaultHandlers方法代码示例

本文整理汇总了Python中OSC.OSCServer.addDefaultHandlers方法的典型用法代码示例。如果您正苦于以下问题:Python OSCServer.addDefaultHandlers方法的具体用法?Python OSCServer.addDefaultHandlers怎么用?Python OSCServer.addDefaultHandlers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OSC.OSCServer的用法示例。


在下文中一共展示了OSCServer.addDefaultHandlers方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: OSCPlotter

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addDefaultHandlers [as 别名]
class OSCPlotter(object):

    """Set up OSC server and other handlers."""

    def __init__(self, port, scope):
        host="localhost"
        logger.info( "Initializing server at %s:%d"%(host,port))
        try:
            self.m_oscserver = OSCServer( (host, port) )
        except:
            logger.fatal("System:Unable to create OSC handler at %s:%d"%(host,port),exc_info=True)
            sys.exit(1)
        self.m_oscserver.timeout = 0
        self.m_oscserver.print_tracebacks = True
        self.m_scope = scope
        self.m_fnum = 0
        
        # add a method to an instance of the class
        self.m_oscserver.handle_timeout = types.MethodType(handle_timeout,self.m_oscserver)

        # this registers a 'default' handler (for unmatched messages), 
        # an /'error' handler, an '/info' handler.
        # And, if the client supports it, a '/subscribe' &
        # '/unsubscribe' handler
        self.m_oscserver.addDefaultHandlers()
        self.m_oscserver.addMsgHandler("default", self.default_handler)
        self.m_oscserver.addMsgHandler("/pf/frame", self.pf_frame)
#        self.m_oscserver.addMsgHandler("/pf/update", self.pf_update)
        self.m_oscserver.addMsgHandler("/conductor/attr", self.cond_attr)

    def handle(self):
        self.m_oscserver.handle_request()

    def cond_attr(self, path, tags, args, source):
        attr=args[0]
        uid=args[1]
        value=args[2]
        logger.info("%d.%s=%f"%(uid,attr,value))
        if attr=="kinetic":
            self.m_scope.append(uid,self.m_fnum,value)
            
    def pf_update(self, path, tags, args, source):
        t=args[1]
        uid=args[2]
        x=args[3]
        logger.debug("uid=%d,t=%f, x=%f"%(uid,t,x))
#        self.m_scope.append(uid,t,x)

    def pf_frame(self, path, tags, args, source):
        self.m_fnum=args[0]
        if self.m_fnum%5==0:
            self.m_scope.update(self.m_fnum)
        
    def default_handler(self, path, tags, args, source):
#        logger.debug("got message for "+path+" with tags "+tags)
        return None
开发者ID:wmodes,项目名称:crs,代码行数:58,代码来源:oscplotter.py

示例2: initOSCServer

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addDefaultHandlers [as 别名]
def initOSCServer(ip='127.0.0.1', port=9001, mode=0) :
    """ mode 0 for basic server, 1 for threading server, 2 for forking server
    """
    global server, st

    if mode == 0 :
        server = OSCServer( (ip ,port) ) # basic
    elif mode == 1 : 
        server = ThreadingOSCServer( (ip ,port) ) # threading
    elif mode == 2 :
        server = ForkingOSCServer( (ip ,port) ) # forking

    server.addDefaultHandlers()
开发者ID:UIKit0,项目名称:RAMDanceToolkit,代码行数:15,代码来源:simpleOSC.py

示例3: __init__

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addDefaultHandlers [as 别名]
class OscServer:
    def __init__(self, port, cbks = None):
        self.server = OSCServer( ("localhost", port) )
        self.server.addDefaultHandlers()
        self.thread = threading.Thread(target = self.server.serve_forever)

        if cbks is not None:
            for path, cbk in cbks:
                self.on_msg(path, cbk)

    def on_msg(self, path, f):
        def go_zero(path, tags, args, source):
            f()            

        def go_args(path, tags, args, source):
            f(*args)

        if f.func_code.co_argcount == 0:
            go = go_zero
        else:
            go = go_args

        self.server.addMsgHandler(path, go)

    def start(self):
        self.thread.start()
        try :
            while 1 :
                time.sleep(10) 
        except KeyboardInterrupt :
            print "\nClosing OSCServer."
            self.server.close()
            print "Waiting for Server-thread to finish"
            self.thread.join()
            print "Done"

    def close(self):
        self.server.close()    
        try:
            self.thread.join()
        except:
            pass
        print "Done"
开发者ID:anton-k,项目名称:osc-studio,代码行数:45,代码来源:adder.py

示例4: main

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addDefaultHandlers [as 别名]
def main():
    #incoming(HOST,PORT)
    server = OSCServer(('127.0.0.1',42003))
    client = OSC.OSCClient()
    client.connect(('127.0.0.1',42002))

    server.addDefaultHandlers()
    server.addMsgHandler("/exo/hand/gesture",handler_func)

    st = threading.Thread( target = server.serve_forever )
    st.start()

    try :
        while 1 :
                time.sleep(10)
    except KeyboardInterrupt :
        print "\nClosing OSCServer."
        s.close()
        print "Waiting for Server-thread to finish"
        st.join()
        print "Done"

    server.close()
开发者ID:momochen,项目名称:smart-glove,代码行数:25,代码来源:read_port.py

示例5: OSCHandler

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addDefaultHandlers [as 别名]
class OSCHandler(object):

    """Set up OSC server and other handlers."""

    def __init__(self, field):
        self.m_field = field
        self.m_server = OSCServer( (OSCHOST, OSCPORT) )
        self.m_server.timeout = OSCTIMEOUT
        self.m_run = True

        self.m_xmin = 0
        self.m_ymin = 0
        self.m_xmax = 0
        self.m_ymax = 0

        self.eventfunc = {
            'ping': self.event_tracking_ping,
            'ack': self.event_tracking_ack,
            'start': self.event_tracking_start,
            'entry': self.event_tracking_entry,
            'exit': self.event_tracking_exit,
            'frame': self.event_tracking_frame,
            'stop': self.event_tracking_stop,
            'minx': self.event_tracking_set,
            'miny': self.event_tracking_set,
            'maxx': self.event_tracking_set,
            'maxy': self.event_tracking_set,
            'npeople': self.event_tracking_set,
            'groupdist': self.event_tracking_set,
            'ungroupdist': self.event_tracking_set,
            'fps': self.event_tracking_set,
            'update': self.event_tracking_update,
            'leg': self.event_tracking_leg,
            'body': self.event_tracking_body,
        }

        # add a method to an instance of the class
        self.m_server.handle_timeout = types.MethodType(handle_timeout, self.m_server)

        for i in self.eventfunc:
            self.m_server.addMsgHandler(OSCPATH[i], self.eventfunc[i])

        # this registers a 'default' handler (for unmatched messages), 
        # an /'error' handler, an '/info' handler.
        # And, if the client supports it, a '/subscribe' &
        # '/unsubscribe' handler
        self.m_server.addDefaultHandlers()
        self.m_server.addMsgHandler("default", self.default_handler)
        # TODO: Handle errors from OSCServer
        #self.m_server.addErrorHandlers()
        #self.m_server.addMsgHandler("error", self.default_handler)
        self.honey_im_home()

    def honey_im_home(self):
        """Broadcast a hello message to the network."""
        # TODO: Broadcast hello message
        return True

    def each_frame(self):
        # clear timed_out flag
        self.m_server.timed_out = False
        # handle all pending requests then return
        while not self.m_server.timed_out:
            self.m_server.handle_request()

    def user_callback(self, path, tags, args, source):
        # which user will be determined by path:
        # we just throw away all slashes and join together what's left
        user = ''.join(path.split("/"))
        # tags will contain 'fff'
        # args is a OSCMessage with data
        # source is where the message came from (in case you need to reply)
        if dbug.LEV & dbug.MSGS: print ("Now do something with", user,args[2],args[0],1-args[1]) 

    def quit_callback(self, path, tags, args, source):
        # don't do this at home (or it'll quit blender)
        self.m_run = False

    # Event handlers

    def default_handler(self, path, tags, args, source):
        if dbug.LEV & dbug.MORE: print "OSC:default_handler:No handler registered for ", path
        return None

    def event_tracking_ping(self, path, tags, args, source):
        if dbug.LEV & dbug.MSGS: print "OSC:event_ping:code",args[0]
        return None

    def event_tracking_ack(self, path, tags, args, source):
        if dbug.LEV & dbug.MSGS: print "OSC:event_ack:code",args[0]
        return None

    def event_tracking_start(self, path, tags, args, source):
        """Tracking system is starting.

        Sent before first /pf/update message for that target
        args:
            [ aparently no params now]
            samp - sample number
            t - time of sample (elapsed time in seconds since beginning of run)
#.........这里部分代码省略.........
开发者ID:jestinbrooks,项目名称:crs,代码行数:103,代码来源:oschandlers.py

示例6: serve

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addDefaultHandlers [as 别名]
def serve(tree, wavdata, ps_correl_port, n_results, sc_synth_port, bus_num):
    all_corrs = wavdata['all_corrs']
    sample_times = wavdata['sample_times']
    amps = wavdata['amp']
    
    sc_synth_facing_server = OSCServer(("127.0.0.1", ps_correl_port))
    sc_synth_client = sc_synth_facing_server.client
    sc_synth_facing_server.addDefaultHandlers()

    def transect_handler(osc_path=None, osc_tags=None, osc_args=None, osc_source=None):
        node = osc_args[0]
        idx = osc_args[1]
        curr_amp = float(osc_args[2])
        lookup = osc_args[3:] #ignores the amplitude
        dists, indices = tree.query(lookup, k=n_results, return_distance=True)
        dists = dists.flatten()
        indices = indices.flatten()
        print "hunting", lookup
        times = sample_times[indices]
        makeup_gains = (curr_amp/amps[indices])
        # send scsynth bus messages
        print "dispatching", bus_num, n_results*3, times, makeup_gains, dists
        msg = OSCMessage("/c_setn", [bus_num, n_results*3])
        #msg.extend() 
        msg.extend(times)
        msg.extend(makeup_gains)
        msg.extend(dists)
        sc_synth_client.sendto(msg, ("127.0.0.1", sc_synth_port))

    # This currently never gets called as pyOSC will ignore everything
    # apart from the scsynth instance, in defiance of my understanding of UDP
    # Need to set up an additional OSC server on a new port
    # or somehow relay through scsynth
    def quit_handler(path=None, tags=None, args=None, source=None):
        print "quit", path, tags, args, source
        sc_synth_facing_server.close()

    def null_handler(path=None, tags=None, args=None, source=None):
        pass

    sc_synth_facing_server.addMsgHandler("/transect", transect_handler )
    sc_synth_facing_server.addMsgHandler("/quit", quit_handler )
    #sc_synth_facing_server.print_tracebacks = True

    sc_synth_client.sendto(OSCMessage("/notify", 1),("127.0.0.1", sc_synth_port))

    print sc_synth_facing_server.server_address, sc_synth_client.address(), sc_synth_facing_server.getOSCAddressSpace()

    sc_synth_facing_server.running = True

    # i = 0
    # ptime = time.time()
    # while True:
    #     i=i+1
    #     ntime = time.time()
    #     deltime = ntime - ptime
    #     if deltime>=1.0:
    #         print i, deltime
    #         ptime = ntime
    #     sc_synth_facing_server.handle_request()
    #     sc_lang_facing_server.handle_request()
    #
    # print "NOOOOOO"
    # sc_synth_facing_server.close()
    # sc_lang_facing_server.close()
    return sc_synth_facing_server
    
开发者ID:howthebodyworks,项目名称:pattern_machine,代码行数:68,代码来源:ps_correl_serve.py

示例7: initOSCServer

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addDefaultHandlers [as 别名]
def initOSCServer(ip='localhost', port=8885) :
    global server, st
    server = OSCServer( (ip ,port) ) # basic
    server.addDefaultHandlers()
    print server
开发者ID:yiwenl,项目名称:C4dPythonOsc,代码行数:7,代码来源:pythonOscServer.py

示例8: OSCHandler

# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addDefaultHandlers [as 别名]
class OSCHandler(object):

    """Set up OSC server and other handlers."""

    def __init__(self, field=None, conductor=None):
        self.m_conductor = conductor
        self.cidkeys={}
        self.lastcid=1
        self.m_field = field
        self.m_run = True
        self.m_downClients={}
        self.m_missingHandlers={}
        self.m_xmin = 0
        self.m_ymin = 0
        self.m_xmax = 0
        self.m_ymax = 0
        self.m_health = 0
        
        # Setup OSC server and clients
        osc_server = []
        osc_clients = []
        for host in OSC_IPS:
            if host == IAM:
                logger.info("setting server for %s to %s: %s",host,OSC_IPS[host],OSC_PORTS[host])
                osc_server = [('server', OSC_IPS[host], OSC_PORTS[host])]
            elif host == 'localhost' or host == 'default':
                continue
            else:
                logger.info("setting client for %s to %s:%s",host,OSC_IPS[host],OSC_PORTS[host])
                osc_clients.append((host, OSC_IPS[host], OSC_PORTS[host]))

        (name, host, port) = osc_server[0]
        self.m_oscserver = OSCServer( (host, port) )
        logger.info( "Initializing server at %s:%s",host, port)
        self.m_oscserver.timeout = config.osctimeout
        self.m_oscserver.print_tracebacks = True

        self.m_osc_clients = {}
        for i in range(len(osc_clients)):
            (name, host, port) = osc_clients[i]
            for j in range(i):
                (oldname, oldhost, oldport) = osc_clients[j]
                if host == oldhost and port == oldport:
                    self.m_osc_clients[name] = self.m_osc_clients[oldname]
                    logger.warning( "%s same as %s",name,oldname)
                    break
            if not name in self.m_osc_clients:
                try:
                    self.m_osc_clients[name] = OSCClient()
                except socket.error:
                    logger.error( "Unable to create OSC handler for client %s at %s:%s",name,host,port,exc_info=True)
                self.m_osc_clients[name].connect( (host, port) )
                logger.info( "Connecting to %s at %s:%s",name,host,port)
            self.send_to(name,"/ping",[0])

        # common
        self.m_oscserver.addMsgHandler("/ping",self.event_ping)
        self.m_oscserver.addMsgHandler( "/ack",self.event_ack)

        # from tracker
        self.m_oscserver.addMsgHandler("/pf/started",self.event_tracking_start)
        self.m_oscserver.addMsgHandler("/pf/stopped",self.event_tracking_stop)
        self.m_oscserver.addMsgHandler("/pf/entry",self.event_tracking_entry)
        self.m_oscserver.addMsgHandler("/pf/exit",self.event_tracking_exit)
        self.m_oscserver.addMsgHandler("/pf/frame",self.event_tracking_frame)
        self.m_oscserver.addMsgHandler("/pf/set/minx",self.event_tracking_set)
        self.m_oscserver.addMsgHandler("/pf/set/miny",self.event_tracking_set)
        self.m_oscserver.addMsgHandler("/pf/set/maxx",self.event_tracking_set)
        self.m_oscserver.addMsgHandler("/pf/set/maxy",self.event_tracking_set)
        self.m_oscserver.addMsgHandler("/pf/set/npeople",self.event_tracking_set)
        self.m_oscserver.addMsgHandler("/pf/set/groupdist",self.event_tracking_set)
        self.m_oscserver.addMsgHandler("/pf/set/ungroupdist",self.event_tracking_set)
        self.m_oscserver.addMsgHandler("/pf/set/fps",self.event_tracking_set)
        self.m_oscserver.addMsgHandler("/pf/update",self.event_tracking_update)
        self.m_oscserver.addMsgHandler("/pf/leg",self.event_tracking_leg)
        self.m_oscserver.addMsgHandler("/pf/body",self.event_tracking_body)
        self.m_oscserver.addMsgHandler("/pf/group",self.event_tracking_group)
        self.m_oscserver.addMsgHandler("/pf/geo",self.event_tracking_geo)

        # to conductor
        self.m_oscserver.addMsgHandler( "/conductor/dump",self.event_conduct_dump)
        # global sensitivity for conx attr
        self.m_oscserver.addMsgHandler( "/ui/condglobal",self.event_ui_condglobal)
        # global sensitivity for cell attr
        self.m_oscserver.addMsgHandler( "/ui/cellglobal",self.event_ui_cellglobal)

        for atype in CELL_ATTR_TYPES + CONX_ATTR_TYPES:
            for param in ("trigger", "memory", "maxage","qual","qualmin","qualmax"):
                self.m_oscserver.addMsgHandler("/ui/cond/"+atype+"/"+param,self.event_ui_condparam)

        # add a method to an instance of the class
        self.m_oscserver.handle_timeout = types.MethodType(handle_timeout, self.m_oscserver)

        # this registers a 'default' handler (for unmatched messages), 
        # an /'error' handler, an '/info' handler.
        # And, if the client supports it, a '/subscribe' &
        # '/unsubscribe' handler
        self.m_oscserver.addDefaultHandlers()
        self.m_oscserver.addMsgHandler("default", self.default_handler)

#.........这里部分代码省略.........
开发者ID:wmodes,项目名称:crs,代码行数:103,代码来源:oschandler.py


注:本文中的OSC.OSCServer.addDefaultHandlers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。