Esempio n. 1
0
    def getAllVoiceLeadingQuartets(self,
                                   includeRests=True,
                                   includeOblique=True,
                                   includeNoMotion=False,
                                   returnObjects=True,
                                   partPairNumbers=None):
        '''
        >>> c = corpus.parse('luca/gloria').measures(1,8)
        >>> tsCol = stream.timespans.streamToTimespanCollection(c)
        >>> verticality22 = tsCol.getVerticalityAt(22.0)
        
        >>> from pprint import pprint as pp
        >>> for vlq in verticality22.getAllVoiceLeadingQuartets():
        ...     pp(vlq)
        <music21.voiceLeading.VoiceLeadingQuartet v1n1=<music21.note.Note E> , v1n2=<music21.note.Note F>, v2n1=<music21.note.Note G>, v2n2=<music21.note.Note C>  
        <music21.voiceLeading.VoiceLeadingQuartet v1n1=<music21.note.Note E> , v1n2=<music21.note.Note F>, v2n1=<music21.note.Note A>, v2n2=<music21.note.Note A>  
        <music21.voiceLeading.VoiceLeadingQuartet v1n1=<music21.note.Note G> , v1n2=<music21.note.Note C>, v2n1=<music21.note.Note A>, v2n2=<music21.note.Note A>  

        >>> for vlq in verticality22.getAllVoiceLeadingQuartets(includeRests = False):
        ...     pp(vlq)
        <music21.voiceLeading.VoiceLeadingQuartet v1n1=<music21.note.Note E> , v1n2=<music21.note.Note F>, v2n1=<music21.note.Note A>, v2n2=<music21.note.Note A>  

        >>> for vlq in verticality22.getAllVoiceLeadingQuartets(includeOblique=False):
        ...     pp(vlq)
        <music21.voiceLeading.VoiceLeadingQuartet v1n1=<music21.note.Note E> , v1n2=<music21.note.Note F>, v2n1=<music21.note.Note G>, v2n2=<music21.note.Note C>  

        >>> verticality22.getAllVoiceLeadingQuartets(includeOblique=False, includeRests=False)
        []


        Raw output
        
        >>> for vlqRaw in verticality22.getAllVoiceLeadingQuartets(returnObjects=False):
        ...     pp(vlqRaw)
        ((<ElementTimespan (21.0 to 22.0) <music21.note.Note E>>,
          <ElementTimespan (22.0 to 23.0) <music21.note.Note F>>),
         (<ElementTimespan (19.5 to 21.0) <music21.note.Note G>>,
          <ElementTimespan (22.0 to 22.5) <music21.note.Note C>>))
        ((<ElementTimespan (21.0 to 22.0) <music21.note.Note E>>,
          <ElementTimespan (22.0 to 23.0) <music21.note.Note F>>),
         (<ElementTimespan (21.5 to 22.5) <music21.note.Note A>>,
          <ElementTimespan (21.5 to 22.5) <music21.note.Note A>>))
        ((<ElementTimespan (19.5 to 21.0) <music21.note.Note G>>,
          <ElementTimespan (22.0 to 22.5) <music21.note.Note C>>),
         (<ElementTimespan (21.5 to 22.5) <music21.note.Note A>>,
          <ElementTimespan (21.5 to 22.5) <music21.note.Note A>>))
          
        >>> for vlq in verticality22.getAllVoiceLeadingQuartets(partPairNumbers=[(0,1)]):
        ...     pp(vlq)
        <music21.voiceLeading.VoiceLeadingQuartet v1n1=<music21.note.Note E> , v1n2=<music21.note.Note F>, v2n1=<music21.note.Note G>, v2n2=<music21.note.Note C>          
        
        >>> for vlq in verticality22.getAllVoiceLeadingQuartets(partPairNumbers=[(0,2),(1,2)]):
        ...     pp(vlq)
        <music21.voiceLeading.VoiceLeadingQuartet v1n1=<music21.note.Note E> , v1n2=<music21.note.Note F>, v2n1=<music21.note.Note A>, v2n2=<music21.note.Note A>  
        <music21.voiceLeading.VoiceLeadingQuartet v1n1=<music21.note.Note G> , v1n2=<music21.note.Note C>, v2n1=<music21.note.Note A>, v2n2=<music21.note.Note A>          
        
        '''
        import itertools
        from music21.voiceLeading import VoiceLeadingQuartet
        pairedMotionList = self.getPairedMotion(includeRests=includeRests,
                                                includeOblique=includeOblique)
        allQuartets = itertools.combinations(pairedMotionList, 2)
        filteredList = []

        verticalityStreamParts = self.timespanCollection.source.parts

        for thisQuartet in allQuartets:
            if includeNoMotion is False:
                if (thisQuartet[0][0].pitches == thisQuartet[0][1].pitches
                        and thisQuartet[1][0].pitches
                        == thisQuartet[1][1].pitches):
                    continue
                if partPairNumbers is not None:
                    isAppropriate = False
                    for pp in partPairNumbers:
                        thisQuartetTopPart = thisQuartet[0][0].part
                        thisQuartetBottomPart = thisQuartet[1][0].part
                        if (((verticalityStreamParts[pp[0]]
                              == thisQuartetTopPart) or
                             (verticalityStreamParts[pp[0]]
                              == thisQuartetBottomPart))
                                and ((verticalityStreamParts[pp[1]]
                                      == thisQuartetTopPart) or
                                     (verticalityStreamParts[pp[1]]
                                      == thisQuartetBottomPart))):
                            isAppropriate = True
                            break
                    if (isAppropriate is False):
                        continue

                if returnObjects is False:
                    filteredList.append(thisQuartet)
                else:
                    n11 = thisQuartet[0][0].element
                    n12 = thisQuartet[0][1].element
                    n21 = thisQuartet[1][0].element
                    n22 = thisQuartet[1][1].element
                    vlq = VoiceLeadingQuartet(n11, n12, n21, n22)
                    filteredList.append(vlq)

        return filteredList
