]> git.donarmstrong.com Git - lilypond.git/commitdiff
MusicXML: Convert fretboards from MusicXML to Lilypond
authorReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 26 Oct 2007 14:38:08 +0000 (16:38 +0200)
committerReinhold Kainhofer <reinhold@kainhofer.com>
Fri, 26 Oct 2007 14:38:08 +0000 (16:38 +0200)
In MusicXML, fretboards are inside <harmony> elements, assigned
to a particular staff, while in lilypond the \fret-diagram is a
text markup assigned to a particular note. So we run into the same
problems as we do with dynamics (i.e. we need to find a proper
note to assign the element to, which is not very robust). For
single-voice harmony, this works quite well so far.

input/regression/musicxml/17b-Fretboards-Finale.xml [new file with mode: 0644]
input/regression/musicxml/17c-ChordsFrets-Finale.xml [new file with mode: 0644]
python/musicexp.py
python/musicxml.py
scripts/musicxml2ly.py

diff --git a/input/regression/musicxml/17b-Fretboards-Finale.xml b/input/regression/musicxml/17b-Fretboards-Finale.xml
new file mode 100644 (file)
index 0000000..bfd24c5
--- /dev/null
@@ -0,0 +1,229 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.0 Partwise//EN"\r
+                                "http://www.musicxml.org/dtds/partwise.dtd">\r
+<score-partwise>\r
+  <movement-title>Fretboards</movement-title>\r
+  <identification>\r
+    <encoding>\r
+      <software>Finale 2007 for Windows</software>\r
+      <software>Dolet Light for Finale 2007</software>\r
+      <encoding-date>2007-10-25</encoding-date>\r
+    </encoding>\r
+  </identification>\r
+  <part-list>\r
+    <score-part id="P1">\r
+      <part-name>MusicXML Part</part-name>\r
+      <score-instrument id="P1-I1">\r
+        <instrument-name>Acoustic Grand Piano</instrument-name>\r
+      </score-instrument>\r
+      <midi-instrument id="P1-I1">\r
+        <midi-channel>1</midi-channel>\r
+        <midi-program>1</midi-program>\r
+      </midi-instrument>\r
+    </score-part>\r
+  </part-list>\r
+  <!--=========================================================-->\r
+  <part id="P1">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>0</fifths>\r
+          <mode>major</mode>\r
+        </key>\r
+        <time symbol="common">\r
+          <beats>4</beats>\r
+          <beat-type>4</beat-type>\r
+        </time>\r
+        <clef>\r
+          <sign>G</sign>\r
+          <line>2</line>\r
+        </clef>\r
+      </attributes>\r
+      <sound tempo="120"/>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>D</root-step>\r
+        </root>\r
+        <kind>major</kind>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>C</root-step>\r
+        </root>\r
+        <kind>dominant</kind>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>1</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>C</root-step>\r
+        </root>\r
+        <kind>minor-seventh</kind>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <first-fret>3</first-fret>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>5</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>4</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>C</root-step>\r
+        </root>\r
+        <kind>dominant</kind>\r
+        <degree>\r
+          <degree-value>13</degree-value>\r
+          <degree-alter>-1</degree-alter>\r
+          <degree-type>add</degree-type>\r
+        </degree>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <first-fret>8</first-fret>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>8</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>8</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>9</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>9</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <barline location="right">\r
+        <bar-style>light-heavy</bar-style>\r
+      </barline>\r
+    </measure>\r
+  </part>\r
+  <!--=========================================================-->\r
+</score-partwise>\r
diff --git a/input/regression/musicxml/17c-ChordsFrets-Finale.xml b/input/regression/musicxml/17c-ChordsFrets-Finale.xml
new file mode 100644 (file)
index 0000000..06eca4a
--- /dev/null
@@ -0,0 +1,430 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.0 Partwise//EN"\r
+                                "http://www.musicxml.org/dtds/partwise.dtd">\r
+<score-partwise>\r
+  <movement-title>Chords and fretboards example</movement-title>\r
+  <identification>\r
+    <encoding>\r
+      <software>Finale 2007 for Windows</software>\r
+      <software>Dolet Light for Finale 2007</software>\r
+      <encoding-date>2007-10-25</encoding-date>\r
+    </encoding>\r
+  </identification>\r
+  <part-list>\r
+    <score-part id="P1">\r
+      <part-name>MusicXML Part</part-name>\r
+      <score-instrument id="P1-I1">\r
+        <instrument-name>Acoustic Grand Piano</instrument-name>\r
+      </score-instrument>\r
+      <midi-instrument id="P1-I1">\r
+        <midi-channel>1</midi-channel>\r
+        <midi-program>1</midi-program>\r
+      </midi-instrument>\r
+    </score-part>\r
+  </part-list>\r
+  <!--=========================================================-->\r
+  <part id="P1">\r
+    <measure number="1">\r
+      <attributes>\r
+        <divisions>1</divisions>\r
+        <key>\r
+          <fifths>0</fifths>\r
+          <mode>major</mode>\r
+        </key>\r
+        <time symbol="common">\r
+          <beats>4</beats>\r
+          <beat-type>4</beat-type>\r
+        </time>\r
+        <clef>\r
+          <sign>G</sign>\r
+          <line>2</line>\r
+        </clef>\r
+      </attributes>\r
+      <sound tempo="120"/>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>C</root-step>\r
+        </root>\r
+        <kind>major</kind>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>1</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>C</root-step>\r
+        </root>\r
+        <kind>major-seventh</kind>\r
+        <degree>\r
+          <degree-value>11</degree-value>\r
+          <degree-alter>1</degree-alter>\r
+          <degree-type>add</degree-type>\r
+        </degree>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <first-fret>2</first-fret>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>5</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>4</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>5</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>B</root-step>\r
+        </root>\r
+        <kind>dominant</kind>\r
+        <degree>\r
+          <degree-value>5</degree-value>\r
+          <degree-alter>1</degree-alter>\r
+          <degree-type>alter</degree-type>\r
+        </degree>\r
+        <degree>\r
+          <degree-value>9</degree-value>\r
+          <degree-alter>1</degree-alter>\r
+          <degree-type>add</degree-type>\r
+        </degree>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>1</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>E</root-step>\r
+          <root-alter>-1</root-alter>\r
+        </root>\r
+        <kind>major</kind>\r
+        <degree>\r
+          <degree-value>2</degree-value>\r
+          <degree-alter>0</degree-alter>\r
+          <degree-type>add</degree-type>\r
+        </degree>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>5</frame-frets>\r
+          <first-fret>11</first-fret>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>11</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>13</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>15</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>12</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>11</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>11</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+    </measure>\r
+    <!--=======================================================-->\r
+    <measure number="2">\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>G</root-step>\r
+        </root>\r
+        <kind>minor</kind>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <first-fret>3</first-fret>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>5</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>5</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>D</root-step>\r
+          <root-alter>1</root-alter>\r
+        </root>\r
+        <kind>major-seventh</kind>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>1</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>A</root-step>\r
+        </root>\r
+        <kind>diminished-seventh</kind>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>1</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>1</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <harmony default-y="100">\r
+        <root>\r
+          <root-step>A</root-step>\r
+        </root>\r
+        <kind>augmented</kind>\r
+        <frame>\r
+          <frame-strings>6</frame-strings>\r
+          <frame-frets>4</frame-frets>\r
+          <frame-note>\r
+            <string>6</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>5</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>4</string>\r
+            <fret>3</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>3</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>2</string>\r
+            <fret>2</fret>\r
+          </frame-note>\r
+          <frame-note>\r
+            <string>1</string>\r
+            <fret>0</fret>\r
+          </frame-note>\r
+        </frame>\r
+      </harmony>\r
+      <note>\r
+        <pitch>\r
+          <step>A</step>\r
+          <octave>4</octave>\r
+        </pitch>\r
+        <duration>1</duration>\r
+        <voice>1</voice>\r
+        <type>quarter</type>\r
+        <stem>up</stem>\r
+      </note>\r
+      <barline location="right">\r
+        <bar-style>light-heavy</bar-style>\r
+      </barline>\r
+    </measure>\r
+  </part>\r
+  <!--=========================================================-->\r
+</score-partwise>\r
index c4ef903a32e0a863616203ee89614da4f23854c8..ef896f9e53752ec80ab325e8966225865dc6ae23 100644 (file)
@@ -761,6 +761,8 @@ class ArticulationEvent (Event):
     def __init__ (self):
         self.type = None
         self.force_direction = None
+    def wait_for_note (self):
+        return True;
 
     def direction_mod (self):
         return { 1: '^', -1: '_', 0: '-' }.get (self.force_direction, '')
@@ -786,6 +788,39 @@ class MarkupEvent (ShortArticulationEvent):
     def ly_expression (self):
         if self.contents:
             return "%s\\markup { %s }" % (self.direction_mod (), self.contents)
+        else:
+            return ''
+
+class FretEvent (MarkupEvent):
+    def __init__ (self):
+        MarkupEvent.__init__ (self)
+        self.force_direction = 1
+        self.strings = 6
+        self.frets = 4
+        self.barre = None
+        self.elements = []
+    def ly_expression (self):
+        val = ""
+        if self.strings <> 6:
+            val += "w:%s;" % self.strings
+        if self.frets <> 4:
+            val += "h:%s;" % self.frets
+        if self.barre and len (self.barre) >= 3:
+            val += "c:%s-%s-%s;" % (self.barre[0], self.barre[1], self.barre[2])
+        have_fingering = False
+        for i in self.elements:
+            if len (i) > 1:
+                val += "%s-%s" % (i[0], i[1])
+            if len (i) > 2:
+                have_fingering = True
+                val += "-%s" % i[2]
+            val += ";"
+        if have_fingering:
+            val = "f:1;" + val
+        if val:
+            return "%s\\markup { \\fret-diagram #\"%s\" }" % (self.direction_mod (), val)
+        else:
+            return ''
 
 class TremoloEvent (ArticulationEvent):
     def __init__ (self):
