Exemple #1
0
    def _checkRestForVerticalPositioning(rest: HumdrumToken,
                                         baseline: int) -> bool:
        m = re.search(r'([A-Ga-g]+)', rest.text)
        if m is None:
            return False

        pitch: str = m.group(1)
        b7: int = Convert.kernToBase7(pitch)
        if b7 < 0:
            # that wasn't really a pitch, no vertical positioning for you
            return False

        diff: int = (b7 - baseline) + 100
        if diff % 2 != 0:
            # force to every other diatonic step (staff lines)
            if rest.duration > 1:
                b7 -= 1
            else:
                b7 += 1

        # Instead of ploc and oloc for MEI (which humlib does), compute and save what the
        # stepShift for a music21 rest should be.
        # stepShift = 0 means "on the middle line", -1 means "in the first space below the
        # midline", +2 means "on the line above the midline", etc.
        # baseline is the base7 pitch of the lowest line in the staff -> stepShift = -4
        # b7 is the base7 pitch (including octave) of where the rest should go, so:

        # midline is 2 spaces + 2 lines (4 diatonic steps) above baseline
        midline: int = baseline + 4
        stepShift: int = b7 - midline
        rest.setValue('auto', 'stepShift', str(stepShift))

        return True
Exemple #2
0
    def _linkTieEndpoints(tieStart: HumdrumToken, startSubtokenIdx: int,
                          tieEnd: HumdrumToken, endSubtokenIdx: int) -> None:
        durTag: str = 'tieDuration'
        startTag: str = 'tieStart'
        endTag: str = 'tieEnd'
        startNumTag: str = 'tieStartSubtokenNumber'
        endNumTag: str = 'tieEndSubtokenNumber'

        startSubtokenNumber: int = startSubtokenIdx + 1
        endSubtokenNumber: int = endSubtokenIdx + 1

        if tieStart.isChord:
            if startSubtokenNumber > 0:
                startSuffix: str = str(startSubtokenNumber)
                durTag += startSuffix
                endNumTag += startSuffix
                endTag += startSuffix

        if tieEnd.isChord:
            if endSubtokenNumber > 0:
                endSuffix: str = str(endSubtokenNumber)
                startTag += endSuffix
                startNumTag += endSuffix

        tieStart.setValue('auto', endTag, tieEnd)
        tieStart.setValue('auto', 'id', tieStart)
        if endSubtokenNumber > 0:
            tieStart.setValue('auto', endNumTag, str(endSubtokenNumber))

        tieEnd.setValue('auto', startTag, tieStart)
        tieEnd.setValue('auto', 'id', tieEnd)
        if startSubtokenNumber > 0:
            tieEnd.setValue('auto', startNumTag, str(startSubtokenNumber))

        duration: HumNum = opFrac(tieEnd.durationFromStart -
                                  tieStart.durationFromStart)
        tieStart.setValue('auto', durTag, duration)
Exemple #3
0
    def _linkSlurOrPhraseEndpoints(slurOrPhrase: str, startTok: HumdrumToken,
                                   endTok: HumdrumToken) -> None:
        if slurOrPhrase == HumdrumToken.SLUR:
            prefix = 'slur'
        else:
            prefix = 'phrase'

        durTag: str = prefix + 'Duration'
        endTag: str = prefix + 'EndId'
        startTag: str = prefix + 'StartId'
        startNumberTag: str = prefix + 'StartNumber'
        endNumberTag: str = prefix + 'EndNumber'
        startCountTag: str = prefix + 'StartCount'
        endCountTag: str = prefix + 'EndCount'

        startCount: int = startTok.getValueInt('auto', startCountTag) + 1
        openCount: int = startTok.text.count(slurOrPhrase)
        openEnumeration = openCount - startCount + 1

        if openEnumeration > 1:
            openSuffix: str = str(openEnumeration)
            endTag += openSuffix
            durTag += openSuffix

        endCount: int = endTok.getValueInt('auto', endCountTag) + 1
        closeEnumeration: int = endCount
        if closeEnumeration > 1:
            closeSuffix: str = str(closeEnumeration)
            startTag += closeSuffix
            startNumberTag += closeSuffix

        duration: HumNum = opFrac(endTok.durationFromStart -
                                  startTok.durationFromStart)

        startTok.setValue('auto', endTag, endTok)
        startTok.setValue('auto', 'id', startTok)
        startTok.setValue('auto', endNumberTag, closeEnumeration)
        startTok.setValue('auto', durTag, duration)
        startTok.setValue('auto', startCountTag, startCount)

        endTok.setValue('auto', startTag, startTok)
        endTok.setValue('auto', 'id', endTok)
        endTok.setValue('auto', startNumberTag, openEnumeration)
        endTok.setValue('auto', endCountTag, endCount)