Skip to content

Instantly share code, notes, and snippets.

@guyfawcus
Created May 29, 2017 17:30
Show Gist options
  • Select an option

  • Save guyfawcus/9d2c077d4b50052af0d638f0ac19f1d0 to your computer and use it in GitHub Desktop.

Select an option

Save guyfawcus/9d2c077d4b50052af0d638f0ac19f1d0 to your computer and use it in GitHub Desktop.
Two-way OSC communication with CasterSoundboard
#!/usr/bin/env python3
import threading
from sys import exit
from pythonosc import dispatcher
from pythonosc import osc_server
from pythonosc import udp_client
def global_information(addr, val):
addr = addr.split('/')
if addr[3] == 'audio_d_s':
print('Global: Duck state = {}'.format(bool(val)))
elif addr[3] == 'label':
if addr[4] == 'tab_name':
print('Global: Tab name = {}'.format(val))
def player_information(addr, val):
addr = addr.split('/')
key = addr[2]
if addr[4] == 'vol':
print('{}: Volume = {:.2f}%'.format(key, val*100))
elif addr[4] == 't_p_p':
print('{}: Track position = {:.2f}%'.format(key, val*100))
elif addr[4] == 'l_s':
print('{}: Set to loop = {}'.format(key, bool(val)))
elif addr[4] == 'label':
if addr[5] == 'tr_name':
print('{}: Track name = {}'.format(key, val))
elif addr[5] == 'time':
print('{}: Track position = {}'.format(key, val))
elif addr[5] == 'p_s':
print('{}: Play state = {}'.format(key, val))
dispatcher = dispatcher.Dispatcher()
dispatcher.map('/glo/*', global_information)
dispatcher.map('/cbp/*', player_information)
server = osc_server.ThreadingOSCUDPServer(('127.0.0.1', 9000), dispatcher)
server_thread = threading.Thread(target=server.serve_forever)
server_thread.daemon = True
server_thread.start()
client = udp_client.SimpleUDPClient('127.0.0.1', 5051)
while True:
command = input('Press a key to start/stop ("." to exit)...\n')
if command == '.':
exit()
else:
client.send_message('/cbp/{}/m/p_s/play_stop'.format(command), 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment