Example #1
0
 def test_modifiers(self):
     from sebastian.core.notes import modifiers
     assert modifiers(0) == 0
     assert modifiers(2) == 0
     assert modifiers(-1) == 0
     assert modifiers(-5) == -1
     assert modifiers(-11) == -2
     assert modifiers(-17) == -2
     assert modifiers(4) == 1
     assert modifiers(13) == 2
     assert modifiers(17) == 2
Example #2
0
 def test_modifiers(self):
     from sebastian.core.notes import modifiers
     assert modifiers(0) == 0
     assert modifiers(2) == 0
     assert modifiers(-1) == 0
     assert modifiers(-5) == -1
     assert modifiers(-11) == -2
     assert modifiers(-17) == -2
     assert modifiers(4) == 1
     assert modifiers(13) == 2
     assert modifiers(17) == 2
Example #3
0
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
Example #4
0
def midi_pitch(point):
    octave = point["octave"]
    pitch = point["pitch"]
    midi_pitch = [2, 9, 4, 11, 5, 0, 7][pitch % 7]
    midi_pitch += modifiers(pitch)
    midi_pitch += 12 * octave
    point[MIDI_PITCH] = midi_pitch
    return point
Example #5
0
def midi_pitch(point):
    octave = point["octave"]
    pitch = point["pitch"]
    midi_pitch = [2, 9, 4, 11, 5, 0, 7][pitch % 7]
    midi_pitch += modifiers(pitch)
    midi_pitch += 12 * octave
    point[MIDI_PITCH] = midi_pitch
    return point
Example #6
0
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
Example #7
0
 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