index 86eca63bf7b267985a5db85089a2c7f7253de8c2..3c38f30828ea09d669a9241deb81e2971c300782 100644 (file)
@@ -89,6 +89,14 @@ class Xml_node:
 
        return cn[0]
 
+    def get_named_child_value_number (self, name, default):
+        n = self.get_maybe_exist_named_child (name)
+        if n:
+            return string.atoi (n.get_text())
+        else:
+            return default
+
+
 class Music_xml_node (Xml_node):
     def __init__ (self):
        Xml_node.__init__ (self)
@@ -610,7 +618,7 @@ class Part (Music_xml_node):
 
            if not (voice_id or isinstance (n, Attributes) or
                     isinstance (n, Direction) or isinstance (n, Partial) or
-                    isinstance (n, Barline) ):
+                    isinstance (n, Barline) or isinstance (n, Harmony) ):
                continue
 
            if isinstance (n, Attributes) and not start_attr:
@@ -630,7 +638,7 @@ class Part (Music_xml_node):
                     voices[v].add_element (n)
                 continue
 
-            if isinstance (n, Direction):
+            if isinstance (n, Direction) or isinstance (n, Harmony):
                 staff_id = n.get_maybe_exist_named_child (u'staff')
                 if staff_id:
                     staff_id = staff_id.get_text ()
@@ -638,8 +646,11 @@ class Part (Music_xml_node):
                     dir_voices = staff_to_voice_dict.get (staff_id, voices.keys ())
                 else:
                     dir_voices = voices.keys ()
