def transferClefs(score,
                  measuresToDo):
    """
    Adjusts clefs to accommodate the new part (transferTune or chordHints).
    Optionally also does the transferTune while it's at it:
    """  # TODO: integrate with leaveRestBars.

    startAdditions = [measuresToDo[0]]  # First in measuresToDo definitely a startAddition
    startGaps = []
    for index in range(1, len(measuresToDo)):
        oneMoreThanLastEntry = measuresToDo[index-1] + 1
        if measuresToDo[index] != oneMoreThanLastEntry:
            startGaps.append(oneMoreThanLastEntry)
            startAdditions.append(measuresToDo[index])

    if measuresToDo[-1] != len(score.parts[0]):
        finalGap = measuresToDo[-1] + 1
        startGaps.append(finalGap)

    for index in range(len(startAdditions)):  # Either
        vClefAdd = score.parts[0].measure(startAdditions[index]).getContextByClass('Clef')
        pClefAdd = score.parts[1].measure(startAdditions[index]).getContextByClass('Clef')
        # vClefGap = score.parts[0].measure(startGaps[index]).getContextByClass('Clef')
        pClefGap = score.parts[1].measure(startGaps[index]).getContextByClass('Clef')
        if vClefAdd != pClefAdd:
            AddClef = vClefAdd.sign + str(vClefAdd.line)  # TODO simplify?
            GapClef = pClefGap.sign + str(pClefGap.line)
            score.parts[1].measure(startAdditions[index]).insert(0, clef.clefFromString(AddClef))
            score.parts[1].measure(startGaps[index]).insert(0, clef.clefFromString(GapClef))

    return score
예제 #2
0
    def clefFromClefSign(self, clefSign):
        '''
        returns a :class:`~music21.clef.Clef` object or subclass from a <clefSign> tag. 
        
        
        >>> ci = capella.fromCapellaXML.CapellaImporter()
        >>> clefSign = ci.domElementFromText('<clefSign clef="treble"/>')
        >>> ci.clefFromClefSign(clefSign)
        <music21.clef.TrebleClef>

        >>> clefSign = ci.domElementFromText('<clefSign clef="G2-"/>')
        >>> ci.clefFromClefSign(clefSign)
        <music21.clef.Treble8vbClef>

        >>> clefSign = ci.domElementFromText('<clefSign clef="F1+"/>')
        >>> clefObject = ci.clefFromClefSign(clefSign)
        >>> clefObject
        <music21.clef.FClef>
        >>> clefObject.sign
        'F'
        >>> clefObject.line
        1
        >>> clefObject.octaveShift
        1
        '''
        if 'clef' in clefSign._attrs:
            clefValue = clefSign._attrs['clef'].value
            if clefValue in self.clefMapping:
                return self.clefMapping[clefValue]()
            elif clefValue[0] == 'p':
                return clef.PercussionClef()
            elif len(clefValue) > 1:
                clefSignAndLine = clefValue[0:2]
                clefOctaveChange = 0
                if len(clefValue) > 2:
                    if clefValue[2] == '+':
                        clefOctaveChange = 1
                    elif clefValue[2] == '-':
                        clefOctaveChange = -1
                clefObj = clef.clefFromString(clefSignAndLine,
                                              clefOctaveChange)
                return clefObj

        return None
