Beispiel #1
0
def generalNote_to_string(gn):
    """
    Return the NoteString with R or N, notehead number and dots.
    Does not consider the ties (because of music21 ties encoding).
    Arguments:
        gn {music21 general note} -- [description]
    Returns:
        String -- the noteString
    """
    out_string = ""
    #add generalNote type (Rest or Note)
    if gn.isRest:
        out_string += "R"
    else:
        out_string += "N"
    #add notehead information (4,2,1,1/2, etc...). 4 means a black note, 2 white, 1 whole etc...
    type_number = Fraction(duration.convertTypeToNumber(gn.duration.type))
    if type_number >= 4:
        out_string += "4"
    else:
        out_string += str(type_number)
    #add the dot
    n_of_dots = gn.duration.dots
    for _ in range(n_of_dots):
        out_string += "*"
    return out_string
Beispiel #2
0
 def fromDurationUnit(self, durationObj):
     """
     Simple lily duration: does not include tuplets
     These are taken care of in the lily processing in stream.Stream
     since lilypond requires tuplets to be in groups
     """
     if durationObj._typeNeedsUpdating:
         durationObj.updateType()
     number_type = duration.convertTypeToNumber(durationObj.type)  # module call
     dots = "." * int(durationObj.dots)
     if number_type < 1:
         number_type = int(number_type * 16)
     return str(number_type) + dots
Beispiel #3
0
 def fromDurationUnit(self, durationObj):
     '''
     Simple lily duration: does not include tuplets
     These are taken care of in the lily processing in stream.Stream
     since lilypond requires tuplets to be in groups
     '''
     if durationObj._typeNeedsUpdating:
         durationObj.updateType()
     number_type = duration.convertTypeToNumber(
         durationObj.type)  # module call
     dots = "." * int(durationObj.dots)
     if number_type < 1:
         number_type = int(number_type * 16)
     return str(number_type) + dots
Beispiel #4
0
 def lyMultipliedDurationFromDuration(self, durationObj):
     try:
         number_type = duration.convertTypeToNumber(durationObj.type) # module call
     except duration.DurationException as de:
         raise LilyTranslateException("DurationException for durationObject %s: %s" % (durationObj, de))
     
     if number_type < 1:
        number_type = int(number_type * 16)
     
     try:
         stenoDuration = lyo.LyStenoDuration(number_type, int(durationObj.dots))
         multipliedDuration = lyo.LyMultipliedDuration(stenoDuration)
     except duration.DurationException as de:
         raise LilyTranslateException("DurationException: Cannot translate durationObject %s: %s" % (durationObj, de))
     return multipliedDuration
Beispiel #5
0
def generalNote_info(gn):
    """
    Get a json of informations about a general note.
    The fields of the json are "type"-string (chord, rest,note), "pitches" (a list of pitches)-list of strings,"noteHead" (also for rests)-string,"dots"-integer.
    For rests the pitch is set to [\"A0\"].
    Does not consider the ties (because of music21 ties encoding).
    Arguments:
        gn {music21 general note} -- the general note to have the information
    """
    #pitches and type info
    if gn.isChord:
        pitches = [(p.step + str(p.octave), p.accidental)
                   for p in gn.sortDiatonicAscending().pitches]
        gn_type = "chord"
    elif gn.isRest:
        pitches = ["A0", None]  # pitch is set to ["A0"] for rests
        gn_type = "rest"
    elif gn.isNote:
        pitches = [(gn.step + str(gn.octave), gn.pitch.accidental)
                   ]  #a list with  one pitch inside
        gn_type = "note"
    else:
        raise TypeError("The generalNote must be a Chord, a Rest or a Note")

    #notehead information (4,2,1,1/2, etc...). 4 means a black note, 2 white, 1 whole etc...
    type_number = Fraction(duration.convertTypeToNumber(gn.duration.type))
    if type_number >= 4:
        note_head = "4"
    else:
        note_head = str(type_number)

    gn_info = {
        "type": gn_type,
        "pitches": pitches,
        "noteHead": note_head,
        "dots": gn.duration.dots
    }
    return gn_info
Beispiel #6
0
def get_types(note_list):
    _type_list = []
    for n in note_list:
        _type_list.append(duration.convertTypeToNumber(n.duration.type))
    return _type_list