[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lilypond-devel Digest, Vol 80, Issue 53

From: Bret Aarden
Subject: Re: lilypond-devel Digest, Vol 80, Issue 53
Date: Tue, 14 Jul 2009 22:54:07 -0400
User-agent: Thunderbird (Macintosh/20090605)

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 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!


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 1.0 Partwise//EN"
  <movement-title>Colored Notes</movement-title>
      <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).
    <score-part id="P1">
      <part-name>MusicXML Part</part-name>
  <part id="P1">
    <measure number="1">
        <time symbol="common">
      <note color="#0000FF">
      <note color="#FF0000">
        <beam number="1">begin</beam>
      <note color="#FF0000">
        <beam number="1">end</beam>
        <rest />
    <measure number="2">
      <note color="#00FF00">
      <note color="#00FFFF">
            <staccato placement="above"/>
      <note color="#FF00FF">
      <barline location="right">
>From 6a792c267db8b86d72504db2c17efa0266eb8a9b Mon Sep 17 00:00:00 2001
From: Bret Aarden <address@hidden>
Date: Tue, 14 Jul 2009 22:50:14 -0400
Subject: [PATCH] Added code to handle the note color attribute.

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

diff --git a/python/ b/python/
index 9ebdb70..eee74a3 100644
--- a/python/
+++ b/python/
@@ -100,7 +100,12 @@ class Output_printer:
         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):
@@ -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/ b/scripts/
old mode 100644
new mode 100755
index ba7be37..1e31e8f
--- a/scripts/
+++ b/scripts/
@@ -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:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]