+ return self.pre_chord_ly ()
+
+class NotestyleEvent (Event): #class changed by DaLa: 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" % self.style
+ 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
+ else:
+ return ''
+ def ly_expression (self):
+ return self.pre_chord_ly ()
+
+class StemstyleEvent (Event): #class added by DaLa
+ 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])
+ else:
+ return ''
+ def pre_note_ly (self, is_chord_element):
+ return ''
+ def ly_expression (self):
+ return self.pre_chord_ly ()
+
+
+class ChordPitch:
+ def __init__ (self):
+ self.alteration = 0
+ self.step = 0
+ def __repr__(self):
+ return self.ly_expression()
+ def ly_expression (self):
+ return pitch_generating_function (self)
+
+class ChordModification:
+ def __init__ (self):
+ self.alteration = 0
+ self.step = 0
+ self.type = 0
+ def ly_expression (self):
+ if self.type:
+ val = {1: ".", -1: "^" }.get (self.type, "")
+ val += "%s" % self.step
+ val += {1: "+", -1: "-"}.get (self.alteration, "")
+ return val
+ else:
+ return ''
+
+class ChordNameEvent (Event):
+ def __init__ (self):
+ Event.__init__ (self)
+ self.root = None
+ self.kind = None
+ self.duration = None
+ self.modifications = []
+ self.bass = None
+ def add_modification (self, mod):
+ self.modifications.append (mod)
+ def ly_expression (self):
+
+ if not self.root:
+ return ''
+ value = self.root.ly_expression ()
+ if self.duration:
+ value += self.duration.ly_expression ()
+ if self.kind:
+ value = self.kind.format(value)
+ # First print all additions/changes, and only afterwards all subtractions
+ for m in self.modifications:
+ if m.type == 1:
+ value += m.ly_expression ()
+ for m in self.modifications:
+ if m.type == -1:
+ value += m.ly_expression ()
+ if self.bass:
+ value += "/+%s" % self.bass.ly_expression ()
+ return value
+
+
+class TremoloEvent(ArticulationEvent):
+ def __init__(self):
+ Event.__init__(self)
+ self.strokes = 0
+
+ def ly_expression(self):
+ ly_str = ''
+ if self.strokes and int(self.strokes) > 0:
+ # ly_dur is a global variable defined in class Duration
+ # ly_dur stores the value of the reciprocal values of notes
+ # ly_dur is used here to check the current note duration
+ # if the duration is smaller than 8, e.g.
+ # quarter, half and whole notes,
+ # `:(2 ** (2 + number of tremolo strokes))'
+ # should be appended to the pitch and duration, e.g.
+ # 1 stroke: `c4:8' or `c2:8' or `c1:8'
+ # 2 strokes: `c4:16' or `c2:16' or `c1:16'
+ # ...
+ # else (if ly_dur is equal to or greater than 8):
+ # we need to make sure that the tremolo value that is to
+ # be appended to the pitch and duration is twice the
+ # duration (if there is only one tremolo stroke.
+ # Each additional stroke doubles the tremolo value, e.g.:
+ # 1 stroke: `c8:16', `c16:32', `c32:64', ...
+ # 2 strokes: `c8:32', `c16:64', `c32:128', ...
+ # ...
+ if ly_dur < 8:
+ ly_str += ':%s' % (2 ** (2 + int(self.strokes)))
+ else:
+ ly_str += ':%s' % (2 ** int((math.log(ly_dur, 2)) + int(self.strokes)))
+ return ly_str