def lilypond(point): """ Generate lilypond representation for a point """ #If lilypond already computed, leave as is if "lilypond" in point: return point #Defaults: pitch_string = "" octave_string = "" duration_string = "" preamble = "" dynamic_string = "" if "pitch" in point: octave = point["octave"] pitch = point["pitch"] if octave > 4: octave_string = "'" * (octave - 4) elif octave < 4: octave_string = "," * (4 - octave) else: octave_string = "" m = modifiers(pitch) if m > 0: modifier_string = "is" * m elif m < 0: modifier_string = "es" * -m else: modifier_string = "" pitch_string = letter(pitch).lower() + modifier_string if DURATION_64 in point: duration = point[DURATION_64] if duration > 0: if duration % 3 == 0: # dotted note duration_string = str(192 // (2 * duration)) + "." else: duration_string = str(64 // duration) #TODO: for now, if we have a duration but no pitch, show a 'c' with an x note if duration_string: if not pitch_string: pitch_string = "c" octave_string = "'" preamble = r'\xNote ' if "dynamic" in point: dynamic = point["dynamic"] if dynamic == "crescendo": dynamic_string = "\<" elif dynamic == "diminuendo": dynamic_string = "\>" else: dynamic_string = "\%s" % (dynamic, ) point["lilypond"] = "%s%s%s%s%s" % (preamble, pitch_string, octave_string, duration_string, dynamic_string) return point
def lilypond(point): """ Generate lilypond representation for a point """ #If lilypond already computed, leave as is if "lilypond" in point: return point #Defaults: pitch_string = "" octave_string = "" duration_string = "" preamble = "" dynamic_string = "" if "pitch" in point: octave = point["octave"] pitch = point["pitch"] if octave > 4: octave_string = "'" * (octave - 4) elif octave < 4: octave_string = "," * (4 - octave) else: octave_string = "" m = modifiers(pitch) if m > 0: modifier_string = "is" * m elif m < 0: modifier_string = "es" * m else: modifier_string = "" pitch_string = letter(pitch).lower() + modifier_string if DURATION_64 in point: duration = point[DURATION_64] if duration > 0: if duration % 3 == 0: # dotted note duration_string = str(192 // (2 * duration)) + "." else: duration_string = str(64 // duration) #TODO: for now, if we have a duration but no pitch, show a 'c' with an x note if duration_string: if not pitch_string: pitch_string = "c" octave_string = "'" preamble = r'\xNote ' if "dynamic" in point: dynamic = point["dynamic"] if dynamic == "crescendo": dynamic_string = "\<" elif dynamic == "diminuendo": dynamic_string = "\>" else: dynamic_string = "\%s" % (dynamic,) point["lilypond"] = "%s%s%s%s%s" % (preamble, pitch_string, octave_string, duration_string, dynamic_string) return point
def _(point): octave = point["octave"] pitch = point["pitch"] duration = point[DURATION_64] if octave > 4: octave_string = "'" * (octave - 4) elif octave < 4: octave_string = "," * (4 - octave) else: octave_string = "" m = modifiers(pitch) if m > 0: modifier_string = "is" * m elif m < 0: modifier_string = "es" * m else: modifier_string = "" pitch_string = letter(pitch).lower() + modifier_string duration_string = str(64 / duration) # @@@ doesn't handle dotted notes yet point["lilypond"] = "%s%s%s" % (pitch_string, octave_string, duration_string) return point