Created
November 21, 2014 09:28
-
-
Save jegger/bfc7ff026f0469501a5d to your computer and use it in GitHub Desktop.
OSC TUIO forwarder / multiplexer / touch ignorer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from OSC import OSCServer | |
from OSC import OSCClient | |
from OSC import OSCMessage | |
import time | |
import Queue | |
import threading | |
server = OSCServer(("localhost", 3333)) | |
# Client in thread | |
client = OSCClient() | |
client.connect(("localhost", 3334)) | |
# Format: [(xmin, ymin, xmax, ymax), ...] | |
ignore_list = [(0.9479166667, 0.046296296299999984, | |
0.9739583333, 0.09259259259999997), ] | |
def collide_ignore(x, y): | |
for l in ignore_list: | |
xmin, ymin, xmax, ymax = l | |
if xmin < x < xmax and ymin < y < ymax: | |
return True | |
def send(path, args): | |
if args[0] == "set": | |
if collide_ignore(args[2], args[3]): | |
print("Block") | |
msg = OSCMessage(path) | |
msg.append(args) | |
client.send(msg) | |
def loop(q): | |
while True: | |
path, args = q.get() | |
q.task_done() | |
send(path, args) | |
# Create thread & create queue | |
queue = Queue.Queue() | |
thread = threading.Thread(target=loop, args=(queue,)) | |
thread.daemon = True | |
thread.start() | |
def user_callback(path, tags, args, source): | |
print time.time() * 1000, path, args | |
queue.put((path, args)) | |
server.addMsgHandler("/tuio/2Dobj", user_callback) | |
server.addMsgHandler("/tuio/2Dcur", user_callback) | |
while True: | |
server.handle_request() | |
server.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from OSC import OSCServer | |
from OSC import OSCClient | |
from OSC import OSCMessage | |
import time | |
server = OSCServer(("localhost", 3334)) | |
def user_callback(path, tags, args, source): | |
print time.time() * 1000, path, args | |
server.addMsgHandler("/tuio/2Dobj", user_callback) | |
server.addMsgHandler("/tuio/2Dcur", user_callback) | |
while True: | |
server.handle_request() | |
server.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment