lilypond-devel
[Top][All Lists]
Advanced

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

Adding note color handling to musicxml2ly


From: Bret Aarden
Subject: Adding note color handling to musicxml2ly
Date: Mon, 13 Jul 2009 19:41:34 -0400
User-agent: Thunderbird 2.0.0.22 (Macintosh/20090605)


I've written a music search tool that exports MusicXML and colors the
matching notes, and I'd like those colors to show up in LilyPond
typesetting.

There is no doubt a much more elegant way to do this, but the included
patch works for me, and it would be great to see this functionality
added to the musicxml2ly distribution.

-Bret.

>From d861198ea6a58696ce52cfe17f63dd8aeee6ed58 Mon Sep 17 00:00:00 2001
From: Bret Aarden <address@hidden>
Date: Mon, 13 Jul 2009 03:17:00 -0400
Subject: [PATCH] Added code to musicxml2ly.py and musicexp.ly to handle color
 overrides on notes.

---
 python/musicexp.py     |   22 ++++++++++++++++++++--
 scripts/musicxml2ly.py |    2 ++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/python/musicexp.py b/python/musicexp.py
index 9ebdb70..5f88818 100644
--- a/python/musicexp.py
+++ b/python/musicexp.py
@@ -100,7 +100,17 @@ class Output_printer:
             return
         
         self.unformatted_output (str)
-                  
+
+    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]))
+        else:
+            str = "\\revert %s #'color" % object
+        self.newline()
+        self.add_word(str)
+        self.newline()
+
     def add_word (self, str):
         if (len (str) + 1 + len (self._line) > self._line_len):
             self.newline()
@@ -1436,6 +1446,10 @@ class NoteEvent(RhythmicEvent):
     def print_ly (self, printer):
         for ev in self.associated_events:
             ev.print_ly (printer)
+        if hasattr(self, 'color'):
+            printer.print_note_color("NoteHead", self.color)
+            printer.print_note_color("Stem", self.color)
+            printer.print_note_color("Beam", self.color)
         if self.pitch:
             self.pitch.print_ly (printer)
             printer (self.pitch_mods ())
@@ -1443,7 +1457,11 @@ class NoteEvent(RhythmicEvent):
             printer (self.drum_type)
 
         self.duration.print_ly (printer)
-
+        if hasattr(self, 'color'):
+            printer.print_note_color("NoteHead")
+            printer.print_note_color("Stem")
+            printer.print_note_color("Beam")
+                                                
 class KeySignatureChange (Music):
     def __init__ (self):
         Music.__init__ (self)
diff --git a/scripts/musicxml2ly.py b/scripts/musicxml2ly.py
index ba7be37..1e31e8f 100644
--- a/scripts/musicxml2ly.py
+++ b/scripts/musicxml2ly.py
@@ -1846,6 +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



reply via email to

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