-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforwardMapper.py
47 lines (42 loc) · 1.39 KB
/
forwardMapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from pythonosc.dispatcher import Dispatcher
from pythonosc.osc_server import BlockingOSCUDPServer
import libmapper as mpr
import threading
IP = '192.168.0.192'
PORT = 8000
signalNames = []
def _create_osc_server():
dispatcher = Dispatcher()
dispatcher.map('/*', osc_handler)
return BlockingOSCUDPServer((IP, PORT), dispatcher)
def osc_handler(address, *args):
if address in signalNames:
# Set sig value
sig = find_sig(address)
if not sig:
return
else:
#print("value: " + list(args))
sig.set_value(list(args))
pass
else:
# Add signal to device
print("adding sig: forward" + str(address))
sigType = mpr.Type.FLOAT if isinstance(args[0], float) else mpr.Type.INT32
dev.add_signal(mpr.Direction.OUTGOING, address, len(args), sigType, "", -1000, 1000, None, None)
signalNames.append(address)
def find_sig(fullname):
fullname = fullname[1:]
if dev:
sig = dev.signals().filter(mpr.Property.NAME, fullname)
if not sig:
return None
return sig.next()
else:
return None
if __name__ == '__main__':
server = _create_osc_server()
threading.Thread(target=server.serve_forever, daemon=True).start()
dev = mpr.Device("forward")
while 1:
dev.poll(100)