Skip to content

Instantly share code, notes, and snippets.

@mathigatti
Last active August 18, 2020 22:12
Show Gist options
  • Select an option

  • Save mathigatti/7be84c00ea5b619cfb8ff7bc3a1efc60 to your computer and use it in GitHub Desktop.

Select an option

Save mathigatti/7be84c00ea5b619cfb8ff7bc3a1efc60 to your computer and use it in GitHub Desktop.
Script for playing FoxDot code from a text file
import sys
import time
import multiprocessing
import os
def supercollider():
SC_CMD = "rm -f /tmp/foxdot.sc; echo FoxDot.start >> /tmp/foxdot.sc; sclang /tmp/foxdot.sc"
proc = multiprocessing.Process(target=lambda : os.system(SC_CMD), args=())
proc.start()
return proc
def finish():
Server.kill()
sc_process.terminate()
# if you want to run supercollider inside this script
#sc_process = supercollider()
from FoxDot import *
code_file = sys.argv[1]
with open(code_file,'r') as f:
execute(f.read())
if len(sys.argv) > 2:
time.sleep(int(sys.argv[2])) # Seconds playing
#Clock.future(float(sys.argv[2]), lambda : finish())
# Usage example
# python code2sound.py FOXDOT_CODE_FILE PLAYING_DURATION_IN_SECONDS (Optional)
# python code2sound.py file_with_foxdot_code.py
# python code2sound.py file_with_foxdot_code.py 30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment