Esempio n. 1
0
def test_HumdrumLine_data():
    line = HumdrumLine('4f]\t.\t2D\t(1cc\t.')
    line.createTokensFromLine()
    CheckHumdrumLine(line, expectedLine = '4f]\t.\t2D\t(1cc\t.',
                           expectedLineNumber = 0,
                           expectedType = LINETYPE_DATA,
                           expectedTokenCount = 5,
                           expectedIsExclusiveInterpretation = False,
                           expectedIsManipulator = False,
                           expectedTokens = ['4f]', '.', '2D', '(1cc', '.'])
Esempio n. 2
0
def test_HumdrumLine_barline():
    line = HumdrumLine('=1\t=1\t=1')
    line.createTokensFromLine()
    CheckHumdrumLine(line, expectedLine = '=1\t=1\t=1',
                           expectedLineNumber = 0,
                           expectedType = LINETYPE_BARLINE,
                           expectedTokenCount = 3,
                           expectedIsExclusiveInterpretation = False,
                           expectedIsManipulator = False,
                           expectedTokens = ['=1', '=1', '=1'])
Esempio n. 3
0
def test_HumdrumLine_manipulators():
    line = HumdrumLine('*\t*^\t*-\t*')
    line.createTokensFromLine()
    CheckHumdrumLine(line, expectedLine = '*\t*^\t*-\t*',
                           expectedLineNumber = 0,
                           expectedType = LINETYPE_INTERPRETATION,
                           expectedTokenCount = 4,
                           expectedIsExclusiveInterpretation = False,
                           expectedIsManipulator = True,
                           expectedTokens = ['*', '*^', '*-', '*'])
Esempio n. 4
0
def test_HumdrumLine_single_exinterp():
    line = HumdrumLine('**kern')
    line.createTokensFromLine()
    CheckHumdrumLine(line, expectedLine = '**kern',
                           expectedLineNumber = 0,
                           expectedType = LINETYPE_INTERPRETATION,
                           expectedTokenCount = 1,
                           expectedIsExclusiveInterpretation = True,
                           expectedIsManipulator = True,
                           expectedTokens = ['**kern'])
Esempio n. 5
0
    def transferSidesFromPart(line: HumdrumLine, part: GridPart, emptyStr: str,
                              maxhcount: int, maxfcount: int):
        sides: GridSide = part.sides
        hcount: int = sides.harmonyCount

        # FIGURED BASS
        if maxfcount > 0:
            figuredBass: HumdrumToken = sides.figuredBass
            if figuredBass is not None:
                line.appendToken(figuredBass)
            else:
                line.appendToken(HumdrumToken(emptyStr))

        # HARMONY
        for _ in range(0, hcount):
            harmony: HumdrumToken = sides.harmony
            if harmony is not None:
                line.appendToken(harmony)
            else:
                line.appendToken(HumdrumToken(emptyStr))

        for _ in range(hcount, maxhcount):
            line.appendToken(HumdrumToken(emptyStr))
Esempio n. 6
0
def CheckHumdrumLine( line: HumdrumLine,
                        expectedLine: str = '',
                        expectedLineNumber: int = None,
                        expectedType: str = LINETYPE_EMPTY,
                        expectedTokenCount: int = 1,
                        expectedIsExclusiveInterpretation: bool = False,
                        expectedIsManipulator: bool = False,
                        expectedTokens: [str] = None ):
    # set up some derived expectations
    expectedIsData = expectedType == LINETYPE_DATA
    expectedIsBarline = expectedType == LINETYPE_BARLINE
    expectedIsInterpretation = expectedType == LINETYPE_INTERPRETATION
    expectedIsLocalComment = expectedType == LINETYPE_LOCALCOMMENT
    expectedIsGlobalComment = expectedType == LINETYPE_GLOBALCOMMENT
    expectedIsGlobalReference = expectedType == LINETYPE_GLOBALREFERENCE
    expectedIsUniversalComment = expectedType == LINETYPE_UNIVERSALCOMMENT
    expectedIsUniversalReference = expectedType == LINETYPE_UNIVERSALREFERENCE
    expectedIsComment = expectedType in commentTypeTuple
    expectedHasSpines = expectedType in hasSpinesTypeTuple
    expectedIsGlobal = expectedType in isGlobalTypeTuple

    expectedIsAllNull = False # if no spines
    if expectedHasSpines:
        # default to True if hasSpines, then if we see a non-null token, we set to False and get out
        expectedIsAllNull = True
        for tokenText in expectedTokens:
            if expectedIsInterpretation and tokenText != '*':
                expectedIsAllNull = False
                break
            if expectedIsLocalComment and tokenText != '!':
                expectedIsAllNull = False
                break
            if (expectedIsData or expectedIsBarline) and tokenText != '.':
                expectedIsAllNull = False
                break

    assert line.lineNumber == expectedLineNumber
    assert line.text == expectedLine
    assert str(line) == expectedLine

    # interrogate the line various ways
    assert line.isAllNull == expectedIsAllNull
    assert line.isData == expectedIsData
    assert line.isBarline == expectedIsBarline
    assert line.isInterpretation == expectedIsInterpretation
    assert line.isLocalComment == expectedIsLocalComment
    assert line.isGlobalComment == expectedIsGlobalComment
    assert line.isGlobalReference == expectedIsGlobalReference
    assert line.isUniversalComment == expectedIsUniversalComment
    assert line.isUniversalReference == expectedIsUniversalReference
    assert line.isComment == expectedIsComment
    assert line.hasSpines == expectedHasSpines # isLocal, in other words
    assert line.isGlobal == expectedIsGlobal
    assert line.isExclusiveInterpretation == expectedIsExclusiveInterpretation
    assert line.isManipulator == expectedIsManipulator

    # check that tokenCount and the length of all the arrays are expectedTokenCount
    assert line.tokenCount == expectedTokenCount
    assert len(list(line.tokens())) == expectedTokenCount

    # check the line tokens themselves
    if expectedTokens is not None: # is None if we have no way of expecting a particular list of tokens
        assert [str(token) for token in line.tokens()] == expectedTokens
        assert [line[tokIdx].text for tokIdx in range(0, line.tokenCount)] == expectedTokens
Esempio n. 7
0
    def transferSidesFromStaff(line: HumdrumLine, staff: GridStaff,
                               emptyStr: str, maxxcount: int, maxdcount: int,
                               maxvcount: int):
        sides: GridSide = staff.sides
        vcount: int = sides.verseCount

        # XMLID
        if maxxcount > 0:
            xmlId: HumdrumToken = sides.xmlId
            if xmlId is not None:
                line.appendToken(xmlId)
            else:
                line.appendToken(HumdrumToken(emptyStr))

        # DYNAMICS
        if maxdcount > 0:
            dynamics: HumdrumToken = sides.dynamics
            if dynamics is not None:
                line.appendToken(dynamics)
            else:
                line.appendToken(HumdrumToken(emptyStr))

        # VERSES
        for i in range(0, vcount):
            verse: HumdrumToken = sides.getVerse(i)
            if verse is not None:
                line.appendToken(verse)
            else:
                line.appendToken(HumdrumToken(emptyStr))

        for i in range(vcount, maxvcount):
            line.appendToken(HumdrumToken(emptyStr))
Esempio n. 8
0
    def transferTokens(self, outFile: HumdrumFile, recip: bool):
        line: HumdrumLine = HumdrumLine()
        voice: GridVoice = None
        emptyStr: str = '.'

        if self.isMeasureSlice:
            if len(self.parts) > 0:
                if len(self.parts[0].staves[0].voices) > 0:
                    voice = self.parts[0].staves[0].voices[0]
                    if voice.token is not None:
                        emptyStr = voice.token.text
                    else:
                        emptyStr = '=YYYYYY'
                else:
                    emptyStr = '=YYYYYY'
        elif self.isInterpretationSlice:
            emptyStr = '*'
        elif self.isLocalLayoutSlice:
            emptyStr = '!'
        elif not self.hasSpines:
            emptyStr = '???'

        if recip:
            token: HumdrumToken = None

            if self.isNoteSlice:
                token = self._createRecipTokenFromDuration(self.duration)
            elif self.isClefSlice:
                token = HumdrumToken('*')
                emptyStr = '*'
            elif self.isMeasureSlice:
                if len(self.parts[0].staves[0]) > 0:
                    voice = self.parts[0].staves[0].voices[0]
                    token = HumdrumToken(voice.token.text)
                else:
                    token = HumdrumToken('=XXXXX')
                emptyStr = token.text
            elif self.isInterpretationSlice:
                token = HumdrumToken('*')
                emptyStr = '*'
            elif self.isGraceSlice:
                token = HumdrumToken('q')
                emptyStr = '.'
            elif self.hasSpines:
                token = HumdrumToken('55')
                emptyStr = '!'

            if token is not None:
                if self.hasSpines:
                    line.appendToken(token)
                else:
                    token = None

        # extract the Tokens from each part/staff
        for p in range(len(self.parts) - 1, -1, -1):
            part = self.parts[p]
            if not self.hasSpines and p != 0:
                continue
            for s in range(len(part.staves) - 1, -1, -1):
                staff = part.staves[s]
                if not self.hasSpines and s != 0:
                    continue
                if len(staff.voices) == 0:
                    # 888: fix this later.  For now if there are no notes
                    # 888: ... on the staff, add a null token.  Fix so that
                    # 888: ... all open voices are given null tokens.
                    line.appendToken(HumdrumToken(emptyStr))
                else:
                    for voice in staff.voices:  # NOT reversed (voices different from parts/staves)
                        if voice is not None and voice.token is not None:
                            line.appendToken(voice.token)
                        else:
                            line.appendToken(HumdrumToken(emptyStr))

                if not self.hasSpines:
                    # Don't add sides to non-spined lines
                    continue

                maxxcount: int = self.getXmlIdCount(p, s)
                maxdcount: int = self.getDynamicsCount(p, s)
                maxvcount: int = self.getVerseCount(p, s)
                self.transferSidesFromStaff(line, staff, emptyStr, maxxcount,
                                            maxdcount, maxvcount)

            if not self.hasSpines:
                # Don't add sides to non-spined lines
                continue

            maxhcount: int = self.getHarmonyCount(p)
            maxfcount: int = self.getFiguredBassCount(p)
            self.transferSidesFromPart(line, part, emptyStr, maxhcount,
                                       maxfcount)

        outFile.appendLine(line)
Esempio n. 9
0
def test_HumdrumLine_default_init():
    line = HumdrumLine()
    line.createTokensFromLine()
    CheckHumdrumLine(line)