arrange.py (1148B)
1 #!/usr/bin/python3 2 3 import sys 4 5 notes = open(sys.argv[1], "r") 6 bpm = sys.argv[2] 7 8 def transp(n): 9 if n[-1] == "4": 10 n = n[:-1] + "3" 11 if n[-1] == "5": 12 n = n[:-1] + "4" 13 if n[-1] == "6": 14 n = n[:-1] + "5" 15 if n[-1] == "7": 16 n = n[:-1] + "6" 17 return n 18 19 print ("""<?xml version="1.0"?> 20 <!DOCTYPE SINGING PUBLIC "-//SINGING//DTD SINGING mark up//EN" 21 "Singing.v0_1.dtd" 22 []>""") 23 print ('<SINGING BPM="%s">' % bpm) 24 25 while True: 26 note = notes.readline() 27 note = note.strip().split(" ") 28 try: 29 if note[1][0] == "S": 30 print ("<REST BEATS=\"%s\"></REST>" % note[0]) 31 continue 32 except Exception: 33 break 34 l = sys.stdin.readline() 35 if not l: 36 break 37 l = l.strip() 38 nh = len(l.split("-")) 39 l = "".join(l.split("-")) 40 n1 = [note[0]] 41 n2 = [transp(note[1])] 42 for i in range(nh-1): 43 note = notes.readline() 44 note = note.strip().split(" ") 45 n1.append(note[0]) 46 n2.append(transp(note[1])) 47 notes1 = ",".join(n1) 48 notes2 = ",".join(n2) 49 print ("<DURATION BEATS=\"%s\"><PITCH NOTE=\"%s\">" 50 "%s</PITCH></DURATION>" % (notes1, notes2, l)) 51 52 53 notes.close() 54 55 print ("</SINGING>")