50 lines
No EOL
1.3 KiB
Python
50 lines
No EOL
1.3 KiB
Python
import argparse
|
|
import os
|
|
|
|
from pysonnum.compiler import *
|
|
|
|
# USAGE
|
|
# python snm.py path_to.snm output.wav
|
|
|
|
parser = argparse.ArgumentParser(description="Sonnum - the additive synthesizer.")
|
|
|
|
parser.add_argument('input_snm_fn', metavar="INPUT", nargs='?', type=str, help="Input *.snm source file", default='')
|
|
|
|
parser.add_argument('-t', '--transpile', help="View the transpiled python code", action='store_true')
|
|
parser.add_argument('-b', '--bytecode', help="View the resulting bytecode", action='store_true')
|
|
|
|
parser.add_argument('-o', '--output', metavar='FN', help="Synthesize to given wav filenames", type=str)
|
|
|
|
|
|
def run():
|
|
|
|
args = parser.parse_args()
|
|
|
|
C = SonnumCompiler()
|
|
fn = args.input_snm_fn
|
|
|
|
with open(fn, 'r', encoding = 'utf-8') as fl:
|
|
snm = fl.read()
|
|
|
|
if args.transpile:
|
|
py_snm = C.transpile_snm_to_py(snm)
|
|
print('TRANSPILED CODE')
|
|
print(py_snm)
|
|
|
|
elif args.bytecode:
|
|
py_snm = C.transpile_snm_to_py(snm)
|
|
C.run_transpiled_code(py_snm)
|
|
C.sort_activities()
|
|
C.list_activities()
|
|
|
|
elif args.output:
|
|
C.compile_to_smnb(snm, 'source.snmb')
|
|
os.system(f'./zigsonnum/sonnum > {args.output}')
|
|
|
|
else:
|
|
C.compile_to_smnb(snm, 'source.snmb')
|
|
os.system(f'zig run zigsonnum/sonnum.zig -lc -OReleaseFast > {fn}.wav')
|
|
#os.system(f'zig run zigsonnum/sonnum.zig -lc > {fn}.wav')
|
|
|
|
if __name__ == '__main__':
|
|
run() |