-                for v in dir_voices:
-                    voices[v].add_element (n)
+                # assign only to first voice, otherwise we'll have duplicates!
+                if dir_voices:
+                    voices[dir_voices[0]].add_element (n)
+                #for v in dir_voices:
+                    #voices[v].add_element (n)
                 continue
 
            id = voice_id.get_text ()
@@ -783,6 +794,30 @@ class Bend (Music_xml_node):
 class Words (Music_xml_node):
     pass
 
+class Harmony (Music_xml_node):
+    pass
+
+class Frame (Music_xml_node):
+    def get_frets (self):
+        return self.get_named_child_value_number ('frame-frets', 4)
+    def get_strings (self):
+        return self.get_named_child_value_number ('frame-strings', 6)
+    def get_first_fret (self):
+        return self.get_named_child_value_number ('first-fret', 1)
+class Frame_Note (Music_xml_node):
+    def get_string (self):
+        return self.get_named_child_value_number ('string', 1)
+    def get_fret (self):
+        return self.get_named_child_value_number ('fret', 0)
+    def get_fingering (self):
+        return self.get_named_child_value_number ('fingering', -1)
+    def get_barre (self):
+        n = self.get_maybe_exist_named_child ('barre')
+        if n:
+            return getattr (n, 'type', '')
+        else:
+            return ''
+
 
 ## need this, not all classes are instantiated
 ## for every input file. Only add those classes, that are either directly
@@ -801,8 +836,11 @@ class_dict = {
        'direction': Direction,
         'direction-type': DirType,
        'duration': Duration,
+        'frame': Frame,
+        'frame-note': Frame_Note,
         'glissando': Glissando,
        'grace': Grace,
+        'harmony': Harmony,
         'identification': Identification,
         'lyric': Lyric,
        'measure': Measure,
index 4441f5be682ef9fc24340ea9ced05f945293f0b5..7238230cb74c8915158a166f5d23ed0d62cb091f 100644 (file)
@@ -737,6 +737,40 @@ def musicxml_direction_to_lily (n):
 
     return res
 
+def musicxml_frame_to_lily_event (frame):
+    ev = musicexp.FretEvent ()
+    ev.strings = frame.get_strings ()
+    ev.frets = frame.get_frets ()
+    #offset = frame.get_first_fret () - 1
+    barre = []
+    for fn in frame.get_named_children ('frame-note'):
+        fret = fn.get_fret ()
+        if fret <= 0:
+            fret = "o"
+        el = [ fn.get_string (), fret ]
+        fingering = fn.get_fingering ()
+        if fingering >= 0:
+            el.append (fingering)
+        ev.elements.append (el)
+        b = fn.get_barre ()
+        if b == 'start':
+            barre[0] = el[0] # start string
+            barre[2] = el[1] # fret
+        elif b == 'stop':
+            barre[1] = el[0] # end string
+    if barre:
+        ev.barre = barre
+    return ev
+
+def musicxml_harmony_to_lily (n):
+    res = []
+    for f in n.get_named_children ('frame'):
+        ev = musicxml_frame_to_lily_event (f)
+        if ev:
+            res.append (ev)
+
+    return res
+
 instrument_drumtype_dict = {
     'Acoustic Snare Drum': 'acousticsnare',
     'Side Stick': 'sidestick',
@@ -938,7 +972,15 @@ def musicxml_voice_to_lily_voice (voice):
                 else:
                     voice_builder.add_command (a)
             continue
-        
+
+        if isinstance (n, musicxml.Harmony):
+            for a in musicxml_harmony_to_lily (n):
+                if a.wait_for_note ():
+                    voice_builder.add_dynamics (a)
+                else:
+                    voice_builder.add_command (a)
+            continue
+
         is_chord = n.get_maybe_exist_named_child ('chord')
         if not is_chord:
             try: