forked from chaosct/repovizzOSC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
68 lines (52 loc) · 1.32 KB
/
server.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from gevent import monkey
monkey.patch_all(thread=False)
from time import sleep
from threading import Thread
import sys
# ===== Server part =====
import OSC
from flask import Flask
# we need to use this instead of flask.ext.socketio
# so PyInstall works
from flask_socketio import SocketIO
app = Flask(__name__)
socketio = SocketIO(app)
connectaddr = ('localhost', 6448)
def send(msg):
osc.sendto(msg, connectaddr)
@socketio.on('data', namespace='/osc')
def ws_play(message):
if message['data']:
msg = OSC.OSCMessage("/rapidmix")
msg += message['data']
try:
send(msg)
except OSC.OSCClientError:
pass
@socketio.on('bulk', namespace='/osc')
def ws_bulk(message):
if message['data']:
for row in message['data']:
msg = OSC.OSCMessage("/rapidmix")
msg += row
try:
send(msg)
sleep(0.001)
except OSC.OSCClientError:
pass
def addr_getter():
global connectaddr
while True:
connectaddr = q.get()
def server(queue):
global osc, q
if queue:
q = queue
t = Thread(target=addr_getter)
t.daemon = True
t.start()
osc = OSC.OSCClient()
try:
socketio.run(app, port=5000)
except KeyboardInterrupt:
pass