示例#1
0
 def testReadSectionEnd(self):
     data = """START_MEASURE
                 START_MEASURE_COUNT
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                 END_MEASURE_COUNT
                 STARTBARLINE 1
                 ENDBARLINE 9
                 REPEAT_COUNT 6
                 SIMILE 0
                 SIMINDEX 0
               END_MEASURE"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv1.MeasureStructureV1().read(iterator)
     self.assert_(measure.isSectionEnd())
示例#2
0
 def testRead(self):
     data = """SCORE_METADATA
                 TITLE Song
                 ARTIST xxx
                 ARTISTVISIBLE False
                 CREATOR zzz
                 CREATORVISIBLE False
                 BPM 200
                 BPMVISIBLE False
                 WIDTH 100
                 KITDATAVISIBLE False
                 METADATAVISIBLE False
                 BEATCOUNTVISIBLE False
                 EMPTYLINESVISIBLE False
                 MEASURECOUNTSVISIBLE True
               END_SCORE_METADATA"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     meta = ScoreMetaData.ScoreMetaData()
     meta.load(iterator)
     self.assertEqual(meta.title, "Song")
     self.assertEqual(meta.artist, "xxx")
     self.assertEqual(meta.artistVisible, False)
     self.assertEqual(meta.creator, "zzz")
     self.assertEqual(meta.creatorVisible, False)
     self.assertEqual(meta.bpm, 200)
     self.assertEqual(meta.bpmVisible, False)
     self.assertEqual(meta.width, 100)
     self.assertEqual(meta.kitDataVisible, False)
     self.assertEqual(meta.metadataVisible, False)
     self.assertEqual(meta.beatCountVisible, False)
     self.assertEqual(meta.emptyLinesVisible, False)
     self.assertEqual(meta.measureCountsVisible, True)
示例#3
0
 def testReadLineBreak(self):
     data = """
     START_BAR 15
       COUNT_INFO_START
         BEAT_START
           COUNT |^+a|
         BEAT_END
         BEAT_START
           COUNT |^+a|
         BEAT_END
         BEAT_START
           COUNT |^ea+ea|
         BEAT_END
         BEAT_START
           COUNT |^+a|
         BEAT_END
       COUNT_INFO_END
       BARLINE NORMAL_BAR,NO_BAR
       BARLINE NORMAL_BAR,LINE_BREAK,NO_BAR
     END_BAR
     """
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv0.MeasureStructureV0().read(iterator)
     self.assert_(measure.isLineBreak())
示例#4
0
 def testReadSectionEnd(self):
     data = """
     START_BAR 8
       COUNT_INFO_START
         REPEAT_BEATS 4
         BEAT_START
           COUNT |^+|
         BEAT_END
       COUNT_INFO_END
       BARLINE NORMAL_BAR,NO_BAR
       NOTE 0,1,o
       NOTE 0,7,x
       NOTE 1,1,o
       NOTE 1,7,x
       NOTE 2,3,o
       NOTE 2,7,x
       NOTE 3,7,x
       NOTE 4,1,o
       NOTE 4,7,x
       NOTE 5,1,o
       NOTE 5,7,x
       NOTE 6,8,x
       NOTE 6,3,o
       BARLINE NORMAL_BAR,NO_BAR,SECTION_END
     END_BAR
     """
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = Measure()
     measure.read(iterator)
     self.assert_(measure.isSectionEnd())
示例#5
0
 def read(handle):
     # Check the file format version
     handle, handleCopy = itertools.tee(handle)
     try:
         firstline = handleCopy.next()
     except StopIteration:
         raise NoContent()
     del handleCopy
     scoreIterator = fileUtils.dbFileIterator(handle)
     if firstline.startswith(DBConstants.DB_FILE_FORMAT_STR):
         fileVersion = firstline.split()
         try:
             if len(fileVersion) >= 2:
                 fileVersion = int(fileVersion[1])
         except (TypeError, ValueError):
             fileVersion = DBConstants.DBFF_0
         scoreIterator.next()
     else:
         fileVersion = DBConstants.DBFF_0
     if fileVersion > DBConstants.CURRENT_FILE_FORMAT:
         raise DBVersionError(scoreIterator)
     fileStructure = _FS_MAP[fileVersion]()
     score = fileStructure.read(scoreIterator)
     score.fileFormat = fileVersion
     return score
