Пример #1
0
    def convertBlockToStreams(self, thisBlock):
        '''
        Takes a block of music information (in
        :class:`~music21.alpha.trecento.trecentoCadence.TrecentoCadenceStream` notation)
        and returns a list of Streams and other information



        >>> block1 = ['e4 f g a', 'g4 a b cc', '', 'no-cadence', '2/4']
        >>> bs = alpha.trecento.cadencebook.BallataSheet()
        >>> dummyPiece = bs.makeWork(2)
        >>> blockStreams = dummyPiece.convertBlockToStreams(block1)
        >>> for x in blockStreams:
        ...     print(x)
        <music21.stream.Part ...>
        <music21.stream.Part ...>
        None
        no-cadence
        2/4
        >>> blockStreams[0].show('text')
        {0.0} <music21.stream.Measure 1 offset=0.0>
            {0.0} <music21.clef.TrebleClef>
            {0.0} <music21.meter.TimeSignature 2/4>
            {0.0} <music21.note.Note E>
            {1.0} <music21.note.Note F>
        {2.0} <music21.stream.Measure 2 offset=2.0>
            {0.0} <music21.note.Note G>
            {1.0} <music21.note.Note A>
            {2.0} <music21.bar.Barline style=final>


        '''
        returnBlock = [None, None, None, None, None]
        currentTimeSig = thisBlock[4]
        returnBlock[4] = currentTimeSig
        returnBlock[3] = thisBlock[3]
        for i in range(3):
            thisVoice = thisBlock[i]
            thisVoice = thisVoice.strip()
            if (thisVoice):
                try:
                    returnBlock[i] = trecentoCadence.CadenceConverter(
                        currentTimeSig + " " + thisVoice).parse().stream
                except duration.DurationException as value:
                    raise duration.DurationException(
                        "Problems in line %s: specifically %s" %
                        (thisVoice, value))


#                except Exception, (value):
#                    raise Exception("Unknown Problems in line %s: specifically %s" %
#                    (thisVoice,  value))

        return returnBlock
Пример #2
0
 def convertBlockToStreams(self, thisBlock):
     '''
     Takes a block of music information (in :class:`~music21.trecento.trecentoCadence.TrecentoCadenceStream` notation)
     and returns a list of Streams and other information
     
     
     
     >>> block1 = ['e4 f g a', 'g4 a b cc', '', 'no-cadence', '2/4']
     >>> bs = trecento.cadencebook.BallataSheet()
     >>> dummyPiece = bs.makeWork(2)
     >>> blockStreams = dummyPiece.convertBlockToStreams(block1)
     >>> for x in blockStreams:
     ...     print(x)
     <music21.trecento.trecentoCadence.TrecentoCadenceStream ...>
     <music21.trecento.trecentoCadence.TrecentoCadenceStream ...>
     None
     no-cadence
     2/4
     >>> blockStreams[0].show('text')
     {0.0} <music21.meter.TimeSignature 2/4>
     {0.0} <music21.note.Note E>
     {1.0} <music21.note.Note F>
     {2.0} <music21.note.Note G>
     {3.0} <music21.note.Note A>
     '''
     returnBlock = [None, None, None, None, None]
     currentTimeSig = thisBlock[4]
     returnBlock[4] = currentTimeSig
     returnBlock[3] = thisBlock[3]
     for i in range(0,3):
         thisVoice = thisBlock[i]
         thisVoice = thisVoice.strip()
         if (thisVoice):
             try:
                 returnBlock[i] = trecentoCadence.TrecentoCadenceStream(thisVoice, currentTimeSig)
             except duration.DurationException, (value):
                 raise duration.DurationException("Problems in line %s: specifically %s" % (thisVoice,  value))
Пример #3
0
    def __init__(self, stringRep="", timeSignature=None):
        stream.Stream.__init__(self)
        self.stringRep = stringRep
        noteStrs = self.stringRep.split()

        self.setupRegularExpressions()

        if (timeSignature is None):
            barDuration = duration.Duration()
            barDuration.type = "whole"  ## assume 4/4
        elif (hasattr(timeSignature,
                      "barDuration")):  # is a TimeSignature object
            barDuration = timeSignature.barDuration
        else:  # is a string
            timeSignature = meter.TimeSignature(timeSignature)
            barDuration = timeSignature.barDuration

        noteList = []
        if timeSignature is not None and hasattr(timeSignature, "barDuration"):
            noteList.append(timeSignature)

        parseStatus = {
            'inTrip': False,
            'inQuad': False,
            'beginTuplet': False,
            'endTuplet': False,
            'lastDuration': None,
            'barDuration': barDuration,
            'lastNoteTied': False,
        }

        for thisNoteStr in noteStrs:
            if self.TRIP.match(thisNoteStr):
                thisNoteStr = self.TRIP.sub('', thisNoteStr)
                parseStatus['inTrip'] = True
                parseStatus['beginTuplet'] = True
            elif self.QUAD.match(thisNoteStr):
                thisNoteStr = self.QUAD.sub('', thisNoteStr)
                parseStatus['inQuad'] = True
                parseStatus['beginTuplet'] = True
            elif self.ENDBRAC.search(thisNoteStr):
                thisNoteStr = self.ENDBRAC.sub('', thisNoteStr)
                parseStatus['endTuplet'] = True
            elif self.TIMESIG.match(thisNoteStr):
                newTime = self.TIMESIG.match(thisNoteStr).group(1)
                timeSignature = meter.TimeSignature(newTime)
                barDuration = timeSignature.barDuration
                parseStatus['barDuration'] = barDuration
                noteList.append(timeSignature)
                continue

            tN = None
            try:
                tN = self.getNote(thisNoteStr, parseStatus)
            except duration.DurationException as value:
                raise duration.DurationException(
                    str(value) + " in context " + str(thisNoteStr))


#            except Exception, (value):
#                raise Exception(str(value) + "in context " + str(thisNoteStr) + ": " + str(stringRep) )
#try:
            noteList.append(tN.note)
            #except TinyNotationException:
            #    raise TinyNotationException(thisNoteStr + " " + str(noteStrs))

            if parseStatus['endTuplet'] == True:
                parseStatus['endTuplet'] = False

                if parseStatus['inTrip'] == True:
                    parseStatus['inTrip'] = False
                elif parseStatus['inQuad'] == True:
                    parseStatus['inQuad'] = False
                else:
                    raise TinyNotationException(
                        "unexpected end bracket in TinyNotationStream")

            parseStatus['beginTuplet'] = False

        for thisNote in noteList:
            self.append(thisNote)