I was about to suggest the same. The \revert is never inserted. But then, you don't want an \override anyway, because the setting should only apply to that one note, which has the color attribute, not to all following ones. So, you really want \once\override.
Ah, I had forgotten about the \once command. That's very useful.

To make sure things really work, you should create a regression test file input/regression/musicxml/59a-NoteColor.xml (see http://kainhofer.com/~lilypond/input/regression/musicxml/collated-files.html for the full regression test suite). That regression test should have: - -) a colored note (at the very beginning, so you see if it works right at the first note, too)
- -) a following differently colored note
- -) a following colored note with the same color
- -) a following rest (should probably not be colored)
- -) a colored note
- -) a non-colored note.
- -) A colored note with some articulation and e.g. a non-default notehead (which uses an \override, too, so you check whether the combination of multiple settings for one note doesn't break)
OK, I put one together and attached it to this email.

+    def print_note_color (self, object, rgb=None):
+        if rgb:
+            str = ("\override %s #'color = #(rgb-color %s %s %s)" %
+                   (object, rgb[0], rgb[1], rgb[2]))

I suppose this should be \\override (i.e. escape the backslash).
Well, it's been a while since I've worked with Python in depth, but it seems to work fine without it.

I'm not sure that you really want TWO newlines. Won't this insert a blank line between two color directives in the lilypond code? I'm not even sure that I want a newline before/after the override at all. This would result in each note of a piece taking ~4 lines in the lilypond file! At least with almost all other note-attached overrides that I implemented, I don't write out any newlines.
OK, I took those out and condensed the code a little. I've attached a new patch file.

Thanks for the comments!

-Bret.


<?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>Colored Notes</movement-title>
  <identification>
    <miscellaneous>
      <miscellaneous-field name="description">8 note elements: a blue
	quarter note (G4), 2 red eighth notes (A4, B4), an uncolored
	half rest, a green quarter note (C5), an uncolored quarter
	note (D5), a staccato cyan quarter note (E5), and a magenta
	'x' notehead quarter note (F5).
      </miscellaneous-field>
    </miscellaneous>
  </identification>
  <part-list>
    <score-part id="P1">
      <part-name>MusicXML Part</part-name>
    </score-part>
  </part-list>
  <!--=========================================================-->
  <part id="P1">
    <measure number="1">
      <attributes>
        <divisions>2</divisions>
        <key>
          <fifths>0</fifths>
          <mode>major</mode>
        </key>
        <time symbol="common">
          <beats>4</beats>
          <beat-type>4</beat-type>
        </time>
        <clef>
          <sign>G</sign>
          <line>2</line>
        </clef>
      </attributes>
      <note color="#0000FF">
        <pitch>
          <step>G</step>
          <octave>4</octave>
        </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>quarter</type>
      </note>
      <note color="#FF0000">
        <pitch>
          <step>A</step>
          <octave>4</octave>
        </pitch>
        <duration>1</duration>
        <voice>1</voice>
        <type>eighth</type>
	<beam number="1">begin</beam>
      </note>
      <note color="#FF0000">
        <pitch>
          <step>B</step>
          <octave>4</octave>
        </pitch>
        <duration>1</duration>
        <voice>1</voice>
        <type>eighth</type>
	<beam number="1">end</beam>
      </note>
      <note>
	<rest />
        <duration>4</duration>
        <voice>1</voice>
        <type>half</type>
      </note>
    </measure>
    <!--=======================================================-->
    <measure number="2">
      <note color="#00FF00">
        <pitch>
          <step>C</step>
          <octave>5</octave>
        </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>quarter</type>
      </note>
      <note>
        <pitch>
          <step>D</step>
          <octave>5</octave>
        </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>quarter</type>
      </note>
      <note color="#00FFFF">
        <pitch>
          <step>E</step>
          <octave>5</octave>
        </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>quarter</type>
	<notations>
	  <articulations>
	    <staccato placement="above"/>
	  </articulations>
	</notations>
      </note>
      <note color="#FF00FF">
        <pitch>
          <step>F</step>
          <octave>5</octave>
        </pitch>
        <duration>2</duration>
        <voice>1</voice>
        <type>quarter</type>
	<notehead>x</notehead>
      </note>
      <barline location="right">
        <bar-style>light-heavy</bar-style>
      </barline>
    </measure>
  </part>
  <!--=========================================================-->
</score-partwise>
>From 6a792c267db8b86d72504db2c17efa0266eb8a9b Mon Sep 17 00:00:00 2001
From: Bret Aarden <aar...@bret-aarden-2.local>
Date: Tue, 14 Jul 2009 22:50:14 -0400
Subject: [PATCH] Added code to handle the note color attribute.

---
 python/musicexp.py     |   10 +++++++++-
 scripts/musicxml2ly.py |    2 ++
 2 files changed, 11 insertions(+), 1 deletions(-)
 mode change 100644 => 100755 scripts/musicxml2ly.py

diff --git a/python/musicexp.py b/python/musicexp.py
index 9ebdb70..eee74a3 100644
--- a/python/musicexp.py
+++ b/python/musicexp.py
@@ -100,7 +100,12 @@ class Output_printer:
             return
         
         self.unformatted_output (str)
-                  
+
+    def print_note_color (self, object, rgb):
+        str = ("\once \override %s #'color = #(rgb-color %s %s %s)" %
+               (object, rgb[0], rgb[1], rgb[2]))
+        self.add_word(str)
+                        
     def add_word (self, str):
         if (len (str) + 1 + len (self._line) > self._line_len):
             self.newline()
@@ -1373,6 +1378,9 @@ class RestEvent (RhythmicEvent):
     def print_ly (self, printer):
         for ev in self.associated_events:
             ev.print_ly (printer)
+        if hasattr(self, 'color'):
+            for object in ("NoteHead", "Stem", "Beam"):
+                printer.print_note_color(object, self.color)
         if self.pitch:
             self.pitch.print_ly (printer)
             self.duration.print_ly (printer)
diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py
old mode 100644
new mode 100755
index ba7be37..1e31e8f
--- a/scripts/musicxml2ly.py
+++ b/scripts/musicxml2ly.py
@@ -1846,7 +1846,8 @@ def musicxml_note_to_lily_main_event (n):
 
     if event:
         event.duration = musicxml_duration_to_lily (n)
+        if hasattr(n, 'color'):
+            event.color = hex_to_color(n.color)
 
     noteheads = n.get_named_children ('notehead')
     for nh in noteheads:
-- 
1.6.1

_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to