Skip to content

Commit

Permalink
replace vendored lib/OSC and lib/oscAPI with oscpy
Browse files Browse the repository at this point in the history
  • Loading branch information
tshirtman committed Apr 28, 2018
1 parent 8921b6a commit 667d866
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 821 deletions.
34 changes: 15 additions & 19 deletions kivy/input/providers/tuio.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 39,8 @@ def build(self):
__all__ = ('TuioMotionEventProvider', 'Tuio2dCurMotionEvent',
'Tuio2dObjMotionEvent')

from kivy.lib import osc
from functools import partial
from oscpy.server import OSCThreadServer
from collections import deque
from kivy.input.provider import MotionEventProvider
from kivy.input.factory import MotionEventFactory
Expand Down Expand Up @@ -131,21 132,19 @@ def create(oscpath, **kwargs):

def start(self):
'''Start the TUIO provider'''
self.oscid = osc.listen(self.ip, self.port)
self.oscid = osc = OSCThreadServer()
osc.listen(self.ip, self.port, default=True)
for oscpath in TuioMotionEventProvider.__handlers__:
self.touches[oscpath] = {}
osc.bind(self.oscid, self._osc_tuio_cb, oscpath)
osc.bind(oscpath, partial(self._osc_tuio_cb, oscpath))

def stop(self):
'''Stop the TUIO provider'''
osc.dontListen(self.oscid)
self.oscid.stop_all()

def update(self, dispatch_fn):
'''Update the TUIO provider (pop events from the queue)'''

# deque osc queue
osc.readQueue(self.oscid)

# read the Queue with event
while True:
try:
Expand All @@ -155,37 154,34 @@ def update(self, dispatch_fn):
return
self._update(dispatch_fn, value)

def _osc_tuio_cb(self, *incoming):
message = incoming[0]
oscpath, types, args = message[0], message[1], message[2:]
self.tuio_event_q.appendleft([oscpath, args, types])
def _osc_tuio_cb(self, oscpath, address, *args):
self.tuio_event_q.appendleft([oscpath, address, args])

def _update(self, dispatch_fn, value):
oscpath, args, types = value
command = args[0]
oscpath, command, args = value

# verify commands
if command not in ['alive', 'set']:
return

# move or create a new touch
if command == 'set':
id = args[1]
if command == b'set':
id = args[0]
if id not in self.touches[oscpath]:
# new touch
touch = TuioMotionEventProvider.__handlers__[oscpath](
self.device, id, args[2:])
self.device, id, args[1:])
self.touches[oscpath][id] = touch
dispatch_fn('begin', touch)
else:
# update a current touch
touch = self.touches[oscpath][id]
touch.move(args[2:])
touch.move(args[1:])
dispatch_fn('update', touch)

# alive event, check for deleted touch
if command == 'alive':
alives = args[1:]
if command == b'alive':
alives = args
to_delete = []
for id in self.touches[oscpath]:
if id not in alives:
Expand Down
Loading

0 comments on commit 667d866

Please sign in to comment.