-
Notifications
You must be signed in to change notification settings - Fork 0
/
osc_server.py
34 lines (25 loc) · 1.05 KB
/
osc_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
import threading
import config
from pythonosc.dispatcher import Dispatcher
from pythonosc.osc_server import BlockingOSCUDPServer
from main import TextSwitcherGUI
class OSCServer(threading.Thread):
def __init__(self, text_switcher_gui: TextSwitcherGUI):
super().__init__()
self.text_switcher_gui = text_switcher_gui
self.dispatcher = Dispatcher()
self.dispatcher.map("/obstext/next", self.next_text)
self.dispatcher.map("/obstext/previous", self.previous_text)
self.dispatcher.map("/obstext/hide", self.hide_text)
self.server = BlockingOSCUDPServer((config.OSC_LISTEN_HOST, config.OSC_LISTEN_PORT), self.dispatcher)
self.start()
def run(self):
self.server.serve_forever()
def shutdown(self):
self.server.shutdown()
def next_text(self, address, *args):
self.text_switcher_gui.next_line()
def previous_text(self, address, *args):
self.text_switcher_gui.prev_line()
def hide_text(self, address, *args):
self.text_switcher_gui.hide_text()