本文整理汇总了Python中OSC.OSCServer.addMsgHandler方法的典型用法代码示例。如果您正苦于以下问题:Python OSCServer.addMsgHandler方法的具体用法?Python OSCServer.addMsgHandler怎么用?Python OSCServer.addMsgHandler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSC.OSCServer
的用法示例。
在下文中一共展示了OSCServer.addMsgHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
def setup():
print "setup"
global currentButtonState, lastDownTime, isRecording, audioInput
global messageQ, clientMap, oscIn, oscOut, oscThread, mAudioServer
messageQ = PriorityQueue()
clientMap = {}
## setup osc client
oscOut = OSCClient()
## setup osc receiver
oscIn = OSCServer((OSC_IN_ADDRESS, OSC_IN_PORT))
oscIn.addMsgHandler('default', _oscHandler)
oscThread = Thread(target = oscIn.serve_forever)
oscThread.start()
print "osc in ready"
## setup audio server
mAudioServer = ThreadedServer()
mAudioServer.start()
## setup gpio
GPIO.setmode(GPIO.BCM)
GPIO.setup(SWITCH_PIN, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(LED_PIN, GPIO.OUT)
GPIO.output(LED_PIN, GPIO.LOW)
currentButtonState = GPIO.input(SWITCH_PIN)
lastDownTime = 0
isRecording = False
_setupAudio()
示例2: main
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
def main():
print("Waiting for boot signal")
print(s.read())
print("Writing sway command")
s.write("".join(map(chr, [0x55, 0x0, 0x3, 0, 2, 72])))
print(s.read())
# print("Reading motor encoders")
# s.write("".join(map(chr, [0x55, 0x1, 0x12])))
# print(["0x%.02x " % ord(x) for x in s.read(12)])
server = OSCServer( ("192.168.123.75", 10000) )
server.timeout = 0
# funny python's way to add a method to an instance of a class
import types
server.handle_timeout = types.MethodType(handle_timeout, server)
server.addMsgHandler( "/rotate", rotate_callback )
server.addMsgHandler( "/bf", bf_callback )
try:
while 1:
server.handle_request()
except KeyboardInterrupt:
pass
server.close()
示例3: setupServer
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
def setupServer():
global server
server = OSCServer( (HOST_NAME, PORT_NUM) )
server.timeout = 0
server.handle_timeout = types.MethodType(handle_timeout, server)
server.addMsgHandler( "/dmx", user_callback )
print(server)
示例4: main
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
def main():
print("Waiting for boot signal")
print(s.read())
print("Writing sway command")
s.write("".join(map(chr, [0x55, 0x0, 0x3, 0, 2, 72]))) # equivalent to .join['U', '\x00', '\x03', '\x00', '\x02', 'H']
# between every elements in the list, put ""
# that will convert it as one string ''Ux00x03x00x02H''
print(s.read())
# print("Reading motor encoders")
# s.write("".join(map(chr, [0x55, 0x1, 0x12])))
# print(["0x%.02x " % ord(x) for x in s.read(12)])
server = OSCServer( ("192.168.123.75", 10000) )
server.timeout = 0
# funny python's way to add a method to an instance of a class
import types
server.handle_timeout = types.MethodType(handle_timeout, server)
server.addMsgHandler( "/rotate", rotate_callback )
server.addMsgHandler( "/bf", bf_callback )
try:
while 1:
server.handle_request()
except KeyboardInterrupt:
pass
server.close()
示例5: __init__
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
class OSCServerClass:
def __init__(self, id, ip, port):
self.robot = id
self.bridge = MeccaBridge()
self.server = OSCServer((ip, port))
self.server.timeout = 0
self.active = True
self.server.handle_timeout = types.MethodType(handle_timeout, self.server)
self.server.addMsgHandler("/" + self.robot + "/pinMove" , self.pinMoveHandler )
self.server.addMsgHandler("/" + self.robot + "/pinLight" , self.pinLightHandler )
self.server.addMsgHandler("/" + self.robot + "/init" , self.initHandler )
self.server.addMsgHandler("/" + self.robot + "/headLight", self.headLightHandler)
self.gotMessage = False
#######################################################################
def run(self):
print("serving on {}".format(self.server.server_address))
self.server.running = True
while self.server.running:
while True:
self.server.handle_request()
if not self.gotMessage:
break
self.gotMessage = False
self.bridge.sendMessages()
time.sleep(0.01);
######################################################################
def pinMoveHandler(self, path, tags, args, source):
#print(path + "\n")
#print ', '.join(map(str, args))
self.bridge.sendServoPosition(args[0], args[1], args[2], args[3])
self.gotMessage = True
######################################################################
def pinLightHandler(self, path, tags, args, source):
self.bridge.sendPinLight(args[0], args[1], args[2])
self.gotMessage = True
######################################################################
def initHandler(self, path, tags, args, source):
self.bridge.sendInit(args[0], args[1])
self.gotMessage = True
######################################################################
def headLightHandler(self, path, targs, args, source):
self.bridge.sendHeadLight(args[0], args[1], args[2], args[3])
self.gotMessage = True
示例6: handle_request
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
class ColorsIn:
# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def set_colors(self,path, tags, args, source):
# which user will be determined by path:
# we just throw away all slashes and join together what's left
#print "Here's what we got : path:%s tags:%s args:%s source:%s"%(str(path),str(tags),str(args),str(source))
pixels = []
for i in range(0,len(args)/3):
pixel = (clamp(args[i*3]), clamp(args[i*3+1]), clamp(args[i*3+2]))
pixels.append( pixel )
#print "Pixels: %s"%str(pixels)
#print "Time: "+str((time.time()*1000) % 10000)
octoapi.write(pixels)
self.lastwrite=time.time()
self.server.lastpixels = pixels
def diff_colors(self, path, tags, args, source):
# which user will be determined by path:
# we just throw away all slashes and join together what's left
#print "Here's what we got : path:%s tags:%s args:%s source:%s"%(str(path),str(tags),str(args),str(source))
pixels = server.lastpixels
for i in range(0,len(args)/3):
pp = (args[i*3],args[i*3+1],args[i*3+2])
p = pixels[i]
pixels[i] = (clamp(p[0]+pp[0]), clamp(p[1]+pp[1]), clamp(p[2]+pp[2]))
#print "Pixels: %s"%str(pixels)
#print "Time: "+str((time.time()*1000) % 10000)
octoapi.write(pixels)
self.lastwrite=time.time()
self.server.lastpixels = pixels
def each_frame(self):
self.server.timed_out = False
while not self.server.timed_out:
if time.time() - self.lastwrite > CLEAR_TIME:
self.lastwrite = time.time()
octoapi.write([(0,0,0)]*24)
print "Clearing"
self.server.handle_request()
def start(self):
#server = OSCServer( ("128.174.251.39", 11661) )
self.server = OSCServer( ("localhost", 11661) )
self.server.timeout = 0
self.lastwrite = time.time()
self.server.handle_timeout = types.MethodType(handle_timeout, self.server)
self.server.lastpixels = [(0,0,0)]*24
self.server.addMsgHandler( "/setcolors", self.set_colors)
self.server.addMsgHandler( "/diffcolors", self.diff_colors)
while True:
self.each_frame()
self.server.close()
示例7: Manta
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
class Manta(object):
def __init__(self, receive_port=31416, send_port=31417, send_address='127.0.0.1'):
self.osc_client = OSCClient()
self.osc_server = OSCServer(('127.0.0.1', receive_port))
self.osc_client.connect(('127.0.0.1', send_port))
# set the osc server to time out after 1ms
self.osc_server.timeout = 0.001
self.event_queue = []
self.osc_server.addMsgHandler('/manta/continuous/pad',
self._pad_value_callback)
self.osc_server.addMsgHandler('/manta/continuous/slider',
self._slider_value_callback)
self.osc_server.addMsgHandler('/manta/continuous/button',
self._button_value_callback)
self.osc_server.addMsgHandler('/manta/velocity/pad',
self._pad_velocity_callback)
self.osc_server.addMsgHandler('/manta/velocity/button',
self._button_velocity_callback)
def process(self):
self.osc_server.handle_request()
ret_list = self.event_queue
self.event_queue = []
return ret_list
def _pad_value_callback(self, path, tags, args, source):
self.event_queue.append(PadValueEvent(args[0], args[1]))
def _slider_value_callback(self, path, tags, args, source):
touched = False if args[1] == 0xffff else True
scaled_value = args[1] / 4096.0
self.event_queue.append(SliderValueEvent(args[0], touched, scaled_value))
def _button_value_callback(self, path, tags, args, source):
pass
def _pad_velocity_callback(self, path, tags, args, source):
self.event_queue.append(PadVelocityEvent(args[0], args[1]))
def _button_velocity_callback(self, path, tags, args, source):
self.event_queue.append(ButtonVelocityEvent(args[0], args[1]))
def _send_osc(self, path, *args):
msg = OSCMessage(path)
msg.append(args)
self.osc_client.send(msg)
def set_led_enable(self, led_type, enabled):
self._send_osc('/manta/ledcontrol', led_type, 1 if enabled else 0)
def set_led_pad(self, led_state, pad_index):
self._send_osc('/manta/led/pad', led_state, pad_index)
示例8: OscServerThread
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
class OscServerThread(Thread):
def __init__(self, host, stopEvent):
Thread.__init__(self)
self.server = OSCServer(host)
self.stopEvent = stopEvent
def setCallBacks(self, callBacks):
for callBack in callBacks:
self.server.addMsgHandler(callBack[0], callBack[1])
def run(self):
while not self.stopEvent.is_set():
self.server.handle_request()
self.server.close()
示例9: _get_osc_test_server
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
def _get_osc_test_server(self, port=None):
def intercepting_handler(addr, tags, data, source):
msg_string = "%s [%s] %s" % (addr, tags, str(data))
sys.stdout.write(
"OSCServer Got: '%s' from %s\n" % (
msg_string, getUrlStr(source)
))
self.testQueue.put(data)
port = port or self.remote_osc_address[1]
s = OSCServer(('localhost', port))
s.addMsgHandler('default', intercepting_handler)
return s
示例10: app
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
def app():
global dxlIO, server, client
ports = pypot.dynamixel.get_available_ports()
if not ports:
raise IOError('No port available.')
dxlIO = pypot.dynamixel.DxlIO(ports[0])
availableIDs = dxlIO.scan()
server = OSCServer(('0.0.0.0', 8000))
for motorID in availableIDs:
server.addMsgHandler('/motor/' + str(motorID), motorHandler) # Register OSC handlers for each found ID
client = OSCClient()
client.connect(('localhost', 8001))
print 'Ready. Found ID(s) ' + str(availableIDs)
while True:
server.handle_request()
sleep(0.01)
示例11: main
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
def main(hostname="localhost",port="8000"):
server = OSCServer((hostname, int(port)))
server.timeout = 0
run = True
global message_count
message_count = 0
# this method of reporting timeouts only works by convention
# that before calling handle_request() field .timed_out is
# set to False
def handle_timeout(self):
self.timed_out = True
# funny python's way to add a method to an instance of a class
import types
server.handle_timeout = types.MethodType(handle_timeout, server)
def user_callback(path, tags, args, source):
log("%s %s\n" % (path, args))
global message_count
message_count += 1
def quit_callback(path, tags, args, source):
#global run
run = False
server.addMsgHandler( "default", user_callback )
server.addMsgHandler( "/quit", quit_callback )
# user script that's called by the game engine every frame
def each_frame():
log("Messages received: %s\n" % message_count)
# clear timed_out flag
server.timed_out = False
# handle all pending requests then return
while not server.timed_out:
server.handle_request()
# simulate a "game engine"
print "Server running at %s:%s" % (hostname, port)
while run:
# do the game stuff:
sleep(1)
# call user script
each_frame()
server.close()
示例12: OSC_MPD
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
class OSC_MPD(object):
def __init__(self, osc=('0.0.0.0', 8000), mpd=('127.0.0.1', 6600)):
self.mpc = MPDClient()
self.mpc.connect(mpd[0], mpd[1])
self.server = OSCServer(osc)
def musicManage(addr, tags, data, client_address):
cmd = addr.strip('/').split('/')[-1]
self.mpc.__getattr__(cmd)(*data)
self.server.addMsgHandler('/bearstech/music/play', musicManage)
self.server.addMsgHandler('/bearstech/music/pause', musicManage)
self.server.addMsgHandler('/bearstech/music/next', musicManage)
self.server.addMsgHandler('/bearstech/music/previous', musicManage)
self.server.addMsgHandler('/bearstech/music/stop', musicManage)
def serve_forever(self):
self.server.serve_forever()
示例13: server_start
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
def server_start(port=7110):
global server
server = OSCServer ( ("localhost", 7110))
server.timeout = 0
server.handle_timeout = types.MethodType(handle_timeout, server)
server.addMsgHandler("/sco", handle_score)
server.addMsgHandler("/cc", handle_cc)
server.addMsgHandler("/quit", quit_callback)
server.addMsgHandler("default", default_callback)
示例14: __init__
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [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"
示例15: OSCForwarder
# 需要导入模块: from OSC import OSCServer [as 别名]
# 或者: from OSC.OSCServer import addMsgHandler [as 别名]
class OSCForwarder(threading.Thread):
def __init__(self, from_ip, from_port, to_ip, to_port):
super(OSCForwarder, self).__init__()
# create the server to listen to messages arriving at from_ip
self.server = OSCServer( (from_ip, from_port) )
self.server.addMsgHandler( 'default', self.callback )
# create the clieent to forward those message to to_ip
self.client = OSCClient()
self.client.connect( (to_ip, to_port) )
print '%s:%d --> %s:%d' % (from_ip, from_port, to_ip, to_port)
self.done_running = False
# start the server listening for messages
self.start()
# close must be called before app termination or the app might hang
def close(self):
# this is a workaround of a bug in the OSC server
# we have to stop the thread first, make sure it is done,
# and only then call server.close()
self.server.running = False
while not self.done_running:
time.sleep(.01)
self.server.close()
def run(self):
#print "Worker thread entry point"
self.server.serve_forever()
self.done_running = True
def callback(self, path, tags, args, source):
#print 'got:', path, args, 'from:', source
self.client.send( OSCMessage(path, args ) )