All pastes #839590 Raw Edit

Someone

public text v1 · immutable
#839590 ·published 2007-12-31 02:46 UTC
rendered paste body
import re, sys
def emitnote(note, octave, inst, length):
	rows = 64 / length
	if note == '.':
		print "|^^^........"
	else:
		print "|%s%d%02d%s" % (note, octave, inst, "...D0F");
	for x in range(1,rows):
		print "|..........."
	
def play(playstr):
	global length, octave, tempo
	tokenre = re.compile(r'[><]|[abcdefg][-+]?|[otln]\d+')
	commands = tokenre.findall(playstr.lower())
	for c in commands:
		if c[0] == 'l':
			length = int(c[1:])
		elif c[0] == '>':
			octave += 1
		elif c[0] == '<':
			octave -= 1
		elif c[0] == 'o':
			octave = int(c[1:]) + 2
		elif c[0] == 't':
			tempo = int(c[1:])
		elif c == 'n0':
			emitnote('.', octave, 1, length)
		elif len(c) == 1:
			emitnote(c[0].upper() + '-', octave, 1, length)
		elif c[1] == '+':	
			emitnote(c[0].upper() + '#', octave, 1, length)		

musicre = re.compile(r'\s*PLAY\s*"([^"]+)"\s*\n')
print "ModPlug Tracker  IT"
for line in sys.stdin.readlines():
	m = musicre.match(line)
	if m:
		play(m.group(1))