def testComplexWrite(self): counter1 = Counter.Counter("e+a") counter2 = Counter.Counter("+a") counter3 = Counter.Counter("+") counter4 = Counter.Counter("e+a") count = MeasureCount.MeasureCount() count.addBeats(Beat.Beat(counter1), 1) count.addBeats(Beat.Beat(counter2), 1) count.addBeats(Beat.Beat(counter3), 1) count.addBeats(Beat.Beat(counter4, 2), 1) handle = StringIO() indenter = fileUtils.Indenter(handle) dbfsv1.MeasureCountStructureV1().write(count, indenter) output = handle.getvalue().splitlines() self.assertEqual(output, ["START_MEASURE_COUNT", " BEAT_START", " NUM_TICKS 4", " COUNT |^e+a|", " BEAT_END", " BEAT_START", " NUM_TICKS 3", " COUNT |^+a|", " BEAT_END", " BEAT_START", " NUM_TICKS 2", " COUNT |^+|", " BEAT_END", " BEAT_START", " NUM_TICKS 2", " COUNT |^e+a|", " BEAT_END", "END_MEASURE_COUNT"])
def read(self, scoreIterator): tracker = self._BarlineTracker(self) self.counter = MeasureCount.MeasureCount() with scoreIterator.section("START_BAR", "END_BAR") as section: section.readCallback("BARLINE", tracker.processBarline) section.readCallback("NOTE", self._readNote) section.readSubsection("COUNT_INFO_START", self._readCounter) section.readCallback("BEATLENGTH", self._makeOldMeasure) section.readPositiveInteger("REPEAT_COUNT", self, "repeatCount") section.readString("ALTERNATE", self, "alternateText")
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 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 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 testReadComplex(self): data = """COUNT_INFO_START BEAT_START COUNT |^e+a| BEAT_END BEAT_START COUNT |^+a| BEAT_END BEAT_START COUNT |^+| BEAT_END BEAT_START NUM_TICKS 2 COUNT |^e+a| BEAT_END COUNT_INFO_END""" handle = StringIO(data) iterator = fileUtils.dbFileIterator(handle) count = MeasureCount.MeasureCount() count.read(iterator) self.assertFalse(count.isSimpleCount()) self.assertEqual(len(count), 11)
def _readCounter(self, scoreIterator): counter = MeasureCount.MeasureCount() counter.read(scoreIterator) self.setBeatCount(counter)
class TestComplex(unittest.TestCase): counter1 = Counter.Counter("e+a") counter2 = Counter.Counter("+a") counter3 = Counter.Counter("+") counter4 = Counter.Counter("e+a") count = MeasureCount.MeasureCount() count.addBeats(Beat.Beat(counter1), 1) count.addBeats(Beat.Beat(counter2), 1) count.addBeats(Beat.Beat(counter3), 1) count.addBeats(Beat.Beat(counter4, 2), 1) def testLength(self): self.assertEqual(len(self.count), 11) def testNumBeats(self): self.assertEqual(self.count.numBeats(), 4) def testIsSimple(self): self.assertFalse(self.count.isSimpleCount()) def testCount(self): self.assertEqual(list(self.count.count()), ["1", "e", "+", "a", "2", "+", "a", "3", "+", "4", "e", ]) def testCountString(self): self.assertEqual(self.count.countString(), "1e+a2+a3+4e") def testGetItem(self): beat = self.count[1] self.assert_(isinstance(beat, Beat.Beat)) self.assertEqual(beat.numTicks, 3) self.assertEqual(beat.ticksPerBeat, 3) self.assertRaises(IndexError, self.count.__getitem__, 4) def testIterTimesMs(self): times = list(self.count.iterTimesMs(120)) self.assertEqual(times, [0, 30, 60, 90, 120, 160, 200, 240, 300, 360, 390, 420]) def testTimeSig(self): self.assertEqual(self.count.timeSig(), (7, 8)) def testIterBeatTicks(self): ticks = list(self.count.iterBeatTicks()) beat1 = self.count[0] beat2 = self.count[1] beat3 = self.count[2] beat4 = self.count[3] self.assertEqual(ticks, [(0, beat1, 0), (0, beat1, 1), (0, beat1, 2), (0, beat1, 3), (1, beat2, 0), (1, beat2, 1), (1, beat2, 2), (2, beat3, 0), (2, beat3, 1), (3, beat4, 0), (3, beat4, 1)]) def testIterBeatTickPositions(self): ticks = list(self.count.iterBeatTickPositions()) self.assertEqual(ticks, [0, 4, 7, 9]) def testIterMidiTicks(self): ticks = list(self.count.iterMidiTicks()) self.assertEqual(ticks, [0, 48, 96, 144, 192, 256, 320, 384, 480, 576, 624, 672]) def testIterTime(self): ticks = list(self.count.iterTime()) self.assertEqual(ticks, [(0, 0, 4), (0, 1, 4), (0, 2, 4), (0, 3, 4), (1, 0, 3), (1, 1, 3), (1, 2, 3), (2, 0, 2), (2, 1, 2), (3, 0, 4), (3, 1, 4)])
def setUp(self): self.measure = Measure(16) counter = self.reg.getCounterByName("16ths") mc = MeasureCount.MeasureCount() mc.addSimpleBeats(counter, 4) self.measure.setBeatCount(mc)
class TestComplex(unittest.TestCase): counter1 = Counter.Counter(Counter.BEAT_COUNT + "e+a") counter2 = Counter.Counter(Counter.BEAT_COUNT + "+a") counter3 = Counter.Counter(Counter.BEAT_COUNT + "+") counter4 = Counter.Counter(Counter.BEAT_COUNT + "e+a") count = MeasureCount.MeasureCount() count.addBeats(Beat.Beat(counter1), 1) count.addBeats(Beat.Beat(counter2), 1) count.addBeats(Beat.Beat(counter3), 1) count.addBeats(Beat.Beat(counter4, 2), 1) def testLength(self): self.assertEqual(len(self.count), 11) def testNumBeats(self): self.assertEqual(self.count.numBeats(), 4) def testIsSimple(self): self.assertFalse(self.count.isSimpleCount()) def testCount(self): self.assertEqual(list(self.count.count()), ["1", "e", "+", "a", "2", "+", "a", "3", "+", "4", "e", ]) def testCountString(self): self.assertEqual(self.count.countString(), "1e+a2+a3+4e") def testGetItem(self): beat = self.count[1] self.assert_(isinstance(beat, Beat.Beat)) self.assertEqual(beat.numTicks, 3) self.assertEqual(beat.ticksPerBeat, 3) self.assertRaises(IndexError, self.count.__getitem__, 4) def testIterTimesMs(self): times = list(self.count.iterTimesMs(120)) self.assertEqual(times, [0, 30, 60, 90, 120, 160, 200, 240, 300, 360, 390, 420]) def testTimeSig(self): self.assertEqual(self.count.timeSig(), (7, 8)) def testIterBeatTicks(self): ticks = list(self.count.iterBeatTicks()) beat1 = self.count[0] beat2 = self.count[1] beat3 = self.count[2] beat4 = self.count[3] self.assertEqual(ticks, [(0, beat1, 0), (0, beat1, 1), (0, beat1, 2), (0, beat1, 3), (1, beat2, 0), (1, beat2, 1), (1, beat2, 2), (2, beat3, 0), (2, beat3, 1), (3, beat4, 0), (3, beat4, 1)]) def testIterBeatTickPositions(self): ticks = list(self.count.iterBeatTickPositions()) self.assertEqual(ticks, [0, 4, 7, 9]) def testIterMidiTicks(self): ticks = list(self.count.iterMidiTicks()) self.assertEqual(ticks, [0, 24, 48, 72, 96, 128, 160, 192, 240, 288, 312, 336]) def testIterTime(self): ticks = list(self.count.iterTime()) self.assertEqual(ticks, [(0, 0, 4), (0, 1, 4), (0, 2, 4), (0, 3, 4), (1, 0, 3), (1, 1, 3), (1, 2, 3), (2, 0, 2), (2, 1, 2), (3, 0, 4), (3, 1, 4)]) def testWrite(self): handle = StringIO() indenter = fileUtils.Indenter(handle) self.count.write(indenter) output = handle.getvalue().splitlines() self.assertEqual(output, ["COUNT_INFO_START", " BEAT_START", " COUNT |^e+a|", " BEAT_END", " BEAT_START", " COUNT |^+a|", " BEAT_END", " BEAT_START", " COUNT |^+|", " BEAT_END", " BEAT_START", " NUM_TICKS 2", " COUNT |^e+a|", " BEAT_END", "COUNT_INFO_END"])