예제 #3
0
    def clefFromClefSign(self, clefSign):
        '''
        returns a :class:`~music21.clef.Clef` object or subclass from a <clefSign> tag. 
        
        
        >>> ci = capella.fromCapellaXML.CapellaImporter()
        >>> clefSign = ci.domElementFromText('<clefSign clef="treble"/>')
        >>> ci.clefFromClefSign(clefSign)
        <music21.clef.TrebleClef>

        >>> clefSign = ci.domElementFromText('<clefSign clef="G2-"/>')
        >>> ci.clefFromClefSign(clefSign)
        <music21.clef.Treble8vbClef>

        >>> clefSign = ci.domElementFromText('<clefSign clef="F1+"/>')
        >>> clefObject = ci.clefFromClefSign(clefSign)
        >>> clefObject
        <music21.clef.FClef>
        >>> clefObject.sign
        'F'
        >>> clefObject.line
        1
        >>> clefObject.octaveChange
        1
        '''
        if 'clef' in clefSign._attrs:
            clefValue = clefSign._attrs['clef'].value
            if clefValue in self.clefMapping:
                return self.clefMapping[clefValue]()
            elif clefValue[0] == 'p':
                return clef.PercussionClef()
            elif len(clefValue) > 1:
                clefSignAndLine = clefValue[0:2]
                clefOctaveChange = 0
                if len(clefValue) > 2:
                    if clefValue[2] == '+':
                        clefOctaveChange = 1
                    elif clefValue[2] == '-':
                        clefOctaveChange = -1
                clefObj = clef.clefFromString(clefSignAndLine, clefOctaveChange)
                return clefObj
                    
        return None
예제 #4
0
    def convertM21(self,outVote,arrError,ground):
        errorColor="#ff0000"
        missingColor="#00ff00"
#         sOut=stream.Stream()
        sOut=stream.Score()
        sPart=stream.Part()
        measureIndex=1
        measure=stream.Measure()
        measure.number=measureIndex
        indexS=0
       
        for symbol in outVote:
            mytie=""
            realDuration=None
            s=symbol
            isError=False
            isMissing=False
            if(len(ground)>indexS):
                sGround=ground[indexS]
            
            if(indexS in arrError):
                isError=True
                if s=="*":
                    s=sGround
                    isMissing=True
                            
            if isinstance(s,list):
                s=s[0]             
            if s.find('TS:')!=-1:
                ts=meter.TimeSignature(s[3:])
                if isError:
                    ts.color = errorColor
                if isMissing:
                    ts.color = missingColor
                measure.append(ts)
            if s.find('KS:')!=-1:
                k=key.KeySignature(int(s[3:]))
                if isError:
                    k.color = errorColor
                if isMissing:
                    k.color = missingColor
                measure.append(k)
            if s.find('CL:')!=-1:
                c=clef.clefFromString(str(s[3:]))
                if isError:
                    c.color = errorColor
                if isMissing:
                    c.color = missingColor
                measure.append(c)
            if s.find('N:')!=-1: 
                try:  
                    if isinstance(symbol,list):
                        realDuration=symbol[1]
                        mytie=symbol[2]
                        
                    sep=s.index("_")
                    duration=s[sep+1:]
#                     if realDuration!=None:
#                         duration=realDuration
                    if(float(duration)>0):
                        n=note.Note(s[2:sep],quarterLength=float(duration))
                        if isError:
                            n.color = errorColor
                        if isMissing:
                            n.color = missingColor
                        if mytie!="":
                            n.tie=tie.Tie(mytie)
                        measure.append(n)
                except:
                    print "error"+s
                    
            if s.find('R:')!=-1: 
                try:
                    if isinstance(symbol,list):
                        realDuration=symbol[1]
                        mytie=symbol[2]
                    duration=s[2:]
#                     if realDuration!=None:
#                         duration=realDuration
                    n=note.Rest(quarterLength=float(duration))
                    if isError:
                        n.color = errorColor
                    if isMissing:
                        n.color = missingColor
                    measure.append(n)
                except:
                    print "error"+s
                
            if s.find('C:')!=-1: 
                notes=s.split("[:")
                cPitch=[]
                for n in notes:
                    if n!='C:':
                        sep=n.index("_")
                        duration=n[sep+1:]
                        pitch= n[0:sep]
                        cPitch.append(pitch)
                c=chord.Chord(cPitch)
                c.duration.quarterLength=float(duration)
                if isError:
                    c.color = errorColor
                if isMissing:
                    c.color = missingColor
                measure.append(c)    
            if s.find('!')!=-1:
                
                if isinstance(symbol,list):
                    barType= symbol[1]
                    barRepeat= symbol[2]
                    if barType!="":
                        mybartype=bar.styleToMusicXMLBarStyle(barType)
                        myBar=bar.Barline(style=mybartype)
                        measure.rightBarline=myBar
    
                    if barRepeat!="":
                        myBar=bar.Repeat(direction=barRepeat)
                        if barRepeat=="start":
                            measure.leftBarline=myBar
                        if barRepeat=="end":
                            measure.rightBarline=myBar
                sPart.append(measure)
                measureIndex+=1
                measure=stream.Measure()
                measure.number=measureIndex
            indexS+=1        
        
        sOut.append(sPart)   
        return sOut
