Exemplo n.º 1
0
    def getPrevNotes(self, n=1):
        if self.justLeft is None:
            self.getPrevNext()
        if self.prevchars is None:
            self.prevchars = self.frescobaldi.getPrevLine()
        if self.inMiddleOfWord:
            print 'inMiddleOfWord %s' % self.inMiddleOfWord
            lastWord = self.prevchars.split()[-1]
            numcharsleft = len(lastWord)
            print 'go left %s characters' % numcharsleft
            keystroke("{left %s}" % numcharsleft)
            self.justLeft, self.justRight = self.prevchars[
                -numcharsleft - 1], self.prevchars[-numcharsleft]
            print 'after go left: justLeft: %s, justRight: %s' % self.justLeft, self.justRight
            self.getPrevNextVariables(self, self.justLeft, self.justRight)
            self.prevchars = self.prevchars[:-numcharsleft]
            print 'prevchars after go left to beginning of note: %s' % repr(
                self.prevchars)

        print 'prevchars: %s' % repr(self.prevchars)
        wordsList, notesIndexes = analyseString(self.prevchars)
        print 'wordsList: %s, notesIndexes: %s' % (wordsList, notesIndexes)
        notesFound = len(notesIndexes)

        if notesFound <= n:
            moreLines = 5
            print 'get %s more lines' % moreLines
            prevchars = self.frescobaldi.getPrevLine(moreLines)
            if prevchars == self.prevchars:
                raise Exception(
                    "getPrevNotes, not enough notes found: %s, wanted: %s" %
                    (notesFound, n))
            print '%s more lines prev:\n%s' % (moreLines, repr(prevchars))
            self.prevchars = prevchars

            wordsList, notesIndexes = analyseString(self.prevchars)
            notesFound = len(notesIndexes)
            print '----prevchars: %s' % repr(self.prevchars)
            if notesFound < n:
                print 'notesFound: %s' % notesFound
                print 'wordsList: %s, notesIndexes: %s' % (wordsList,
                                                           notesIndexes)
                raise Exception(
                    "too little notes caught in %s lines up: %s, wanted: %s" %
                    (moreLines, notesFound, n))
        else:
            self.hasAllInfoPrev = True  ## know enough

        wordsList, notesIndexes, afterNotes, beforeNotes, beforeNoteComplete = \
                              getNotesFromWordsList(n, wordsList, notesIndexes, reverse=True)
        beforeNoteComplete = beforeNoteComplete or self.hasAllInfoPrev
        return wordsList, notesIndexes, afterNotes, beforeNotes, beforeNoteComplete
Exemplo n.º 2
0
    def getNextNotes(self, n=1):
        if self.nextchars is None:
            self.nextchars = self.frescobaldi.getNextLine()
        print 'nextchars: |%s|' % self.nextchars
        if self.justLeft is None:
            self.getPrevNext()
        if self.inMiddleOfWord:
            print 'inMiddleOfWord %s' % self.inMiddleOfWord
            if not self.prevchars:
                self.prevchars = self.frescobaldi.getPrevLine()
            lastWord = self.prevchars.split()[-1]
            numcharsleft = len(lastWord)
            print 'go left %s characters' % numcharsleft
            keystroke("{left %s}" % numcharsleft)
            self.getPrevNext()
            self.nextchars = self.frescobaldi.getNextLine()

        print 'nextchars: %s' % repr(self.nextchars)
        wordsList, notesIndexes = analyseString(self.nextchars)
        print 'wordsList: %s, notesIndexes: %s' % (wordsList, notesIndexes)
        notesFound = len(notesIndexes)

        if notesFound <= n:
            moreLines = 5
            print 'get %s more lines' % moreLines
            nextchars = self.frescobaldi.getNextLine(moreLines)
            # nextcharsplit = self.nextchars.split('\n\n') # double empty line ends the search
            # if len(nextcharsplit) > 1:
            #     self.hasAllInfoNext = True
            # self.nextchars = nextcharsplit[0]
            if nextchars == self.nextchars:
                raise Exception(
                    "getNextNotes, not enough notes found: %s, wanted: %s" %
                    (notesFound, n))
            self.nextchars = nextchars
            wordsList, notesIndexes = analyseString(self.nextchars)
            notesFound = len(notesIndexes)
            print '----nextchars: %s' % repr(self.nextchars)
            if notesFound < n:
                print 'notesFound: %s' % notesFound
                print 'wordsList: %s, notesIndexes: %s' % (wordsList,
                                                           notesIndexes)
                raise Exception(
                    "too little notes caught in %s lines down: %s, wanted: %s"
                    % (moreLines, notesFound, n))
        else:
            self.hasAllInfoNext = True
        wordsList, notesIndexes, beforeNotes, afterNotes, afterNoteComplete = \
                              getNotesFromWordsList(n, wordsList, notesIndexes)
        afterNoteComplete = afterNoteComplete or self.hasAllInfoNext
        return wordsList, notesIndexes, beforeNotes, afterNotes, afterNoteComplete
Exemplo n.º 3
0
    def tttestGetNotesFromWordsListReverse(self):
        """check the getNotesFromWordsList function

        here are the "backward" PREVIOUS note tests, with reverse == True
        See the function getNotesFromWordsList in lynote.py
        """
        # testing the beforeWord case:
        # s = ' | b8\n'
        # expWords= [' ', '|', ' ', 'b8', '\n']
        # expNotesIndexes =  [3]
        # # first redo the analyseString test:
        # wordsList, notesIndexes = lynote.analyseString(s)
        # gotWordsList = [str(a) for a in wordsList]
        # self.assertEqual(expWords, gotWordsList, 'assertion test: words of analyseString (%s) not as expected\nexpected: %s\ngot: %s'%
        #                  (s, expWords, gotWordsList))
        # self.assertEqual(expNotesIndexes, notesIndexes, 'assertion test: notesIndexes of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'%
        #                  (s, expNotesIndexes, notesIndexes))
        # # now the real test
        # maxWords = 1
        # expWords =(['b8'],)
        # expNotesIndexes = ([0],)
        # expBeforeNotes = (' | ',)
        # expAfterNotes = ('\n',)
        # expAfterNoteComplete = (False,)
        # self.doTestGetNotesFromWordsList(maxWords, wordsList, notesIndexes,
        #      expWords, expNotesIndexes, expBeforeNotes, expAfterNotes, expAfterNoteComplete, reverse=True)
        #

        # previous words test:
        expWords = ['a4', ' |\n', 'b', ' ', 'c', ' ']
        expNotesIndexes = [0, 2, 4]
        s = 'a4 |\nb c '
        # first redo the analyseString test:
        wordsList, notesIndexes = lynote.analyseString(s)
        gotWordsList = [str(a) for a in wordsList]
        self.assertEqual(
            expWords, gotWordsList,
            'assertion test: words of analyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expWords, gotWordsList))
        self.assertEqual(
            expNotesIndexes, notesIndexes,
            'assertion test: notesIndexes of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expNotesIndexes, notesIndexes))
        # now the real test
        maxWords = 3
        expWords = ['c'], ['b', ' ', 'c'], ['a4', ' |\n', 'b', ' ', 'c']
        expNotesIndexes = [0], [0, 2], [0, 2, 4]
        expBeforeNotes = ' ', ' |\n', ''
        expAfterNotes = ' ', ' ', ' '
        expAfterNoteComplete = True, True, False
        self.doTestGetNotesFromWordsList(maxWords,
                                         wordsList,
                                         notesIndexes,
                                         expWords,
                                         expNotesIndexes,
                                         expBeforeNotes,
                                         expAfterNotes,
                                         expAfterNoteComplete,
                                         reverse=True)
Exemplo n.º 4
0
    def tttestGetNotesFromWordsList(self):
        """check the getNotesFromWordsList function
        
        here are the "forward" next note tests, with reverse == False (default)
        See the function getNotesFromWordsList in lynote.py
        """

        # testing the beforeWord case:
        s = ' | b8\n'
        expWords = [' | ', 'b8', '\n']
        expNotesIndexes = [1]
        # first redo the analyseString test:
        wordsList, notesIndexes = lynote.analyseString(s)
        gotWordsList = [str(a) for a in wordsList]
        self.assertEqual(
            expWords, gotWordsList,
            'assertion test: words of analyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expWords, gotWordsList))
        self.assertEqual(
            expNotesIndexes, notesIndexes,
            'assertion test: notesIndexes of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expNotesIndexes, notesIndexes))
        # now the real test
        maxWords = 1
        expWords = (['b8'], )
        expNotesIndexes = ([0], )
        expBeforeNotes = (' | ', )
        expAfterNotes = ('\n', )
        expAfterNoteComplete = (False, )
        self.doTestGetNotesFromWordsList(maxWords, wordsList, notesIndexes,
                                         expWords, expNotesIndexes,
                                         expBeforeNotes, expAfterNotes,
                                         expAfterNoteComplete)

        expWords = ['a4', ' ', 'b', ' ', 'c']
        expNotesIndexes = [0, 2, 4]
        s = 'a4 b c'
        # first redo the analyseString test:
        wordsList, notesIndexes = lynote.analyseString(s)
        gotWordsList = [str(a) for a in wordsList]
        self.assertEqual(
            expWords, gotWordsList,
            'assertion test: words of analyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expWords, gotWordsList))
        self.assertEqual(
            expNotesIndexes, notesIndexes,
            'assertion test: notesIndexes of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expNotesIndexes, notesIndexes))
        # now the real test
        maxWords = 3
        expWords = ['a4'], ['a4', ' ', 'b'], ['a4', ' ', 'b', ' ', 'c']
        expNotesIndexes = [0], [0, 2], [0, 2, 4]
        expBeforeNotes = '', '', ''
        expAfterNotes = ' ', ' ', ''
        expAfterNoteComplete = True, True, False
        self.doTestGetNotesFromWordsList(maxWords, wordsList, notesIndexes,
                                         expWords, expNotesIndexes,
                                         expBeforeNotes, expAfterNotes,
                                         expAfterNoteComplete)

        # lot of text after last note:
        expWords = [
            'f', '  ', 'b8', '\n\\time 3/4\n', 'g4', ' ', 'a', '  ', 'b', ' ',
            'c', ' \\bar "||"\n', 'c1'
        ]
        expNotesIndexes = [0, 2, 4, 6, 8, 10, 12]
        s = 'f  b8\n\\time 3/4\ng4 a  b c \\bar "||"\nc1'

        wordsList, notesIndexes = lynote.analyseString(s)
        gotWordsList = [str(n) for n in wordsList]
        self.assertEqual(
            expWords, gotWordsList,
            'assertion test: wordsList of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expWords, gotWordsList))
        self.assertEqual(
            expNotesIndexes, notesIndexes,
            'assertion test: notesIndexes of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expNotesIndexes, notesIndexes))

        maxWords = 4
        expWords = (['f'], ['f', '  ',
                            'b8'], ['f', '  ', 'b8', '\n\\time 3/4\n', 'g4'],
                    ['f', '  ', 'b8', '\n\\time 3/4\n', 'g4', ' ', 'a'])
        expNotesIndexes = [0], [0, 2], [0, 2, 4], [0, 2, 4, 6]
        expBeforeNotes = '', '', '', ''
        expAfterNotes = '  ', '\n\\time 3/4\n', ' ', '  '
        expAfterNoteComplete = True, True, True, True
        self.doTestGetNotesFromWordsList(maxWords, wordsList, notesIndexes,
                                         expWords, expNotesIndexes,
                                         expBeforeNotes, expAfterNotes,
                                         expAfterNoteComplete)
Exemplo n.º 5
0
    def testAnalyseString(self):
        """check the analyseString function"""

        expWords = ['a4', ' ', 'b', ' ', 'c']
        expNotesIndexes = [0, 2, 4]
        s = 'a4 b c'
        words, noteIndexes = lynote.analyseString(s)
        words = [str(n) for n in words]
        self.assertEqual(
            expWords, words,
            'words of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expWords, words))
        self.assertEqual(
            expNotesIndexes, noteIndexes,
            'noteIndexes of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expNotesIndexes, noteIndexes))

        # testing the beforeWord case:
        s = ' | b8\n'
        expWords = [' | ', 'b8', '\n']
        expNotesIndexes = [1]
        words, noteIndexes = lynote.analyseString(s)
        words = [str(n) for n in words]
        self.assertEqual(
            expWords, words,
            'words of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expWords, words))
        self.assertEqual(
            expNotesIndexes, noteIndexes,
            'noteIndexes of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expNotesIndexes, noteIndexes))

        # testing the beforeWord case:
        s = 'c4\n\n\n\n | b'
        expWords = ['c4', '\n\n\n\n | ', 'b']
        expNotesIndexes = [0, 2]
        words, noteIndexes = lynote.analyseString(s)
        words = [str(n) for n in words]
        self.assertEqual(
            expWords, words,
            'words of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expWords, words))
        self.assertEqual(
            expNotesIndexes, noteIndexes,
            'noteIndexes of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expNotesIndexes, noteIndexes))

        # lot of text after last note:
        expWords = [
            'ais', '  ', 'b8', '\n\\time 3/4\n', 'g4', ' ', 'a', '  ', 'b',
            ' ', 'c', ' \\bar "||"\n', 'c1'
        ]
        expNotesIndexes = [0, 2, 4, 6, 8, 10, 12]
        s = 'ais  b8\n\\time 3/4\ng4 a  b c \\bar "||"\nc1'
        words, noteIndexes = lynote.analyseString(s)
        words = [str(n) for n in words]
        self.assertEqual(
            expWords, words,
            'words of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expWords, words))
        self.assertEqual(
            expNotesIndexes, noteIndexes,
            'noteIndexes of testAnalyseString (%s) not as expected\nexpected: %s\ngot: %s'
            % (s, expNotesIndexes, noteIndexes))