summaryrefslogtreecommitdiff
path: root/scripts/auxiliar/musicxml_generate_keys.py
blob: 7a16ac987f8bd42dc393f7c523d12f69d84c6c20 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python

notes = "CDEFGAB"
alterations = [-1, 0, 1]

def print_measure (nr, fifth, mode, atts1 = "", atts = "", final = ""):
    print """    <measure number="%s">
      <attributes>
%s        <key>
          <fifths>%s</fifths>
          <mode>%s</mode>
        </key>
%s      </attributes>
      <note>
        <pitch>
          <step>C</step>
          <octave>4</octave>
        </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>half</type>
      </note>
%s    </measure>""" % (nr, atts1, fifth, mode, atts, final)

first_div = """        <divisions>1</divisions>
"""
first_atts = """        <time symbol="common">
          <beats>2</beats>
          <beat-type>4</beat-type>
        </time>
        <clef>
          <sign>G</sign>
          <line>2</line>
        </clef>
"""

final_barline = """      <barline location="right">
        <bar-style>light-heavy</bar-style>
      </barline>
"""

print """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.0 Partwise//EN"
                                "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
  <movement-title>Different Key signatures</movement-title>
  <identification>
    <miscellaneous>
      <miscellaneous-field name="description">Various key signature: from 11
            flats to 11 sharps (each one first one measure in major, then one
            measure in minor)</miscellaneous-field>
    </miscellaneous>
  </identification>
  <part-list>
    <score-part id="P1">
      <part-name>MusicXML Part</part-name>
    </score-part>
  </part-list>
  <!--=========================================================-->
  <part id="P1">"""

max_range = 11
measure = 0
for fifth in range(-max_range, max_range+1):
    measure += 1
    if fifth == -max_range:
        print_measure (measure, fifth, "major", first_div, first_atts)
    else:
        print_measure (measure, fifth, "major")
    measure += 1
    if fifth == max_range:
        print_measure (measure, fifth, "minor", "", "", final_barline)
    else:
        print_measure (measure, fifth, "minor")
    

print """  </part>
</score-partwise>"""