예제 #5
0
    def convertM21(self, outVote, arrError, ground):
        errorColor = "#ff0000"
        missingColor = "#00ff00"
        #         sOut=stream.Stream()
        sOut = stream.Score()
        sPart = stream.Part()
        measureIndex = 1
        measure = stream.Measure()
        measure.number = measureIndex
        indexS = 0

        for symbol in outVote:
            mytie = ""
            realDuration = None
            s = symbol
            isError = False
            isMissing = False
            if (len(ground) > indexS):
                sGround = ground[indexS]

            if (indexS in arrError):
                isError = True
                if s == "*":
                    s = sGround
                    isMissing = True

            if isinstance(s, list):
                s = s[0]
            if s.find('TS:') != -1:
                ts = meter.TimeSignature(s[3:])
                if isError:
                    ts.color = errorColor
                if isMissing:
                    ts.color = missingColor
                measure.append(ts)
            if s.find('KS:') != -1:
                k = key.KeySignature(int(s[3:]))
                if isError:
                    k.color = errorColor
                if isMissing:
                    k.color = missingColor
                measure.append(k)
            if s.find('CL:') != -1:
                c = clef.clefFromString(str(s[3:]))
                if isError:
                    c.color = errorColor
                if isMissing:
                    c.color = missingColor
                measure.append(c)
            if s.find('N:') != -1:
                try:
                    if isinstance(symbol, list):
                        realDuration = symbol[1]
                        mytie = symbol[2]

                    sep = s.index("_")
                    duration = s[sep + 1:]
                    #                     if realDuration!=None:
                    #                         duration=realDuration
                    if (float(duration) > 0):
                        n = note.Note(s[2:sep], quarterLength=float(duration))
                        if isError:
                            n.color = errorColor
                        if isMissing:
                            n.color = missingColor
                        if mytie != "":
                            n.tie = tie.Tie(mytie)
                        measure.append(n)
                except:
                    print "error" + s

            if s.find('R:') != -1:
                try:
                    if isinstance(symbol, list):
                        realDuration = symbol[1]
                        mytie = symbol[2]
                    duration = s[2:]
                    #                     if realDuration!=None:
                    #                         duration=realDuration
                    n = note.Rest(quarterLength=float(duration))
                    if isError:
                        n.color = errorColor
                    if isMissing:
                        n.color = missingColor
                    measure.append(n)
                except:
                    print "error" + s

            if s.find('C:') != -1:
                notes = s.split("[:")
                cPitch = []
                for n in notes:
                    if n != 'C:':
                        sep = n.index("_")
                        duration = n[sep + 1:]
                        pitch = n[0:sep]
                        cPitch.append(pitch)
                c = chord.Chord(cPitch)
                c.duration.quarterLength = float(duration)
                if isError:
                    c.color = errorColor
                if isMissing:
                    c.color = missingColor
                measure.append(c)
            if s.find('!') != -1:

                if isinstance(symbol, list):
                    barType = symbol[1]
                    barRepeat = symbol[2]
                    if barType != "":
                        mybartype = bar.styleToMusicXMLBarStyle(barType)
                        myBar = bar.Barline(style=mybartype)
                        measure.rightBarline = myBar

                    if barRepeat != "":
                        myBar = bar.Repeat(direction=barRepeat)
                        if barRepeat == "start":
                            measure.leftBarline = myBar
                        if barRepeat == "end":
                            measure.rightBarline = myBar
                sPart.append(measure)
                measureIndex += 1
                measure = stream.Measure()
                measure.number = measureIndex
            indexS += 1

        sOut.append(sPart)
        return sOut