Guide: How to Control CasterSoundboard with Python 3 - JupiterBroadcasting/CasterSoundboard GitHub Wiki
How to Control CasterSoundboard with Python 3
Steps to send a one-way message
- Install python-osc from the command-line (requires python3):
pip3 install python-osc
-
Open up CasterSoundboard
-
Create a new tab called
test
* -
Add a sound to the
1
key * -
Open the OSC settings dialog by pressing the button**
-
Click
Start
-
Close
the conformation window -
Open a Python 3 interpreter by invoking one from the command line:
python3
- Import
pythonosc
and initialise the client:
>>> from pythonosc import udp_client
>>> client = udp_client.SimpleUDPClient('127.0.0.1', 5051)
- Play the clip we added:
>>> client.send_message('/castersoundboard/board/test/player/1/modify/play_state/play', 1)
* You don't need to follow these steps exactly, you'll just have to adapt some of the later steps if you pick your own names/keys.
** It doesn't really matter when you do this step, as long as you do it before trying to talk OSC to CasterSoundboard!
Example script using two-way communication
This script is from a gist, the raw text can be downloaded here.
For this to work, you'll need to set the Outbound Traffic
client IP address to 127.0.0.1
in the OSC settings dialog in CasterSoundboard.
Save the script as a Python file like csb_osc_comms.py
then run it with python3 csb_osc_comms.py
.
When running, it will print any OSC message sent by CasterSoundoard as well as send a start/stop command to an associated player when you press a key on your keyboard. Send a .
to quit the program.
#!/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)
Further information
You should now be up and running! Check out the following pages for more information: