Last active
August 18, 2020 22:11
-
-
Save mathigatti/323bbe0303e11879287964844ead4a99 to your computer and use it in GitHub Desktop.
Script for converting FoxDot code into wav audio file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sys | |
| import time | |
| import multiprocessing | |
| 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 * | |
| def record(recording_length): | |
| start = Clock.mod(recording_length) - 0.1 | |
| filename = f"{time.strftime('%Y%m%d_%H%M%S')}.wav" | |
| Clock.schedule(lambda : Server.record(filename), start) | |
| Clock.schedule(lambda : Server.stopRecording(),start + recording_length) | |
| code_file = sys.argv[1] | |
| recording_length = int(sys.argv[2]) # measured in beats | |
| with open(code_file,'r') as f: | |
| execute(f.read()) | |
| record(recording_length) | |
| time.sleep(60*recording_length/Clock.bpm+1) | |
| # Usage example | |
| # python code2wav.py FOXDOT_CODE_FILE RECORDING_LENGTH_IN_BEATS | |
| # python code2wav.py file_with_foxdot_code.py 32 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment