Esempio n. 1
0
 def testSevenFour(self):
     count = MeasureCount.makeSimpleCount(self.eighths, 7)
     self.assertEqual(count.timeSig(), (7, 4))
     count = MeasureCount.makeSimpleCount(self.triplets, 7)
     self.assertEqual(count.timeSig(), (7, 4))
     count = MeasureCount.makeSimpleCount(self.sixteenths, 7)
     self.assertEqual(count.timeSig(), (7, 4))
Esempio n. 2
0
 def testNineEight(self):
     count = MeasureCount.makeSimpleCount(self.eighths, 4)
     count.addBeats(Beat.Beat(self.eighths, 1), 1)
     self.assertEqual(count.timeSig(), (9, 8))
     count = MeasureCount.makeSimpleCount(self.sixteenths, 4)
     count.addBeats(Beat.Beat(self.sixteenths, 2), 1)
     self.assertEqual(count.timeSig(), (9, 8))
Esempio n. 3
0
 def testNineEight(self):
     count = MeasureCount.makeSimpleCount(self.eighths, 4)
     count.addBeats(Beat.Beat(self.eighths, 1), 1)
     self.assertEqual(count.timeSig(), (9, 8))
     count = MeasureCount.makeSimpleCount(self.sixteenths, 4)
     count.addBeats(Beat.Beat(self.sixteenths, 2), 1)
     self.assertEqual(count.timeSig(), (9, 8))
Esempio n. 4
0
 def testFiveFour(self):
     count = MeasureCount.makeSimpleCount(self.eighths, 5)
     self.assertEqual(count.timeSig(), (5, 4))
     count = MeasureCount.makeSimpleCount(self.triplets, 5)
     self.assertEqual(count.timeSig(), (5, 4))
     count = MeasureCount.makeSimpleCount(self.sixteenths, 5)
     self.assertEqual(count.timeSig(), (5, 4))
Esempio n. 5
0
 def testFiveFour(self):
     count = MeasureCount.makeSimpleCount(self.eighths, 5)
     self.assertEqual(count.timeSig(), (5, 4))
     count = MeasureCount.makeSimpleCount(self.triplets, 5)
     self.assertEqual(count.timeSig(), (5, 4))
     count = MeasureCount.makeSimpleCount(self.sixteenths, 5)
     self.assertEqual(count.timeSig(), (5, 4))
Esempio n. 6
0
 def testSevenFour(self):
     count = MeasureCount.makeSimpleCount(self.eighths, 7)
     self.assertEqual(count.timeSig(), (7, 4))
     count = MeasureCount.makeSimpleCount(self.triplets, 7)
     self.assertEqual(count.timeSig(), (7, 4))
     count = MeasureCount.makeSimpleCount(self.sixteenths, 7)
     self.assertEqual(count.timeSig(), (7, 4))
Esempio n. 7
0
 def testSimpleDefaultWrite(self):
     myCounter = Counter.Counter("e+a")
     count = MeasureCount.makeSimpleCount(myCounter, 4)
     handle = StringIO()
     indenter = fileUtils.Indenter(handle)
     dbfsv1.DefaultMeasureCountStructureV1().write(count, indenter)
     output = handle.getvalue().splitlines()
     self.assertEqual(output,
                      ["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"])
Esempio n. 8
0
 def testSimpleDefaultWrite(self):
     myCounter = Counter.Counter("e+a")
     count = MeasureCount.makeSimpleCount(myCounter, 4)
     handle = StringIO()
     indenter = fileUtils.Indenter(handle)
     dbfsv1.DefaultMeasureCountStructureV1().write(count, indenter)
     output = handle.getvalue().splitlines()
     self.assertEqual(output,
                      ["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"])
Esempio n. 9
0
 def testSimpleWrite(self):
     myCounter = Counter.Counter("e+a")
     count = MeasureCount.makeSimpleCount(myCounter, 4)
     handle = StringIO()
     indenter = fileUtils.Indenter(handle)
     dbfsv0.MeasureCountStructureV0().write(count, indenter)
     output = handle.getvalue().splitlines()
     self.assertEqual(output, [
         "COUNT_INFO_START", "  REPEAT_BEATS 4", "  BEAT_START",
         "    COUNT |^e+a|", "  BEAT_END", "COUNT_INFO_END"
     ])
Esempio n. 10
0
 def testSimpleWrite(self):
     myCounter = Counter.Counter("e+a")
     count = MeasureCount.makeSimpleCount(myCounter, 4)
     handle = StringIO()
     indenter = fileUtils.Indenter(handle)
     dbfsv0.MeasureCountStructureV0().write(count, indenter)
     output = handle.getvalue().splitlines()
     self.assertEqual(output,
                      ["COUNT_INFO_START",
                       "  REPEAT_BEATS 4",
                       "  BEAT_START",
                       "    COUNT |^e+a|",
                       "  BEAT_END",
                       "COUNT_INFO_END"])
Esempio n. 11
0
 def getSmallestSimpleCount(self):
     if not self.counter.isSimpleCount():
         return None
     numBeats = self.counter.numBeats()
     maxLen = len(self)
     newCount = None
     for unused_, count in Counter.DEFAULT_REGISTRY:
         if len(count) * numBeats >= maxLen:
             continue
         mcount = MeasureCount.makeSimpleCount(count, numBeats)
         newMeasure = self.copyMeasure()
         newMeasure.setBeatCount(mcount)
         if self.numNotes() == newMeasure.numNotes():
             newCount = mcount
     return newCount
Esempio n. 12
0
 def getSmallestSimpleCount(self):
     if not self.counter.isSimpleCount():
         return None
     numBeats = self.counter.numBeats()
     maxLen = len(self)
     newCount = None
     for unused_, count in Counter.DEFAULT_REGISTRY:
         if len(count) * numBeats >= maxLen:
             continue
         mcount = MeasureCount.makeSimpleCount(count, numBeats)
         newMeasure = self.copyMeasure()
         newMeasure.setBeatCount(mcount)
         if self.numNotes() == newMeasure.numNotes():
             newCount = mcount
     return newCount
Esempio n. 13
0
class TestSimple(unittest.TestCase):
    my_counter = Counter.Counter("e+a")
    count = MeasureCount.makeSimpleCount(my_counter, 4)

    def testLength(self):
        self.assertEqual(len(self.count), 16)

    def testNumBeats(self):
        self.assertEqual(self.count.numBeats(), 4)

    def testIsSimple(self):
        self.assert_(self.count.isSimpleCount())

    def testCount(self):
        self.assertEqual(list(self.count.count()),
                         ["1", "e", "+", "a",
                          "2", "e", "+", "a",
                          "3", "e", "+", "a",
                          "4", "e", "+", "a"])

    def testCountString(self):
        self.assertEqual(self.count.countString(),
                         "1e+a2e+a3e+a4e+a")

    def testGetItem(self):
        beat = self.count[1]
        self.assert_(isinstance(beat, Beat.Beat))
        self.assertEqual(beat.numTicks, 4)
        self.assertEqual(beat.ticksPerBeat, 4)
        self.assertRaises(IndexError, self.count.__getitem__, 4)

    def testIterTimesMs(self):
        times = list(self.count.iterTimesMs(100))
        self.assertEqual(times, [0, 25, 50, 75,
                                 100, 125, 150, 175,
                                 200, 225, 250, 275,
                                 300, 325, 350, 375, 400])

    def testTimeSig(self):
        self.assertEqual(self.count.timeSig(), (4, 4))

    def testIterBeatTicks(self):
        ticks = list(self.count.iterBeatTicks())
        beat = self.count[0]
        self.assertEqual(ticks,
                         [(0, beat, 0), (0, beat, 1),
                          (0, beat, 2), (0, beat, 3),
                          (1, beat, 0), (1, beat, 1),
                          (1, beat, 2), (1, beat, 3),
                          (2, beat, 0), (2, beat, 1),
                          (2, beat, 2), (2, beat, 3),
                          (3, beat, 0), (3, beat, 1),
                          (3, beat, 2), (3, beat, 3)])

    def testIterBeatTickPositions(self):
        ticks = list(self.count.iterBeatTickPositions())
        self.assertEqual(ticks, [0, 4, 8, 12])

    def testIterMidiTicks(self):
        ticks = list(self.count.iterMidiTicks())
        self.assertEqual(ticks, [0, 48, 96, 144,
                                 192, 240, 288, 336,
                                 384, 432, 480, 528,
                                 576, 624, 672, 720, 768])

    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, 4), (1, 1, 4), (1, 2, 4), (1, 3, 4),
                          (2, 0, 4), (2, 1, 4), (2, 2, 4), (2, 3, 4),
                          (3, 0, 4), (3, 1, 4), (3, 2, 4), (3, 3, 4)])
Esempio n. 14
0
 def testSeventeenSixteen(self):
     count = MeasureCount.makeSimpleCount(self.sixteenths, 4)
     count.addBeats(Beat.Beat(self.sixteenths, 1), 1)
     self.assertEqual(count.timeSig(), (17, 16))
Esempio n. 15
0
 def testSeventeenSixteen(self):
     count = MeasureCount.makeSimpleCount(self.sixteenths, 4)
     count.addBeats(Beat.Beat(self.sixteenths, 1), 1)
     self.assertEqual(count.timeSig(), (17, 16))
Esempio n. 16
0
class TestSimple(unittest.TestCase):
    my_counter = Counter.Counter(Counter.BEAT_COUNT + "e+a")
    count = MeasureCount.makeSimpleCount(my_counter, 4)

    def testLength(self):
        self.assertEqual(len(self.count), 16)

    def testNumBeats(self):
        self.assertEqual(self.count.numBeats(), 4)

    def testIsSimple(self):
        self.assert_(self.count.isSimpleCount())

    def testCount(self):
        self.assertEqual(list(self.count.count()),
                         ["1", "e", "+", "a",
                          "2", "e", "+", "a",
                          "3", "e", "+", "a",
                          "4", "e", "+", "a"])

    def testCountString(self):
        self.assertEqual(self.count.countString(),
                         "1e+a2e+a3e+a4e+a")

    def testGetItem(self):
        beat = self.count[1]
        self.assert_(isinstance(beat, Beat.Beat))
        self.assertEqual(beat.numTicks, 4)
        self.assertEqual(beat.ticksPerBeat, 4)
        self.assertRaises(IndexError, self.count.__getitem__, 4)

    def testIterTimesMs(self):
        times = list(self.count.iterTimesMs(100))
        self.assertEqual(times, [0, 25, 50, 75,
                                 100, 125, 150, 175,
                                 200, 225, 250, 275,
                                 300, 325, 350, 375, 400])

    def testTimeSig(self):
        self.assertEqual(self.count.timeSig(), (4, 4))

    def testIterBeatTicks(self):
        ticks = list(self.count.iterBeatTicks())
        beat = self.count[0]
        self.assertEqual(ticks,
                         [(0, beat, 0), (0, beat, 1),
                          (0, beat, 2), (0, beat, 3),
                          (1, beat, 0), (1, beat, 1),
                          (1, beat, 2), (1, beat, 3),
                          (2, beat, 0), (2, beat, 1),
                          (2, beat, 2), (2, beat, 3),
                          (3, beat, 0), (3, beat, 1),
                          (3, beat, 2), (3, beat, 3)])

    def testIterBeatTickPositions(self):
        ticks = list(self.count.iterBeatTickPositions())
        self.assertEqual(ticks, [0, 4, 8, 12])

    def testIterMidiTicks(self):
        ticks = list(self.count.iterMidiTicks())
        self.assertEqual(ticks, [0, 24, 48, 72,
                                 96, 120, 144, 168,
                                 192, 216, 240, 264,
                                 288, 312, 336, 360, 384])

    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, 4), (1, 1, 4), (1, 2, 4), (1, 3, 4),
                          (2, 0, 4), (2, 1, 4), (2, 2, 4), (2, 3, 4),
                          (3, 0, 4), (3, 1, 4), (3, 2, 4), (3, 3, 4)])

    def testWrite(self):
        handle = StringIO()
        indenter = fileUtils.Indenter(handle)
        self.count.write(indenter)
        output = handle.getvalue().splitlines()
        self.assertEqual(output,
                         ["COUNT_INFO_START",
                          "  REPEAT_BEATS 4",
                          "  BEAT_START",
                          "    COUNT |^e+a|",
                          "  BEAT_END",
                          "COUNT_INFO_END"])