示例#6
0
 def testReadFull(self):
     handle = StringIO("""BEAT_START
     COUNT |^e+a|
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     beat = Beat.Beat.read(iterator)
     self.assertEqual("".join(beat.count(1)), "1e+a")
示例#7
0
 def testReadSimile(self):
     data = """START_MEASURE
                 START_MEASURE_COUNT
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                 END_MEASURE_COUNT
                 STARTBARLINE 1
                 ENDBARLINE 9
                 REPEAT_COUNT 6
                 SIMILE 2
                 SIMINDEX 1
               END_MEASURE"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv1.MeasureStructureV1().read(iterator)
     self.assertEqual(measure.simileDistance, 2)
     self.assertEqual(measure.simileIndex, 1)
示例#8
0
 def testReadRepeatBar(self):
     data = """START_MEASURE
                 START_MEASURE_COUNT
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                 END_MEASURE_COUNT
                 STARTBARLINE 3
                 ENDBARLINE 5
                 REPEAT_COUNT 6
               END_MEASURE"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv1.MeasureStructureV1().read(iterator)
     self.assertEqual(measure.repeatCount, 6)
     self.assert_(measure.isRepeatStart())
     self.assert_(measure.isRepeatEnd())
     self.assertFalse(measure.isSectionEnd())
     self.assertFalse(measure.isLineBreak())
     self.assertEqual(measure.newBpm, 0)
示例#9
0
 def testReadSimple(self):
     data = """
     START_DRUM
       NAME test
       ABBR td
       DEFAULT_HEAD x
       LOCKED True
       HEADLIST x
       START_NOTEHEAD
         MIDINOTE 71
         MIDIVOLUME 96
         EFFECT normal
         NOTATIONHEAD default
         NOTATIONLINE 0
         NOTATIONEFFECT none
         STEM 0
         SHORTCUT y
       END_NOTEHEAD
     END_DRUM
     """
     iterator = fileUtils.dbFileIterator(StringIO(data))
     drum = dbfsv1.DrumStructureV1().read(iterator)
     self.assertEqual(drum.name, 'test')
     self.assertEqual(drum.abbr, 'td')
     self.assert_(drum.locked)
     self.assertEqual(drum.head, 'x')
     self.assertEqual(len(drum), 1)
     self.assertEqual(drum[0], 'x')
示例#10
0
 def testReadBadCount(self):
     handle = StringIO("""BEAT_START
     COUNT |^e+d|
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.BadCount, dbfsv1.BeatStructureV1().read,
                       iterator)
示例#11
0
 def testReadAlterate(self):
     data = """
     START_BAR 8
       COUNT_INFO_START
         REPEAT_BEATS 4
         BEAT_START
           COUNT |^+|
         BEAT_END
       COUNT_INFO_END
       BARLINE NORMAL_BAR,NO_BAR
       NOTE 0,6,x
       NOTE 1,1,o
       NOTE 1,6,x
       NOTE 2,3,o
       NOTE 2,6,x
       NOTE 3,6,x
       NOTE 4,1,o
       NOTE 4,6,x
       NOTE 5,1,o
       NOTE 5,6,x
       NOTE 6,8,x
       NOTE 6,3,o
       BARLINE NORMAL_BAR,NO_BAR,SECTION_END,REPEAT_END
       REPEAT_COUNT 2
       ALTERNATE 2.
     END_BAR
     """
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = Measure()
     measure.read(iterator)
     self.assert_(measure.isRepeatEnd())
     self.assertEqual(measure.alternateText, "2.")
示例#12
0
 def testReadLineBreak(self):
     data = """
     START_BAR 15
       COUNT_INFO_START
         BEAT_START
           COUNT |^+a|
         BEAT_END
         BEAT_START
           COUNT |^+a|
         BEAT_END
         BEAT_START
           COUNT |^ea+ea|
         BEAT_END
         BEAT_START
           COUNT |^+a|
         BEAT_END
       COUNT_INFO_END
       BARLINE NORMAL_BAR,NO_BAR
       NOTE 10,1,o
       NOTE 11,1,o
       NOTE 12,1,O
       BARLINE NORMAL_BAR,LINE_BREAK,NO_BAR
     END_BAR
     """
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = Measure()
     measure.read(iterator)
     self.assert_(measure.isLineBreak())
示例#13
0
 def testReadBadLine(self):
     handle = StringIO("""BEAT_START
     COUNT |^e+a|
     BAD_LINE xxx
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.UnrecognisedLine, Beat.Beat.read, iterator)
示例#14
0
 def testReadBadTicks(self):
     handle = StringIO("""BEAT_START
     NUM_TICKS x
     COUNT |^e+a|
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.InvalidInteger, Beat.Beat.read, iterator)
示例#15
0
 def testReadSimile(self):
     data = """START_MEASURE
                 START_MEASURE_COUNT
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                 END_MEASURE_COUNT
                 STARTBARLINE 1
                 ENDBARLINE 9
                 REPEAT_COUNT 6
                 SIMILE 2
                 SIMINDEX 1
               END_MEASURE"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv1.MeasureStructureV1().read(iterator)
     self.assertEqual(measure.simileDistance, 2)
     self.assertEqual(measure.simileIndex, 1)
示例#16
0
 def testReadSimple(self):
     data = """
     START_DRUM
       NAME test
       ABBR td
       DEFAULT_HEAD x
       LOCKED True
       HEADLIST x
       START_NOTEHEAD
         MIDINOTE 71
         MIDIVOLUME 96
         EFFECT normal
         NOTATIONHEAD default
         NOTATIONLINE 0
         NOTATIONEFFECT none
         STEM 0
         SHORTCUT y
       END_NOTEHEAD
     END_DRUM
     """
     iterator = fileUtils.dbFileIterator(StringIO(data))
     drum = dbfsv1.DrumStructureV1().read(iterator)
     self.assertEqual(drum.name, 'test')
     self.assertEqual(drum.abbr, 'td')
     self.assert_(drum.locked)
     self.assertEqual(drum.head, 'x')
     self.assertEqual(len(drum), 1)
     self.assertEqual(drum[0], 'x')
示例#17
0
 def testReadSectionEnd(self):
     data = """START_MEASURE
                 START_MEASURE_COUNT
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                 END_MEASURE_COUNT
                 STARTBARLINE 1
                 ENDBARLINE 9
                 REPEAT_COUNT 6
                 SIMILE 0
                 SIMINDEX 0
               END_MEASURE"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv1.MeasureStructureV1().read(iterator)
     self.assert_(measure.isSectionEnd())
示例#18
0
 def testReadLineBreak(self):
     data = """START_MEASURE
                 START_MEASURE_COUNT
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                 END_MEASURE_COUNT
                 STARTBARLINE 1
                 ENDBARLINE 17
                 REPEAT_COUNT 6
               END_MEASURE"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv1.MeasureStructureV1().read(iterator)
     self.assert_(measure.isLineBreak())
示例#19
0
 def testReadAlternate(self):
     data = """
     START_MEASURE
       START_MEASURE_COUNT
         BEAT_START
           NUM_TICKS 4
           COUNT |^+|
         BEAT_END
         BEAT_START
           NUM_TICKS 4
           COUNT |^+|
         BEAT_END
         BEAT_START
           NUM_TICKS 4
           COUNT |^+|
         BEAT_END
         BEAT_START
           NUM_TICKS 4
           COUNT |^+|
         BEAT_END
       END_MEASURE_COUNT
       STARTBARLINE 1
       ENDBARLINE 1
       REPEAT_COUNT 2
       ALTERNATE 2.
     END_MEASURE
     """
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv1.MeasureStructureV1().read(iterator)
     self.assertEqual(measure.alternateText, "2.")
示例#20
0
 def testRead(self):
     data = """SCORE_METADATA
                 TITLE Song
                 ARTIST xxx
                 ARTISTVISIBLE False
                 CREATOR zzz
                 CREATORVISIBLE False
                 BPM 200
                 BPMVISIBLE False
                 WIDTH 100
                 KITDATAVISIBLE False
                 METADATAVISIBLE False
                 BEATCOUNTVISIBLE False
                 EMPTYLINESVISIBLE False
                 MEASURECOUNTSVISIBLE True
               END_SCORE_METADATA"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     meta = ScoreMetaData.ScoreMetaData()
     meta.load(iterator)
     self.assertEqual(meta.title, "Song")
     self.assertEqual(meta.artist, "xxx")
     self.assertEqual(meta.artistVisible, False)
     self.assertEqual(meta.creator, "zzz")
     self.assertEqual(meta.creatorVisible, False)
     self.assertEqual(meta.bpm, 200)
     self.assertEqual(meta.bpmVisible, False)
     self.assertEqual(meta.width, 100)
     self.assertEqual(meta.kitDataVisible, False)
     self.assertEqual(meta.metadataVisible, False)
     self.assertEqual(meta.beatCountVisible, False)
     self.assertEqual(meta.emptyLinesVisible, False)
     self.assertEqual(meta.measureCountsVisible, True)
示例#21
0
 def testReadSimpleDefault(self):
     data = """START_DEFAULT_MEASURE_COUNT
                   BEAT_START
                       NUM_TICKS 4
                       COUNT |^e+a|
                   BEAT_END
                   BEAT_START
                       NUM_TICKS 4
                       COUNT |^e+a|
                   BEAT_END
                   BEAT_START
                       NUM_TICKS 4
                       COUNT |^e+a|
                   BEAT_END
                   BEAT_START
                       NUM_TICKS 4
                       COUNT |^e+a|
                   BEAT_END
               END_DEFAULT_MEASURE_COUNT"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     count = dbfsv1.DefaultMeasureCountStructureV1().read(iterator)
     self.assert_(count.isSimpleCount())
     self.assertEqual(len(count), 16)
     self.assertEqual(count.countString(), "1e+a2e+a3e+a4e+a")
示例#22
0
 def testReadBadLine(self):
     handle = StringIO("""BEAT_START
     COUNT |^e+a|
     BAD_LINE xxx
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.UnrecognisedLine, Beat.Beat.read, iterator)
示例#23
0
 def testReadFull(self):
     handle = StringIO("""BEAT_START
     COUNT |^e+a|
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     beat = Beat.Beat.read(iterator)
     self.assertEqual("".join(beat.count(1)), "1e+a")
示例#24
0
 def testReadLineBreak(self):
     data = """START_MEASURE
                 START_MEASURE_COUNT
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                 END_MEASURE_COUNT
                 STARTBARLINE 1
                 ENDBARLINE 17
                 REPEAT_COUNT 6
               END_MEASURE"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv1.MeasureStructureV1().read(iterator)
     self.assert_(measure.isLineBreak())
示例#25
0
 def testReadBadTicks(self):
     handle = StringIO("""BEAT_START
     NUM_TICKS x
     COUNT |^e+a|
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.InvalidInteger, Beat.Beat.read, iterator)
示例#26
0
 def testReadAlternate(self):
     data = """
     START_MEASURE
       START_MEASURE_COUNT
         BEAT_START
           NUM_TICKS 4
           COUNT |^+|
         BEAT_END
         BEAT_START
           NUM_TICKS 4
           COUNT |^+|
         BEAT_END
         BEAT_START
           NUM_TICKS 4
           COUNT |^+|
         BEAT_END
         BEAT_START
           NUM_TICKS 4
           COUNT |^+|
         BEAT_END
       END_MEASURE_COUNT
       STARTBARLINE 1
       ENDBARLINE 1
       REPEAT_COUNT 2
       ALTERNATE 2.
     END_MEASURE
     """
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv1.MeasureStructureV1().read(iterator)
     self.assertEqual(measure.alternateText, "2.")
示例#27
0
 def testReadRepeatBar(self):
     data = """START_MEASURE
                 START_MEASURE_COUNT
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                     BEAT_START
                       NUM_TICKS 2
                       COUNT |^+|
                     BEAT_END
                 END_MEASURE_COUNT
                 STARTBARLINE 3
                 ENDBARLINE 5
                 REPEAT_COUNT 6
               END_MEASURE"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = dbfsv1.MeasureStructureV1().read(iterator)
     self.assertEqual(measure.repeatCount, 6)
     self.assert_(measure.isRepeatStart())
     self.assert_(measure.isRepeatEnd())
     self.assertFalse(measure.isSectionEnd())
     self.assertFalse(measure.isLineBreak())
     self.assertEqual(measure.newBpm, 0)
示例#28
0
 def testReadBadCount(self):
     handle = StringIO("""BEAT_START
     COUNT |^e+d|
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.BadCount,
                       dbfsv0.BeatStructureV0().read, iterator)
示例#29
0
 def testReadSimpleDefault(self):
     data = """START_DEFAULT_MEASURE_COUNT
                   BEAT_START
                       NUM_TICKS 4
                       COUNT |^e+a|
                   BEAT_END
                   BEAT_START
                       NUM_TICKS 4
                       COUNT |^e+a|
                   BEAT_END
                   BEAT_START
                       NUM_TICKS 4
                       COUNT |^e+a|
                   BEAT_END
                   BEAT_START
                       NUM_TICKS 4
                       COUNT |^e+a|
                   BEAT_END
               END_DEFAULT_MEASURE_COUNT"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     count = dbfsv1.DefaultMeasureCountStructureV1().read(iterator)
     self.assert_(count.isSimpleCount())
     self.assertEqual(len(count), 16)
     self.assertEqual(count.countString(), "1e+a2e+a3e+a4e+a")
示例#30
0
 def testReadPartial(self):
     handle = StringIO("""BEAT_START
     NUM_TICKS 2
     COUNT |^e+a|
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     beat = dbfsv1.BeatStructureV1().read(iterator)
     self.assertEqual("".join(beat.count(1)), "1e")
示例#31
0
 def testReadPartial(self):
     handle = StringIO("""BEAT_START
     NUM_TICKS 2
     COUNT |^e+a|
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     beat = dbfsv0.BeatStructureV0().read(iterator)
     self.assertEqual("".join(beat.count(1)), "1e")
示例#32
0
 def testReadBadNegativeTicks(self):
     handle = StringIO("""BEAT_START
     NUM_TICKS -1
     COUNT |^e+a|
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.InvalidPositiveInteger,
                       dbfsv0.BeatStructureV0().read, iterator)
示例#33
0
 def testReadBadLine(self):
     handle = StringIO("""BEAT_START
     NUM_TICKS 4
     COUNT |^e+a|
     BAD_LINE xxx
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.UnrecognisedLine,
                       dbfsv1.BeatStructureV1().read, iterator)
示例#34
0
 def testReadBadNegativeTicks(self):
     handle = StringIO("""BEAT_START
     NUM_TICKS -1
     COUNT |^e+a|
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.InvalidPositiveInteger,
                       dbfsv1.BeatStructureV1().read,
                       iterator)
示例#35
0
 def testReadBadLine(self):
     handle = StringIO("""BEAT_START
     NUM_TICKS 4
     COUNT |^e+a|
     BAD_LINE xxx
     BEAT_END""")
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.UnrecognisedLine,
                       dbfsv1.BeatStructureV1().read, iterator)
示例#36
0
 def testRepeatBeats(self):
     data = """START_MEASURE_COUNT
           REPEAT_BEATS 3
           BEAT_START
               COUNT |^e+a|
           BEAT_END
       END_MEASURE_COUNT"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.UnrecognisedLine,
                       dbfsv1.MeasureCountStructureV1().read, iterator)
示例#37
0
 def testRepeatBeats(self):
     data = """START_MEASURE_COUNT
           REPEAT_BEATS 3
           BEAT_START
               COUNT |^e+a|
           BEAT_END
       END_MEASURE_COUNT"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.UnrecognisedLine,
                       dbfsv1.MeasureCountStructureV1().read, iterator)
示例#38
0
 def testBadLine(self):
     data = """COUNT_INFO_START
           REPEAT_BEATS 4
           UNRECOGNISED LINE
           BEAT_START
               COUNT |^e+a|
           BEAT_END
       COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.UnrecognisedLine,
                       dbfsv0.MeasureCountStructureV0().read, iterator)
示例#39
0
 def testIterate(self):
     mockfile = """firstline
     secondline hasdata
     
     thirdline comes after a blank
     """
     mockfile = StringIO(mockfile)
     iterator = fileUtils.dbFileIterator(mockfile)
     lines = list(iterator)
     self.assertEqual(lines, [("FIRSTLINE", None),
                              ("SECONDLINE", "hasdata"),
                              ("THIRDLINE", "comes after a blank")])
示例#40
0
 def testNegativeBeatCount(self):
     data = """COUNT_INFO_START
           REPEAT_BEATS -1
           UNRECOGNISED LINE
           BEAT_START
               COUNT |^e+a|
           BEAT_END
       COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.InvalidPositiveInteger,
                       dbfsv0.MeasureCountStructureV0().read, iterator)
示例#41
0
 def testNegativeBeatCount(self):
     data = """COUNT_INFO_START
           REPEAT_BEATS -1
           UNRECOGNISED LINE
           BEAT_START
               COUNT |^e+a|
           BEAT_END
       COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     count = MeasureCount.MeasureCount()
     self.assertRaises(DBErrors.InvalidPositiveInteger, count.read, iterator)
示例#42
0
 def testBadBeatCount(self):
     data = """COUNT_INFO_START
           REPEAT_BEATS xxx
           UNRECOGNISED LINE
           BEAT_START
               COUNT |^e+a|
           BEAT_END
       COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     count = MeasureCount.MeasureCount()
     self.assertRaises(DBErrors.InvalidInteger, count.read, iterator)
示例#43
0
 def testBadLine(self):
     data = """COUNT_INFO_START
           REPEAT_BEATS 4
           UNRECOGNISED LINE
           BEAT_START
               COUNT |^e+a|
           BEAT_END
       COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     count = MeasureCount.MeasureCount()
     self.assertRaises(DBErrors.UnrecognisedLine, count.read, iterator)
示例#44
0
 def testBadBeatCount(self):
     data = """COUNT_INFO_START
           REPEAT_BEATS xxx
           UNRECOGNISED LINE
           BEAT_START
               COUNT |^e+a|
           BEAT_END
       COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     self.assertRaises(DBErrors.InvalidInteger,
                       dbfsv0.MeasureCountStructureV0().read, iterator)
示例#45
0
 def getKit(self):
     item = self.defaultKitList.currentItem()
     isUser = item.data(_IS_USER_KIT).toBool()
     kitName = unicode(item.text())
     if isUser:
         kitString = str(self._settings.value(kitName).toString())
         handle = StringIO(kitString)
         dbfile = fileUtils.dbFileIterator(handle)
         kit = DrumKit.DrumKit()
         kit.read(dbfile)
         return kit
     else:
         return DrumKit.getNamedDefaultKit(kitName)
示例#46
0
 def getKit(self):
     item = self.defaultKitList.currentItem()
     isUser = item.data(_IS_USER_KIT).toBool()
     kitName = unicode(item.text())
     if isUser:
         kitString = str(self._settings.value(kitName).toString())
         handle = StringIO(kitString)
         dbfile = fileUtils.dbFileIterator(handle)
         kit = DrumKit.DrumKit()
         kit.read(dbfile)
         return kit
     else:
         return DrumKit.getNamedDefaultKit(kitName)
示例#47
0
 def testIterate(self):
     mockfile = """firstline
     secondline hasdata
     
     thirdline comes after a blank
     """
     mockfile = StringIO(mockfile)
     iterator = fileUtils.dbFileIterator(mockfile)
     lines = list(iterator)
     self.assertEqual(lines,
                      [("FIRSTLINE", None),
                       ("SECONDLINE", "hasdata"),
                       ("THIRDLINE", "comes after a blank")])
示例#48
0
 def testReadSimpleDefault(self):
     data = """DEFAULT_COUNT_INFO_START
                   REPEAT_BEATS 4
                   BEAT_START
                       COUNT |^e+a|
                   BEAT_END
               COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     count = MeasureCount.MeasureCount()
     count.read(iterator, True)
     self.assert_(count.isSimpleCount())
     self.assertEqual(len(count), 16)
示例#49
0
 def testReadSimpleDefault(self):
     data = """DEFAULT_COUNT_INFO_START
                   REPEAT_BEATS 4
                   BEAT_START
                       COUNT |^e+a|
                   BEAT_END
               COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     count = dbfsv0.MeasureCountStructureV0(startTag = "DEFAULT_COUNT_INFO_START").read(iterator)
     self.assert_(count.isSimpleCount())
     self.assertEqual(len(count), 16)
     self.assertEqual(count.countString(), "1e+a2e+a3e+a4e+a")
示例#50
0
 def testReadSimple(self):
     data = """COUNT_INFO_START
                   REPEAT_BEATS 4
                   BEAT_START
                       COUNT |^e+a|
                   BEAT_END
               COUNT_INFO_END"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     count = dbfsv0.MeasureCountStructureV0().read(iterator)
     self.assert_(count.isSimpleCount())
     self.assertEqual(len(count), 16)
     self.assertEqual(count.countString(), "1e+a2e+a3e+a4e+a")
示例#51
0
 def testReadExtraHeads(self):
     data = """
     START_DRUM
       NAME test
       ABBR td
       DEFAULT_HEAD x
       LOCKED False
       HEADLIST xyz
       START_NOTEHEAD
         MIDINOTE 71
         MIDIVOLUME 96
         EFFECT normal
         NOTATIONHEAD default
         NOTATIONLINE 0
         NOTATIONEFFECT none
         STEM 0
         SHORTCUT y
       END_NOTEHEAD
       START_NOTEHEAD
         MIDINOTE 100
         MIDIVOLUME 96
         EFFECT normal
         NOTATIONHEAD default
         NOTATIONLINE 0
         NOTATIONEFFECT none
         STEM 0
         SHORTCUT a
       END_NOTEHEAD
       START_NOTEHEAD
         MIDINOTE 72
         MIDIVOLUME 100
         EFFECT ghost
         NOTATIONHEAD cross
         NOTATIONLINE 1
         NOTATIONEFFECT choke
         STEM 1
         SHORTCUT c
       END_NOTEHEAD
     END_DRUM
     """
     iterator = fileUtils.dbFileIterator(StringIO(data))
     drum = dbfsv1.DrumStructureV1().read(iterator)
     self.assertEqual(drum.name, 'test')
     self.assertEqual(drum.abbr, 'td')
     self.assertFalse(drum.locked)
     self.assertEqual(drum.head, 'x')
     self.assertEqual(len(drum), 3)
     self.assertEqual(drum[0], 'x')
     self.assertEqual(drum[1], 'y')
     self.assertEqual(drum[2], 'z')
示例#52
0
 def getValues(self):
     mc = self.measureTabs.getCounter()
     kitName = unicode(self.kitCombobox.currentText())
     kitIndex = self.kitCombobox.currentIndex()
     isUserKit = self.kitCombobox.itemData(kitIndex).toBool()
     if isUserKit:
         kitString = str(self._settings.value(kitName).toString())
         handle = StringIO(kitString)
         dbfile = fileUtils.dbFileIterator(handle)
         kit = DrumKit.DrumKit()
         kit.read(dbfile)
     else:
         kit = DrumKit.getNamedDefaultKit(kitName)
     return (self.numMeasuresSpinBox.value(), mc, kit)
示例#53
0
 def testRead_NoNoteHeads(self):
     kitData = """KIT_START
     DRUM Snare,Sn,o,True
     DRUM Kick,Bd,o,True
     KIT_END
     """
     handle = StringIO(kitData)
     iterator = fileUtils.dbFileIterator(handle)
     kit = dbfsv0.DrumKitStructureV0().read(iterator)
     self.assertEqual(len(kit), 2)
     self.assertEqual(kit[0].name, "Snare")
     self.assertEqual(len(kit[0]), 6)
     self.assertEqual(kit[1].name, "Kick")
     self.assertEqual(len(kit[1]), 4)
示例#54
0
 def testReadExtraHeads(self):
     data = """
     START_DRUM
       NAME test
       ABBR td
       DEFAULT_HEAD x
       LOCKED False
       HEADLIST xyz
       START_NOTEHEAD
         MIDINOTE 71
         MIDIVOLUME 96
         EFFECT normal
         NOTATIONHEAD default
         NOTATIONLINE 0
         NOTATIONEFFECT none
         STEM 0
         SHORTCUT y
       END_NOTEHEAD
       START_NOTEHEAD
         MIDINOTE 100
         MIDIVOLUME 96
         EFFECT normal
         NOTATIONHEAD default
         NOTATIONLINE 0
         NOTATIONEFFECT none
         STEM 0
         SHORTCUT a
       END_NOTEHEAD
       START_NOTEHEAD
         MIDINOTE 72
         MIDIVOLUME 100
         EFFECT ghost
         NOTATIONHEAD cross
         NOTATIONLINE 1
         NOTATIONEFFECT choke
         STEM 1
         SHORTCUT c
       END_NOTEHEAD
     END_DRUM
     """
     iterator = fileUtils.dbFileIterator(StringIO(data))
     drum = dbfsv1.DrumStructureV1().read(iterator)
     self.assertEqual(drum.name, 'test')
     self.assertEqual(drum.abbr, 'td')
     self.assertFalse(drum.locked)
     self.assertEqual(drum.head, 'x')
     self.assertEqual(len(drum), 3)
     self.assertEqual(drum[0], 'x')
     self.assertEqual(drum[1], 'y')
     self.assertEqual(drum[2], 'z')
示例#55
0
 def getValues(self):
     mc = self.measureTabs.getCounter()
     kitName = unicode(self.kitCombobox.currentText())
     kitIndex = self.kitCombobox.currentIndex()
     isUserKit = self.kitCombobox.itemData(kitIndex).toBool()
     if isUserKit:
         kitString = str(self._settings.value(kitName).toString())
         handle = StringIO(kitString)
         dbfile = fileUtils.dbFileIterator(handle)
         kit = DrumKit.DrumKit()
         kit.read(dbfile)
     else:
         kit = DrumKit.getNamedDefaultKit(kitName)
     return (self.numMeasuresSpinBox.value(), mc, kit)
示例#56
0
 def testRead_NoNoteHeads(self):
     kitData = """KIT_START
     DRUM Snare,Sn,o,True
     DRUM Kick,Bd,o,True
     KIT_END
     """
     handle = StringIO(kitData)
     iterator = fileUtils.dbFileIterator(handle)
     kit = dbfsv0.DrumKitStructureV0().read(iterator)
     self.assertEqual(len(kit), 2)
     self.assertEqual(kit[0].name, "Snare")
     self.assertEqual(len(kit[0]), 6)
     self.assertEqual(kit[1].name, "Kick")
     self.assertEqual(len(kit[1]), 4)
示例#57
0
 def testReadMeasure(self):
     data = """START_BAR 12
               COUNT_INFO_START
                 REPEAT_BEATS 4
                 BEAT_START
                   COUNT |^+|
                 BEAT_END
               COUNT_INFO_END
               BARLINE NORMAL_BAR,NO_BAR
               NOTE 0,1,o
               NOTE 0,2,o
               NOTE 1,2,o
               NOTE 2,2,o
               NOTE 2,3,o
               NOTE 3,2,o
               NOTE 3,3,o
               NOTE 4,1,o
               NOTE 4,2,o
               NOTE 5,2,o
               NOTE 6,2,o
               NOTE 6,3,o
               NOTE 7,2,o
               BARLINE NORMAL_BAR,NO_BAR
             END_BAR"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = Measure()
     measure.read(iterator)
     self.assertEqual(len(measure), 8)
     self.assertEqual(measure.numNotes(), 13)
     self.assertEqual(measure.noteAt(0, 1), "o")
     self.assertEqual(measure.noteAt(0, 2), "o")
     self.assertEqual(measure.noteAt(1, 2), "o")
     self.assertEqual(measure.noteAt(2, 2), "o")
     self.assertEqual(measure.noteAt(2, 3), "o")
     self.assertEqual(measure.noteAt(3, 2), "o")
     self.assertEqual(measure.noteAt(3, 3), "o")
     self.assertEqual(measure.noteAt(4, 1), "o")
     self.assertEqual(measure.noteAt(4, 2), "o")
     self.assertEqual(measure.noteAt(5, 2), "o")
     self.assertEqual(measure.noteAt(6, 2), "o")
     self.assertEqual(measure.noteAt(6, 3), "o")
     self.assertEqual(measure.noteAt(7, 2), "o")
     self.assertFalse(measure.isRepeatStart())
     self.assertFalse(measure.isRepeatEnd())
     self.assertFalse(measure.isSectionEnd())
     self.assertFalse(measure.isLineBreak())
     self.assertEqual(measure.alternateText, None)
     self.assertEqual(measure.repeatCount, 1)