]> git.donarmstrong.com Git - lilypond.git/blob - scripts/auxiliar/musicxml_generate_timesignatures.py
Add '-dcrop' option to ps and svg backends
[lilypond.git] / scripts / auxiliar / musicxml_generate_timesignatures.py
1 #!/usr/bin/env python
2
3 notes = "CDEFGAB"
4 alterations = [-1, 0, 1]
5
6 dot_xml = """        <dot/>
7 """
8 tie_xml = """        <tie type="%s"/>
9 """
10 tie_notation_xml = """        <notations><tied type="%s"/></notations>
11 """
12
13
14 def generate_note (duration, end_tie = False):
15     if duration < 2:
16       (notetype, dur) = ("8th", 1)
17     elif duration < 4:
18       (notetype, dur) = ("quarter", 2)
19     elif duration < 8:
20       (notetype, dur) = ("half", 4)
21     else:
22       (notetype, dur) = ("whole", 8)
23     dur_processed = dur
24     dot = ""
25     if (duration - dur_processed >= dur/2):
26       dot = dot_xml
27       dur_processed += dur/2
28       if (duration - dur_processed >= max(dur/4, 1)):
29         dot += dot_xml
30         dur_processed += dur/4
31     tie = ""
32     tie_notation = ""
33     if end_tie:
34         tie += tie_xml % "stop"
35         tie_notation += tie_notation_xml % "stop"
36     second_note = None
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"
41     note = """      <note>
42         <pitch>
43           <step>C</step>
44           <octave>5</octave>
45         </pitch>
46         <duration>%s</duration>
47 %s        <voice>1</voice>
48         <type>%s</type>
49 %s%s      </note>""" % (dur_processed, tie, notetype, dot, tie_notation)
50     if second_note:
51         return "%s\n%s" % (note, second_note)
52     else:
53         return note
54
55 def print_measure (nr, beats, type, params = "", attr = "", attr2 = "", barline = ""):
56     duration = 8*beats/type
57     note = generate_note (duration)
58
59     print """    <measure number="%s">
60       <attributes>
61 %s        <time%s>
62           <beats>%s</beats>
63           <beat-type>%s</beat-type>
64         </time>
65 %s      </attributes>
66 %s
67 %s    </measure>""" % (nr, attr, params, beats, type, attr2, note, barline)
68
69 first_key = """        <divisions>2</divisions>
70         <key>
71           <fifths>0</fifths>
72           <mode>major</mode>
73         </key>
74 """
75 first_clef = """        <clef>
76           <sign>G</sign>
77           <line>2</line>
78         </clef>
79 """
80
81 final_barline = """      <barline location="right">
82         <bar-style>light-heavy</bar-style>
83       </barline>
84 """
85
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">
89 <score-partwise>
90   <identification>
91     <miscellaneous>
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>
95     </miscellaneous>
96   </identification>
97   <part-list>
98     <score-part id="P1">
99       <part-name>MusicXML Part</part-name>
100     </score-part>
101   </part-list>
102   <!--=========================================================-->
103   <part id="P1">"""
104
105 measure = 1
106
107 print_measure (measure, 2, 2, " symbol=\"common\"", first_key, first_clef)
108 measure += 1
109
110 print_measure (measure, 4, 4, " symbol=\"common\"")
111 measure += 1
112
113 print_measure (measure, 2, 2)
114 measure += 1
115
116 print_measure (measure, 3, 2)
117 measure += 1
118
119 print_measure (measure, 2, 4)
120 measure += 1
121
122 print_measure (measure, 3, 4)
123 measure += 1
124
125 print_measure (measure, 4, 4)
126 measure += 1
127
128 print_measure (measure, 5, 4)
129 measure += 1
130
131 print_measure (measure, 3, 8)
132 measure += 1
133
134 print_measure (measure, 6, 8)
135 measure += 1
136
137 print_measure (measure, 12, 8, "", "", "", final_barline)
138 measure += 1
139
140 print """  </part>
141 </score-partwise>"""