4 alterations = [-1, 0, 1]
8 tie_xml = """ <tie type="%s"/>
10 tie_notation_xml = """ <notations><tied type="%s"/></notations>
14 def generate_note (duration, end_tie = False):
16 (notetype, dur) = ("8th", 1)
18 (notetype, dur) = ("quarter", 2)
20 (notetype, dur) = ("half", 4)
22 (notetype, dur) = ("whole", 8)
25 if (duration - dur_processed >= dur/2):
27 dur_processed += dur/2
28 if (duration - dur_processed >= max(dur/4, 1)):
30 dur_processed += dur/4
34 tie += tie_xml % "stop"
35 tie_notation += tie_notation_xml % "stop"
37 if duration - dur_processed > 0:
38 second_note = generate_note (duration-dur_processed, True)
39 tie += tie_xml % "start"
40 tie_notation += tie_notation_xml % "start"
46 <duration>%s</duration>
49 %s%s </note>""" % (dur_processed, tie, notetype, dot, tie_notation)
51 return "%s\n%s" % (note, second_note)
55 def print_measure (nr, beats, type, params = "", attr = "", attr2 = "", barline = ""):
56 duration = 8*beats/type
57 note = generate_note (duration)
59 print """ <measure number="%s">
63 <beat-type>%s</beat-type>
67 %s </measure>""" % (nr, attr, params, beats, type, attr2, note, barline)
69 first_key = """ <divisions>2</divisions>
75 first_clef = """ <clef>
81 final_barline = """ <barline location="right">
82 <bar-style>light-heavy</bar-style>
86 print """<?xml version="1.0" encoding="UTF-8"?>
87 <!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.0 Partwise//EN"
88 "http://www.musicxml.org/dtds/partwise.dtd">
92 <miscellaneous-field name="description">Various time signatures: 2/2
93 (alla breve), 4/4 (C), 2/2, 3/2, 2/4, 3/4, 4/4, 5/4, 3/8, 6/8,
94 12/8</miscellaneous-field>
99 <part-name>MusicXML Part</part-name>
102 <!--=========================================================-->
107 print_measure (measure, 2, 2, " symbol=\"common\"", first_key, first_clef)
110 print_measure (measure, 4, 4, " symbol=\"common\"")
113 print_measure (measure, 2, 2)
116 print_measure (measure, 3, 2)
119 print_measure (measure, 2, 4)
122 print_measure (measure, 3, 4)
125 print_measure (measure, 4, 4)
128 print_measure (measure, 5, 4)
131 print_measure (measure, 3, 8)
134 print_measure (measure, 6, 8)
137 print_measure (measure, 12, 8, "", "", "", final_barline)