[Top][All Lists]

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

New Feature: musicxml2ly should consider colors of noteheads and stems

From: DaLa
Subject: New Feature: musicxml2ly should consider colors of noteheads and stems
Date: Sat, 20 Jul 2013 20:01:07 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

many thanks for all the software of the lilypond project.
Yesterday I colored some noteheads in a piece of music using the format
I learned: the format musicxml supports color attributes for noteheads and
Unfortunately the script musicxml2ly.py in lilypond version 2.16.2-1 seems
to ignore color attributes of noteheads and stems.

I therefore would like to recommend the following changes in the scripts
 * musicxml2ly.py
 * musicexp.py

I have made some simple tests - the changes seem to work. Maybe some
additional regression tests are necessary. (and: I'm not familiar with the
methods pre_note_ly of the Event classes - must they consider the color
attribute? I don't know.)

Thank You

 - - -

[musicxml2ly.py, line 1610]

def musicxml_notehead_to_lily (nh): #function changed: additionally process
color attribute
    styles = []

    # Notehead style
    style = notehead_styles_dict.get (nh.get_text ().strip (), None)
    style_elm = musicexp.NotestyleEvent ()
    if style:
        style_elm.style = style
    if hasattr (nh, 'filled'):
        style_elm.filled = (getattr (nh, 'filled') == "yes")
    if hasattr (nh, 'color'):
        style_elm.color = hex_to_color (getattr (nh, 'color'))
    if style_elm.style or (style_elm.filled != None) or (style_elm.color !=
        styles.append (style_elm)

    # parentheses
    if hasattr (nh, 'parentheses') and (nh.parentheses == "yes"):
        styles.append (musicexp.ParenthesizeEvent ())

    return styles

def musicxml_stem_to_lily (st): #function added: process stem color attribute
    styles = []

    # Stem style
    style_elm = musicexp.StemstyleEvent ()
    if hasattr (st, 'color'):
        style_elm.color = hex_to_color (getattr (st, 'color'))
    if (style_elm.color != None):
        styles.append (style_elm)

    return styles

[musicexp.py, line 1247]

class NotestyleEvent (Event): #class changed: additional attribute color
    def __init__ (self):
        Event.__init__ (self)
        self.style = None
        self.filled = None
        self.color = None
    def pre_chord_ly (self):
        return_string = '' 
        if self.style:
            return_string += " \\once \\override NoteHead #'style = #%s" %
        if self.color:
            return_string += " \\once \\override NoteHead #'color =
#(rgb-color %s %s %s)" % (self.color[0], self.color[1], self.color[2])
        return return_string
    def pre_note_ly (self, is_chord_element):
        if self.style and is_chord_element:
            return "\\tweak #'style #%s" % self.style
            return ''
    def ly_expression (self):
        return self.pre_chord_ly ()

class StemstyleEvent (Event): #class added
    def __init__ (self):
        Event.__init__ (self)
        self.color = None
    def pre_chord_ly (self):
        if self.color:
            return "\\once \\override Stem #'color = #(rgb-color %s %s %s)"
% (self.color[0], self.color[1], self.color[2])
            return ''
    def pre_note_ly (self, is_chord_element):
        return ''
    def ly_expression (self):
        return self.pre_chord_ly ()

reply via email to

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