Esempio n. 2
0
    def getAllVoiceLeadingQuartets(self,
                                   includeRests=True,
                                   includeOblique=True,
                                   includeNoMotion=False,
                                   returnObjects=True,
                                   partPairNumbers=None):
        '''
        >>> c = corpus.parse('luca/gloria').measures(1, 8)
        >>> tsCol = tree.fromStream.asTimespans(c, flatten=True,
        ...            classList=(note.Note, chord.Chord))
        >>> verticality22 = tsCol.getVerticalityAt(22.0)

        >>> from pprint import pprint as pp
        >>> for vlq in verticality22.getAllVoiceLeadingQuartets():
        ...     pp(vlq)
        <music21.voiceLeading.VoiceLeadingQuartet
            v1n1=G4, v1n2=C4, v2n1=E4, v2n2=F4>
        <music21.voiceLeading.VoiceLeadingQuartet
            v1n1=G4, v1n2=C4, v2n1=A3, v2n2=A3>
        <music21.voiceLeading.VoiceLeadingQuartet
            v1n1=E4, v1n2=F4, v2n1=A3, v2n2=A3>

        >>> for vlq in verticality22.getAllVoiceLeadingQuartets(includeRests=False):
        ...     pp(vlq)
        <music21.voiceLeading.VoiceLeadingQuartet
            v1n1=E4, v1n2=F4, v2n1=A3, v2n2=A3>
        >>> for vlq in verticality22.getAllVoiceLeadingQuartets(includeOblique=False):
        ...     pp(vlq)
        <music21.voiceLeading.VoiceLeadingQuartet
            v1n1=G4, v1n2=C4, v2n1=E4, v2n2=F4>
        >>> verticality22.getAllVoiceLeadingQuartets(includeOblique=False, includeRests=False)
        []


        Raw output

        >>> for vlqRaw in verticality22.getAllVoiceLeadingQuartets(returnObjects=False):
        ...     pp(vlqRaw)
        ((<PitchedTimespan (19.5 to 21.0) <music21.note.Note G>>,
          <PitchedTimespan (22.0 to 22.5) <music21.note.Note C>>),
         (<PitchedTimespan (21.0 to 22.0) <music21.note.Note E>>,
          <PitchedTimespan (22.0 to 23.0) <music21.note.Note F>>))
        ((<PitchedTimespan (19.5 to 21.0) <music21.note.Note G>>,
          <PitchedTimespan (22.0 to 22.5) <music21.note.Note C>>),
         (<PitchedTimespan (21.5 to 22.5) <music21.note.Note A>>,
          <PitchedTimespan (21.5 to 22.5) <music21.note.Note A>>))
        ((<PitchedTimespan (21.0 to 22.0) <music21.note.Note E>>,
          <PitchedTimespan (22.0 to 23.0) <music21.note.Note F>>),
         (<PitchedTimespan (21.5 to 22.5) <music21.note.Note A>>,
          <PitchedTimespan (21.5 to 22.5) <music21.note.Note A>>))

        >>> for vlq in verticality22.getAllVoiceLeadingQuartets(partPairNumbers=[(0, 1)]):
        ...     pp(vlq)
        <music21.voiceLeading.VoiceLeadingQuartet
            v1n1=G4, v1n2=C4, v2n1=E4, v2n2=F4>
        >>> for vlq in verticality22.getAllVoiceLeadingQuartets(partPairNumbers=[(0, 2), (1, 2)]):
        ...     pp(vlq)
        <music21.voiceLeading.VoiceLeadingQuartet
            v1n1=G4, v1n2=C4, v2n1=A3, v2n2=A3>
        <music21.voiceLeading.VoiceLeadingQuartet
            v1n1=E4, v1n2=F4, v2n1=A3, v2n2=A3>
        '''
        from music21.voiceLeading import VoiceLeadingQuartet
        pairedMotionList = self.getPairedMotion(includeRests=includeRests,
                                                includeOblique=includeOblique)
        allQuartets = itertools.combinations(pairedMotionList, 2)
        filteredList = []

        verticalityStreamParts = self.timespanTree.source.parts

        for thisQuartet in allQuartets:
            if includeNoMotion is False:
                if (thisQuartet[0][0].pitches == thisQuartet[0][1].pitches
                        and thisQuartet[1][0].pitches
                        == thisQuartet[1][1].pitches):
                    continue
                if partPairNumbers is not None:
                    isAppropriate = False
                    for pp in partPairNumbers:
                        thisQuartetTopPart = thisQuartet[0][0].part
                        thisQuartetBottomPart = thisQuartet[1][0].part
                        if ((verticalityStreamParts[pp[0]]
                             == thisQuartetTopPart
                             or verticalityStreamParts[pp[0]]
                             == thisQuartetBottomPart)
                                and (verticalityStreamParts[pp[1]]
                                     == thisQuartetTopPart
                                     or verticalityStreamParts[pp[1]]
                                     == thisQuartetBottomPart)):
                            isAppropriate = True
                            break
                    if not isAppropriate:
                        continue

                if returnObjects is False:
                    filteredList.append(thisQuartet)
                else:
                    n11 = thisQuartet[0][0].element
                    n12 = thisQuartet[0][1].element
                    n21 = thisQuartet[1][0].element
                    n22 = thisQuartet[1][1].element

                    if (n11 is not None and n12 is not None and n21 is not None
                            and n22 is not None):
                        vlq = VoiceLeadingQuartet(n11, n12, n21, n22)
                        filteredList.append(vlq)

        return filteredList
Esempio n. 3
0
 def isParallelFifth(self, note11, note12, note21, note22):
     '''Given four notes, assuming the first pair sounds at the same time and
     the second pair sounds at the same time, returns True if the two
     harmonic intervals are P5 and False otherwise.'''
     vlq = VoiceLeadingQuartet(note11, note12, note21, note22)
     return vlq.parallelFifth()