pandora_cdosea/render_all_gongs.py

52 lines
1.5 KiB
Python
Executable File

#!/usr/bin/python3
from argparse import ArgumentParser
from concurrent.futures import ThreadPoolExecutor
import json
import os
import string
import subprocess
import sys
def render_gongs(source):
gongs_wav = source.replace('.json', '.gongs.wav')
render_gongs = not os.path.exists(gongs_wav)
if not render_gongs:
render_gongs = os.path.getmtime(source) > os.path.getmtime(gongs_wav)
if render_gongs:
with open(source) as fd:
data = json.load(fd)
duration = sum(clip['duration'] for clip in data['clips'])
cmd = [
# offset in pi, duration, number of tracks, target
'./render_gongs.py',
str(data['gongs']['offset']),
str(duration),
str(data['gongs']['tracks']),
gongs_wav
]
print(cmd)
subprocess.call(cmd)
if __name__ == '__main__':
usage = "usage: %(prog)s [options] json"
parser = ArgumentParser(usage=usage)
parser.add_argument('-p', '--prefix', dest='prefix', help='version prefix', default='.')
parser.add_argument('files', metavar='path', type=str, nargs='*', help='json source file')
opts = parser.parse_args()
files = opts.files
if not files:
files = []
for n in range(10):
for letter in string.ascii_uppercase:
f = os.path.join(opts.prefix, 'output/%02d/%s.json' % (n, letter))
files.append(f)
with ThreadPoolExecutor(max_workers=4) as e:
for f in sorted(files):
e.submit(render_gongs, f)