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())
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)
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())
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())
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
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")
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)
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)
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')
def testReadBadCount(self): handle = StringIO("""BEAT_START COUNT |^e+d| BEAT_END""") iterator = fileUtils.dbFileIterator(handle) self.assertRaises(DBErrors.BadCount, dbfsv1.BeatStructureV1().read, iterator)
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.")
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())
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)
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)
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())
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.")
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")
def testReadBadCount(self): handle = StringIO("""BEAT_START COUNT |^e+d| BEAT_END""") iterator = fileUtils.dbFileIterator(handle) self.assertRaises(DBErrors.BadCount, dbfsv0.BeatStructureV0().read, iterator)
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")
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")
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)
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)
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)
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)
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)
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")])
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)
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)
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)
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)
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)
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)
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)
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")
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")
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')
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)
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)
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)