本文整理汇总了Python中OSC.OSCClient.close方法的典型用法代码示例。如果您正苦于以下问题:Python OSCClient.close方法的具体用法?Python OSCClient.close怎么用?Python OSCClient.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSC.OSCClient
的用法示例。
在下文中一共展示了OSCClient.close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OscProxyClient
# 需要导入模块: from OSC import OSCClient [as 别名]
# 或者: from OSC.OSCClient import close [as 别名]
class OscProxyClient(object):
def __init__(self,
remote_osc_address,
json_to_osc_q,
osc_command_name,
bridge=None,
*args, **kwargs):
self.remote_osc_address = remote_osc_address
self.json_to_osc_q = json_to_osc_q
self.osc_client = OSCClient()
self.osc_client.connect(remote_osc_address)
self.osc_command_name = osc_command_name
self.bridge = bridge
def serve_forever(self):
for msg in self.json_to_osc_q:
osc_msg = OSCMessage(self.osc_command_name)
osc_msg.append(msg[0]) #HTTP verb
osc_msg.append(msg[1]) #HTTP path
osc_msg.append(msg[2]) #content
self.osc_client.send(osc_msg)
def close(self):
self.osc_client.close()
示例2: unpack
# 需要导入模块: from OSC import OSCClient [as 别名]
# 或者: from OSC.OSCClient import close [as 别名]
def unpack(data, totalCoordinates, socket):
cX = totalCoordinates[0]
cY = totalCoordinates[1]
client = OSCClient()
client.connect(("localhost", socket))
""" Prepare and send OSC bundles to Max from a list of tuples of coordinates. """
def bundlePolyline(coordinates, speed, polylineType, passengers, coordsX, coordsY):
for pair in coordinates:
# create an OSC bundle:
bundle = OSCBundle()
# append polylineType: "trip" or "delay" (data for in between current and next trip)
bundle.append({'addr': "/curr", 'args': [polylineType]})
# append min/max longX and latY to bundle:
bundle.append({'addr': "/minX", 'args': [min(coordsX)]})
bundle.append({'addr': "/maxX", 'args': [max(coordsX)]})
bundle.append({'addr': "/minY", 'args': [min(coordsY)]})
bundle.append({'addr': "/maxY", 'args': [max(coordsY)]})
# append longX and latY to bundle
bundle.append({'addr': "/longX", 'args': [pair[0]]})
bundle.append({'addr': "/latY", 'args': [pair[1]]})
# append start/end longX and latY of coordinates list
xVals = [coords[0] for coords in coordinates]
bundle.append({'addr': "/startX", 'args': [xVals[0]]})
bundle.append({'addr': "/endX", 'args': [xVals[len(xVals) - 1]]})
yVals = [coords[1] for coords in coordinates]
bundle.append({'addr': "/startY", 'args': [yVals[0]]})
bundle.append({'addr': "/endY", 'args': [yVals[len(yVals) - 1]]})
# append passengers
bundle.append({'addr': "/passengers", 'args': [passengers]})
# send bundle to Max:
client.send(bundle)
# delay time to even out polyline steps
time.sleep(speed)
""" Read the next line in the data file. """
for row in data:
""" Parse and set time stamps in minutes (i.e. 4:02 == 242). """
pickup = row["pickuptime"].split(" ")[1]
pickup = pickup.split(":")
pickup = (int(pickup[0])*60) + int(pickup[1])
dropoff = row["dropofftime"].split(" ")[1]
dropoff = dropoff.split(":")
dropoff = (int(dropoff[0])*60) + int(dropoff[1])
nextPickup = row["nextpickuptime"].split(" ")[1]
nextPickup = nextPickup.split(":")
nextPickup = (int(nextPickup[0])*60) + int(nextPickup[1])
""" Decode trippolyline. """
latLongList = polylinemapper.decode(row["trippolyline"])
passengers = row["passengers"]
latLongSpeed = round((dropoff - pickup) / (2*len(latLongList)), 10) # translate 1 minute in RT == 0.5 seconds
bundlePolyline(latLongList, latLongSpeed, "trip", passengers, cX, cY)
""" Decode nextpolyline. """
nextLatLong = polylinemapper.decode(row["nextpolyline"])
passengers = 0
nextSpeed = round((nextPickup - dropoff) / (2*len(nextLatLong)), 10) # translate 1 minute in RT == 0.5 seconds
bundlePolyline(nextLatLong, nextSpeed, "delay", passengers, cX, cY)
client.close()
示例3: OSCClient
# 需要导入模块: from OSC import OSCClient [as 别名]
# 或者: from OSC.OSCClient import close [as 别名]
from OSC import OSCClient, OSCMessage
app= OSCClient()
app.connect(('127.0.0.1', 61000)) #send address
msg= OSCMessage('/stop')
msg.append(100)
app.send(msg) #fade out over 100 frames
app.close()
示例4: range
# 需要导入模块: from OSC import OSCClient [as 别名]
# 或者: from OSC.OSCClient import close [as 别名]
from OSC import OSCClient, OSCBundle
socket = 15800
for x in range(4):
client = OSCClient()
client.connect(("localhost", socket))
bundle = OSCBundle()
bundle.append({'addr': "/curr", 'args': [" "]})
bundle.append({'addr': "/minX", 'args': [0]})
bundle.append({'addr': "/maxX", 'args': [0]})
bundle.append({'addr': "/minY", 'args': [0]})
bundle.append({'addr': "/maxY", 'args': [0]})
bundle.append({'addr': "/longX", 'args': [0]})
bundle.append({'addr': "/latY", 'args': [0]})
bundle.append({'addr': "/startX", 'args': [0]})
bundle.append({'addr': "/endX", 'args': [0]})
bundle.append({'addr': "/startY", 'args': [0]})
bundle.append({'addr': "/endY", 'args': [0]})
bundle.append({'addr': "/passengers", 'args': [0]})
client.send(bundle)
client.close()
socket += 1
示例5: KeykitShell
# 需要导入模块: from OSC import OSCClient [as 别名]
# 或者: from OSC.OSCClient import close [as 别名]
class KeykitShell(cmd.Cmd):
intro = """
Welcome to the Keykit shell. Type help or ? to list commands.
Connect to local keykit server with 'connect port'.
Exit shell with 'bye'.
"""
remote_server_adr = (PYCONSOLE_HOSTNAME, PYCONSOLE_PORT)
local_server_adr = (MY_HOSTNAME, PYCONSOLE_PORT + 1)
prompt = ''
def __init__(self, *args, **kwargs):
cmd.Cmd.__init__(self, args, kwargs)
self.client = None
self.server = None
# Start client and server with default values
self.init()
def init(self):
# Client
if(self.client is not None):
self.client.close()
self.client = OSCClient()
try:
self.client.connect(self.remote_server_adr)
except ValueError:
warn("Connectiong failed. Invalid port?")
# Server
if self.server is not None:
self.server.stop()
self.server_thread.join()
self.server = Server(self.local_server_adr)
self.server_thread = Thread(target=self.server.start)
self.server_thread.start()
# Inform keykit programm to use this as target
try:
self.client.send(OSCMessage("/keykit/pyconsole/target",
list(self.local_server_adr)))
except OSCClientError:
warn("Sending of /target message failed. Pyconsole.k offline?")
def emptyline(self):
"""Do nothing on empty input line"""
pass
# ----- internal shell commands -----
def do_connect(self, arg):
"""Connect to OSC-Server: connect [PORT] [HOSTNAME]
Default PORT: %i
Default HOSTNAME: %s
"""
words = arg.split(' ')
if len(words) > 1:
self.remote_server_adr = (str(words[1]), int(words[0]))
elif len(words) > 0:
self.remote_server_adr = (self.remote_server_adr[0], int(words[0]))
self.local_server_adr = (
self.local_server_adr[0],
self.remote_server_adr[1] + 1)
self.init()
do_connect.__doc__ %= (remote_server_adr[1], remote_server_adr[0])
def do_verbose(self, arg):
"""Set verbose level variable of pyconsole.k: verbose [0|1]"""
if arg == "":
arg = "1"
try:
self.client.send(
OSCMessage("/keykit/pyconsole/verbose", [int(arg)]))
except OSCClientError:
warn("Sending failed")
def do_bye(self, arg):
"""Close keykit shell window and exit: bye
It mutes the output of keykit, too.
"""
warn('Quitting keykit shell.')
# self.send("stop()")
self.send("alloff()")
self.close()
return True
'''
def do_exit(self, arg):
"""Close keykit shell window and exit: exit"""
return self.do_bye(arg)
def do_quit(self, arg):
"""Close keykit shell window and exit: quit"""
return self.do_bye(arg)
'''
loopVarIdx = 0
#.........这里部分代码省略.........
示例6: retrieve
# 需要导入模块: from OSC import OSCClient [as 别名]
# 或者: from OSC.OSCClient import close [as 别名]
class Kinect:
"""Manages connection to Kinect, and saves and processes coordinates"""
@staticmethod
def retrieve(joints=None, max_port=5555):
""" Retrieves a singleton Kinect instance, and creates it if it doesn't exist. """
global kinect_instance
if kinect_instance is None:
kinect_instance = Kinect(joints, max_port)
return kinect_instance
def __init__(self, joints=None, max_port=5555):
if joints is None:
self.joints = ['righthand', 'lefthand', 'rightfoot', 'leftfoot', 'head', 'torso']
else:
self.joints = joints
self.coords = {k:(0.,0.,0.) for k in self.joints}
self.prev_coords = {k:(0.,0.,0.) for k in self.joints}
self.joint_speed = {k:False for k in self.joints}
self.speed_piano = {'lefthand':{X:0, Y:0}, 'righthand':{X:0, Y:0}}
self.kinect_client = OSCClient()
self.max_client = OSCClient()
self.server = OSCServer(('127.0.0.1', 12345))
self.kinect_client.connect(('127.0.0.1', 12346))
self.max_client.connect(('127.0.0.1', max_port))
self.server.addMsgHandler('default', self.process_message)
self.flipped = False
self.speed = 0.
self.speed_ramp = 0.
sprout(self.server.serve_forever)
sprout(self._remind_synapse)
#sprout(self._calc_speed)
def __enter__(self):
return self
def __exit__(self, _type, value, traceback):
self.server.close()
self.kinect_client.close()
self.max_client.close()
def process_message(self, addr, tags, data, source):
"""process data coming in from Synapse, happens about every 0.03 seconds"""
if addr[-9:] == '_pos_body':
if self.flipped:
if addr[:5] == '/left':
addr = '/right' + addr[5:]
data[X] = -data[X]
elif addr[:6] == '/right':
addr = '/left'+addr[6:]
data[X] = -data[X]
self.coords[addr[1:-9]] = data
def _remind_synapse(self):
"""Send Synapse an OSC message to ask it to continue polling the required joints"""
while True:
for track in self.joints:
self.sendToKinect('/'+track+'_trackjointpos', 1)
time.sleep(1)
def calc_speed(self):
"""Calculate speed of movement, at 0.06 second intervals"""
self.calculating_speed = True
while self.calculating_speed:
total_speed = 0.
for joint, v in self.coords.items():
magnitude = Magnitude(v)
prev_magnitude = Magnitude(self.prev_coords[joint])
speed = abs(magnitude - prev_magnitude)
if joint in ('lefthand', 'righthand'):
speed_x = Distance(SubVector(self.prev_coords[joint], X),
SubVector(self.coords[joint], X))
speed_y = Distance(SubVector(self.prev_coords[joint], Y),
SubVector(self.coords[joint], Y))
self.speed_piano[joint][X] += (speed_x - self.speed_piano[joint][X]) * 0.5
self.speed_piano[joint][Y] += (speed_y - self.speed_piano[joint][Y]) * 0.5
total_speed += speed
total_speed /= len(self.coords)
self.speed = total_speed
self.speed_ramp = self.speed_ramp + (self.speed - self.speed_ramp) * 0.125
self.prev_coords = copy.copy(self.coords)
time.sleep(0.06)
@property
def area(self):
return Area( self.coords['head'],
self.coords['lefthand'],
self.coords['leftfoot'],
self.coords['rightfoot'],
self.coords['righthand'] ) / 1000000.
@property
def facing(self):
return self.coords['rightfoot'][X] >= self.coords['leftfoot'][X]
def hand_down(self, hand):
#.........这里部分代码省略.........