#!/usr/local/bin/python2.4 # Copyright 2007 George Gonzalez import sys, string, commands fileName = "" try: fileName = sys.argv[1] except: print "usage: dm " sys.exit(1) levels = [100, 10, 20, 30, 40, 50, 60, 70, 80, 90] patterns = {} patlen = {} tpb = 4 bpm = 80 dmap = {"kick":1, "snare":2, "chh":3, "ohh":4, "crash":5, "hitom":6, "floor":7, "bell":8, "ride":9, "stick":10} file = open(fileName, 'r') line = file.readline() while line: if line[0:3]=="end": break elif line[0]=='p': patln = 0 patname = line[:-1] pat = {} line2 = file.readline()[:-1] while line2: if line2[0]==";": line2 = file.readline()[:-1] continue (instr, ticks) = line2.split() ticks = ticks.replace("|","") if patln == 0: patln=len(ticks) else: if len(ticks)!=patln: print "ERROR: uneven line lengths" sys.exit(1) pat[dmap[instr]] = ticks line2 = file.readline()[:-1] patterns[patname] = pat patlen[patname] = patln line = file.readline() plist = "" line = file.readline() while line: if line[0]!='#': plist+=line line = file.readline() song = string.split(plist) out = open("song.sco", 'w') for key in dmap.keys(): print >> out, "f", dmap[key], "0 0 1 \"samples/"+key+".wav\" 0 0 0" print >> out base = 0 newbase = 0 for pat in song: if pat[0]=='b': bpm=eval(pat[1:]) elif pat[0]=='t': tpb=eval(pat[1:]) else: inc = 60.0/(tpb*float(bpm)) for (i,notes) in patterns[pat].items(): t=0 for n in range(len(notes)): if not notes[n].isdigit(): t+=inc continue dur = 2 if notes[(n+1) % patlen[pat]]=='.': count=1 while notes[(n+count) % patlen[pat]]=='.': count+=1 dur = inc*count print >> out, "i 1", base+t, dur, i, levels[eval(notes[n])] t+=inc newbase = base + inc*patlen[pat] base = newbase print >> out, "e" out.close() (stat, outp) = commands.getstatusoutput("csound -d -o devaudio foo.orc song.sco") if stat: print outp