default=1, help="speed ratio") parser.add_argument("-q", "--quiet", action="store_true", help="suppress log output") gp = parser.add_mutually_exclusive_group(required=True) gp.add_argument("--sampler", type=str, help="use a sampler", default=None) gp.add_argument("--basic", type=str, help="use a basic synthesizer", choices=['sin', 'square', 'sawtooth', 'triangle'], default=None) args = parser.parse_args() pitch = 2**(args.pitch / 12) if args.sampler == None: piano = BasicPiano(44100, mode=args.basic, pitch_ratio=pitch) else: x = readWav(args.sampler) piano = Sampler(x, pitch_ratio=pitch) piano = PianoCache(piano) t = loadTrack(args.track) seq = synthesize(piano, t, lenRatio=args.length, speedRatio=args.speed, volRatio=10**(args.volume / 10), quiet=args.quiet) seq.writeWav(args.output)
from argparse import ArgumentParser from pymad import writeMidi, loadTrack if __name__ == "__main__": parser = ArgumentParser('write midi', description="write track to midi") parser.add_argument('track', help='the source track file') parser.add_argument('midi', help='destination') args = parser.parse_args() mid = writeMidi(loadTrack(args.track)) mid.save(args.midi)
import json import sys from argparse import ArgumentParser from pymad import loadTrack if __name__ == "__main__": parser = ArgumentParser('combine-track', 'combine tracks') parser.add_argument('track', help='track path') parser.add_argument('-o', '--orchestra', action='append', nargs=2, metavar=('id', 'path'), help='add an orchestra') args = parser.parse_args() tracks = { int(o[0]): loadTrack(o[1]) for o in args.orchestra } track = loadTrack(args.track) notes = [] for n0 in track['notes']: if n0['note'] in tracks: for n in tracks[n0['note']]['notes']: notes.append({ 'note': n['note'], 'length': n['length'], 'offset': n0['offset'] + n['offset'] }) json.dump({ 'bpm': track['bpm'], 'bar': track['bar'], 'notes': notes }, sys.stdout)