Пример #1
0
 def testDeleteMeasure_BadIndex(self):
     self.staff.addMeasure(Measure(1))
     self.staff.addMeasure(Measure(2))
     self.assertRaises(BadTimeError, self.staff.deleteMeasure,
                       NotePosition(measureIndex=-1))
     self.assertRaises(BadTimeError, self.staff.deleteMeasure,
                       NotePosition(measureIndex=2))
Пример #2
0
 def testAddMeasure(self):
     self.staff.addMeasure(Measure(1))
     self.assertEqual(self.staff.numMeasures(), 1)
     self.assertEqual(len(self.staff), 1)
     self.staff.addMeasure(Measure(2))
     self.assertEqual(self.staff.numMeasures(), 2)
     self.assertEqual(len(self.staff), 3)
Пример #3
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.")
Пример #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 setUp(self):
     self.staff = Staff()
     self.staff.addMeasure(Measure(1))
     self.staff.addMeasure(Measure(2))
     self.staff.addMeasure(Measure(3))
     self.staff.addMeasure(Measure(4))
     self.np = NotePosition(measureIndex=2)
Пример #6
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())
Пример #7
0
 def testClearStaff(self):
     self.staff.addMeasure(Measure(16))
     self.staff.addMeasure(Measure(16))
     self.staff.addMeasure(Measure(16))
     self.staff.addMeasure(Measure(16))
     self.staff.clear()
     self.assertEqual(len(self.staff), 0)
     self.assertEqual(self.staff.numMeasures(), 0)
Пример #8
0
    def setUp(self):
        self.measure = Measure(16)
        self.calls = []

        def myCallBack(position):
            self.calls.append((position.noteTime, position.drumIndex))

        self.measure.setCallBack(myCallBack)
Пример #9
0
 def testCount(self):
     count = self.measure.count()
     self.assertEqual(count, [
         "1", "e", "+", "a", "2", "e", "+", "a", "3", "e", "+", "a", "4",
         "e", "+", "a"
     ])
     measure = Measure(16)
     self.assertEqual(measure.count(), [" "] * 16)
Пример #10
0
 def testInsertMeasure_BadIndex(self):
     self.staff.addMeasure(Measure(1))
     self.staff.addMeasure(Measure(2))
     m = Measure(3)
     self.assertRaises(BadTimeError, self.staff.insertMeasure,
                       NotePosition(measureIndex=-1), m)
     self.assertRaises(BadTimeError, self.staff.insertMeasure,
                       NotePosition(measureIndex=3), m)
Пример #11
0
 def testGridWidth(self):
     self.staff.addMeasure(Measure(16))
     self.staff.addMeasure(Measure(16))
     self.staff.addMeasure(Measure(16))
     self.assertEqual(self.staff.gridWidth(), 52)
     endMeasure = Measure(16)
     endMeasure.setSectionEnd(True)
     self.staff.addMeasure(endMeasure)
     self.assertEqual(self.staff.gridWidth(), 69)
Пример #12
0
 def testCount(self):
     count = self.measure.count()
     self.assertEqual(count,
                      ["1", "e", "+", "a",
                       "2", "e", "+", "a",
                       "3", "e", "+", "a",
                       "4", "e", "+", "a"])
     measure = Measure(16)
     self.assertEqual(measure.count(), [" "] * 16)
Пример #13
0
 def testCopyPaste(self):
     self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "x")
     self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "o")
     measure2 = Measure(8)
     copied = self.measure.copyMeasure()
     measure2.pasteMeasure(copied)
     self.assertEqual(len(measure2), 16)
     self.assertEqual(measure2.numNotes(), 2)
     self.assertEqual(measure2.getNote(NotePosition(None, None, 0, 0)), "x")
     self.assertEqual(measure2.getNote(NotePosition(None, None, 1, 1)), "o")
Пример #14
0
 def testDeleteLastMeasure(self):
     self.staff.addMeasure(Measure(1))
     self.staff.addMeasure(Measure(2))
     self.staff.addMeasure(Measure(3))
     self.staff.addMeasure(Measure(4))
     self.assertEqual(self.staff.numMeasures(), 4)
     self.staff.deleteLastMeasure()
     self.assertEqual(self.staff.numMeasures(), 3)
     for index in range(1, 4):
         self.assertEqual(len(self.staff[index - 1]), index)
Пример #15
0
 def setUp(self):
     self.kit = DrumKitFactory.getNamedDefaultKit()
     self.lilykit = lilypond.LilyKit(self.kit)
     self.indenter = lilypond.LilyIndenter()
     self.output = StringIO.StringIO()
     self.indenter.setHandle(self.output)
     self.measure = Measure()
     counter = _REG.getCounterByName("Triplets")
     mc = MeasureCount()
     mc.addSimpleBeats(counter, 4)
     self.measure.setBeatCount(mc)
Пример #16
0
 def testDeleteMeasureCallBack(self):
     self.staff.addMeasure(Measure(16))
     self.staff.addMeasure(Measure(16))
     np = NotePosition(measureIndex=1, noteTime=0, drumIndex=0)
     self.staff.addNote(np, "x")
     self.staff.deleteMeasure(NotePosition(measureIndex=0))
     self.staff.deleteNote(
         NotePosition(measureIndex=0, noteTime=0, drumIndex=0))
     self.staff.addNote(np, "x")
     self.assertEqual(len(self.calls), 3)
     self.assertEqual(self.calls[0], (1, 0, 0))
     self.assertEqual(self.calls[1], (0, 0, 0))
     self.assertEqual(self.calls[2], (1, 0, 0))
Пример #17
0
 def insertMeasureByPosition(self, width, position=None, counter=None):
     if position is None:
         if self.numStaffs() == 0:
             self._addStaff()
         position = NotePosition(self.numStaffs() - 1)
         staff = self.getStaffByIndex(self.numStaffs() - 1)
         position.measureIndex = staff.numMeasures()
     self._checkStaffIndex(position.staffIndex)
     newMeasure = Measure(width)
     newMeasure.counter = counter
     staff = self.getStaffByIndex(position.staffIndex)
     staff.insertMeasure(position, newMeasure)
     return newMeasure
Пример #18
0
 def insertMeasureByPosition(self, width, position = None, counter = None):
     if position is None:
         if self.numStaffs() == 0:
             self._addStaff()
         position = NotePosition(self.numStaffs() - 1)
         staff = self.getStaffByIndex(self.numStaffs() - 1)
         position.measureIndex = staff.numMeasures()
     self._checkStaffIndex(position.staffIndex)
     newMeasure = Measure(width)
     newMeasure.counter = counter
     staff = self.getStaffByIndex(position.staffIndex)
     staff.insertMeasure(position, newMeasure)
     return newMeasure
Пример #19
0
 def insertMeasureByIndex(self, width, index = None, counter = None, measure = None):
     if index is None:
         index = self.numMeasures()
     if self.numStaffs() == 0:
         self._addStaff()
         staff = self.getStaffByIndex(0)
     elif index == self.numMeasures():
         staff = self.getStaffByIndex(-1)
         index = staff.numMeasures()
     else:
         staff, index = self._staffContainingMeasure(index)
     if measure is None:
         newMeasure = Measure(width)
         newMeasure.counter = counter
     else:
         newMeasure = measure
     staff.insertMeasure(NotePosition(measureIndex = index),
                         newMeasure)
     return newMeasure
Пример #20
0
    def setUp(self):
        self.staff = Staff()
        self.staff.addMeasure(Measure(16))
        self.calls = []

        def myCallBack(position):
            self.calls.append(
                (position.measureIndex, position.noteTime, position.drumIndex))

        self.staff.setCallBack(myCallBack)
Пример #21
0
 def insertMeasureByIndex(self, width, index=None, counter=None, measure=None):
     if index is None:
         index = self.numMeasures()
     if self.numStaffs() == 0:
         self._addStaff()
         staff = self.getStaffByIndex(0)
     elif index == self.numMeasures():
         staff = self.getStaffByIndex(-1)
         index = staff.numMeasures()
     else:
         staff, index = self._staffContainingMeasure(index)
     if measure is None:
         newMeasure = Measure(width)
         newMeasure.counter = counter
     else:
         newMeasure = measure
     staff.insertMeasure(NotePosition(measureIndex=index),
                         newMeasure)
     return newMeasure
Пример #22
0
 def testGridWidth(self):
     self.staff.addMeasure(Measure(16))
     self.staff.addMeasure(Measure(16))
     self.staff.addMeasure(Measure(16))
     self.assertEqual(self.staff.gridWidth(), 52)
     endMeasure = Measure(16)
     endMeasure.setSectionEnd(True)
     self.staff.addMeasure(endMeasure)
     self.assertEqual(self.staff.gridWidth(), 69)
Пример #23
0
 def testInsertMeasureCallBack(self):
     np0 = NotePosition(measureIndex=0, noteTime=0, drumIndex=0)
     np1 = NotePosition(measureIndex=1, noteTime=0, drumIndex=0)
     self.staff.addNote(np0, "x")
     self.staff.insertMeasure(np0, Measure(8))
     self.staff.addNote(np0, "x")
     self.staff.deleteNote(np1)
     self.assertEqual(len(self.calls), 3)
     self.assertEqual(self.calls[0], (0, 0, 0))
     self.assertEqual(self.calls[1], (0, 0, 0))
     self.assertEqual(self.calls[2], (1, 0, 0))
Пример #24
0
class TestCompoundSticking(unittest.TestCase):
    def setUp(self):
        self.kit = DrumKitFactory.getNamedDefaultKit()
        self.lilykit = lilypond.LilyKit(self.kit)
        self.indenter = lilypond.LilyIndenter()
        self.output = StringIO.StringIO()
        self.indenter.setHandle(self.output)
        self.measure = Measure()
        counter = _REG.getCounterByName("Triplets")
        mc = MeasureCount()
        mc.addSimpleBeats(counter, 4)
        self.measure.setBeatCount(mc)

    def testCompoundSticking(self):
        self.measure.setAbove(0, "L")
        self.measure.setAbove(1, "R")
        self.measure.setAbove(2, "L")
        lilyMeasure = lilypond.LilyMeasure(self.measure, self.lilykit)
        lilyMeasure.sticking(self.indenter)
        output = self.output.getvalue().strip()
        self.assertEqual(
            output,
            r'\new Lyrics \with { alignAboveContext = #"main" } \lyricmode { \times 2/3 { L8 R8 L8 } " "4 " "4 " "4 }'
        )

    def testCompoundStickingAtEndOfMeasure(self):
        self.measure.setAbove(9, "L")
        self.measure.setAbove(10, "R")
        self.measure.setAbove(11, "L")
        lilyMeasure = lilypond.LilyMeasure(self.measure, self.lilykit)
        lilyMeasure.sticking(self.indenter)
        output = self.output.getvalue().strip()
        self.assertEqual(
            output,
            r'\new Lyrics \with { alignAboveContext = #"main" } \lyricmode { " "4 " "4 " "4 \times 2/3 { L8 R8 L8 } }'
        )
Пример #25
0
 def testCopyPaste(self):
     self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "x")
     self.measure.addNote(NotePosition(noteTime=1, drumIndex=1), "o")
     measure2 = Measure(8)
     copied = self.measure.copyMeasure()
     measure2.pasteMeasure(copied)
     self.assertEqual(len(measure2), 16)
     self.assertEqual(measure2.numNotes(), 2)
     self.assertEqual(measure2.getNote(NotePosition(None, None, 0, 0)), "x")
     self.assertEqual(measure2.getNote(NotePosition(None, None, 1, 1)), "o")
Пример #26
0
 def testReadRepeatBar(self):
     data = """START_BAR 8
                 COUNT_INFO_START
                   REPEAT_BEATS 4
                   BEAT_START
                     COUNT |^+|
                   BEAT_END
                 COUNT_INFO_END
                 BARLINE NORMAL_BAR,REPEAT_START,NO_BAR
                 BARLINE NORMAL_BAR,NO_BAR,REPEAT_END
                 REPEAT_COUNT 6
               END_BAR"""
     handle = StringIO(data)
     iterator = fileUtils.dbFileIterator(handle)
     measure = Measure()
     measure.read(iterator)
     self.assertEqual(measure.repeatCount, 6)
     self.assert_(measure.isRepeatStart())
     self.assert_(measure.isRepeatEnd())
Пример #27
0
 def testReadOldMeasure(self):
     data = """START_BAR 8
               BEATLENGTH 2
               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(8)
     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)
Пример #28
0
 def setUp(self):
     self.measure = Measure(16)
     counter = self.reg.getCounterByName("16ths")
     mc = MeasureCount()
     mc.addSimpleBeats(counter, 4)
     self.measure.setBeatCount(mc)
Пример #29
0
class TestMeasure(unittest.TestCase):
    reg = CounterRegistry()

    def setUp(self):
        self.measure = Measure(16)
        counter = self.reg.getCounterByName("16ths")
        mc = MeasureCount()
        mc.addSimpleBeats(counter, 4)
        self.measure.setBeatCount(mc)

    def testCount(self):
        count = self.measure.count()
        self.assertEqual(count, [
            "1", "e", "+", "a", "2", "e", "+", "a", "3", "e", "+", "a", "4",
            "e", "+", "a"
        ])
        measure = Measure(16)
        self.assertEqual(measure.count(), [" "] * 16)

    def testEmptyMeasure(self):
        self.assertEqual(len(self.measure), 16)
        self.assertEqual(self.measure.numNotes(), 0)
        self.assertEqual(
            self.measure.getNote(NotePosition(noteTime=0, drumIndex=0)),
            EMPTY_NOTE)
        self.assertFalse(self.measure.isSectionEnd())
        self.assertFalse(self.measure.isRepeatEnd())
        self.assertFalse(self.measure.isRepeatStart())

    def testIsEmpty_True(self):
        self.assert_(self.measure.isEmpty())

    def testIsEmpty_False(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "o")
        self.assertFalse(self.measure.isEmpty())

    def testGetNote_BadTime(self):
        self.assertRaises(BadTimeError, self.measure.getNote,
                          NotePosition(noteTime=-1, drumIndex=0))
        self.assertRaises(BadTimeError, self.measure.getNote,
                          NotePosition(noteTime=20, drumIndex=0))

    def testNumNotes(self):
        for i in range(0, 16):
            self.measure.addNote(NotePosition(noteTime=i, drumIndex=0), "o")
        self.assertEqual(self.measure.numNotes(), 16)

    def testAddNote(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "o")
        notePos = NotePosition(noteTime=0, drumIndex=0)
        self.assertEqual(self.measure.getNote(notePos), "o")

    def testAddNote_BadTime(self):
        self.assertRaises(BadTimeError, self.measure.addNote,
                          NotePosition(noteTime=-1, drumIndex=0), "x")
        self.assertRaises(BadTimeError, self.measure.addNote,
                          NotePosition(noteTime=20, drumIndex=0), "x")

    def testIterNotes(self):
        for i in range(0, 4):
            self.measure.addNote(NotePosition(noteTime=4 * i, drumIndex=i),
                                 str(i))
        for i, (np, head) in enumerate(self.measure):
            self.assertEqual(head, str(i))
            self.assertEqual(np.noteTime, 4 * i)
            self.assertEqual(np.drumIndex, i)

    def testDeleteNote(self):
        np = NotePosition(noteTime=0, drumIndex=0)
        self.measure.addNote(np, "o")
        self.measure.deleteNote(np)
        self.assertEqual(self.measure.numNotes(), 0)
        self.assertEqual(self.measure.getNote(np), EMPTY_NOTE)

    def testDeleteNote_BadTime(self):
        self.assertRaises(BadTimeError, self.measure.deleteNote,
                          NotePosition(noteTime=-1, drumIndex=0))
        self.assertRaises(BadTimeError, self.measure.deleteNote,
                          NotePosition(noteTime=20, drumIndex=0))

    def testToggleNote(self):
        np = NotePosition(noteTime=0, drumIndex=0)
        self.measure.toggleNote(np, "o")
        self.assertEqual(self.measure.getNote(np), "o")
        self.assertEqual(self.measure.numNotes(), 1)
        self.measure.toggleNote(np, "o")
        self.assertEqual(self.measure.numNotes(), 0)
        self.assertEqual(self.measure.getNote(np), EMPTY_NOTE)

    def testToggleNote_ChangeNote(self):
        np = NotePosition(noteTime=0, drumIndex=0)
        self.measure.toggleNote(np, "o")
        self.measure.toggleNote(np, "x")
        self.assertEqual(self.measure.getNote(np), "x")

    def testToggleNote_BadTime(self):
        self.assertRaises(BadTimeError, self.measure.toggleNote,
                          NotePosition(noteTime=-1, drumIndex=0), "x")
        self.assertRaises(BadTimeError, self.measure.toggleNote,
                          NotePosition(noteTime=20, drumIndex=0), "x")

    def testSetSectionEnd_NoRepeat(self):
        self.assertFalse(self.measure.isSectionEnd())
        self.assertFalse(self.measure.isLineEnd())
        self.measure.setSectionEnd(True)
        self.assert_(self.measure.isSectionEnd())
        self.assert_(self.measure.isLineEnd())
        self.measure.setSectionEnd(False)
        self.assertFalse(self.measure.isSectionEnd())
        self.assertFalse(self.measure.isLineEnd())

    def testSetSectionEnd_Repeat(self):
        self.measure.setRepeatEnd(True)
        self.assertFalse(self.measure.isSectionEnd())
        self.measure.setSectionEnd(True)
        self.assert_(self.measure.isSectionEnd())
        self.assert_(self.measure.isRepeatEnd())
        self.measure.setSectionEnd(False)
        self.assertFalse(self.measure.isSectionEnd())
        self.assert_(self.measure.isRepeatEnd())
        self.measure.setRepeatEnd(False)
        self.assertFalse(self.measure.isSectionEnd())
        self.assertFalse(self.measure.isRepeatEnd())

    def testSetRepeatStart(self):
        self.measure.setRepeatStart(True)
        self.assert_(self.measure.isRepeatStart())
        self.measure.setRepeatStart(False)
        self.assertFalse(self.measure.isRepeatStart())

    def testSetRepeatEnd_NotSectionEnd(self):
        self.measure.setRepeatEnd(True)
        self.assert_(self.measure.isRepeatEnd())
        self.measure.setRepeatEnd(False)
        self.assertFalse(self.measure.isRepeatEnd())

    def testSetRepeatEnd_IsSectionEnd(self):
        self.measure.setSectionEnd(True)
        self.measure.setRepeatEnd(True)
        self.assert_(self.measure.isRepeatEnd())
        self.measure.setRepeatEnd(False)
        self.assertFalse(self.measure.isRepeatEnd())

    def testLineBreak(self):
        self.assertFalse(self.measure.isLineBreak())
        self.assertFalse(self.measure.isLineEnd())
        self.measure.setLineBreak(True)
        self.assert_(self.measure.isLineBreak())
        self.assert_(self.measure.isLineEnd())
        self.measure.setLineBreak(False)
        self.assertFalse(self.measure.isLineBreak())
        self.assertFalse(self.measure.isLineEnd())

    def testClearMeasure(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "x")
        self.measure.addNote(NotePosition(noteTime=1, drumIndex=1), "o")
        self.assertEqual(self.measure.numNotes(), 2)
        self.assertFalse(self.measure.isEmpty())
        self.measure.clear()
        self.assert_(self.measure.isEmpty())

    def testCopyPaste(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "x")
        self.measure.addNote(NotePosition(noteTime=1, drumIndex=1), "o")
        measure2 = Measure(8)
        copied = self.measure.copyMeasure()
        measure2.pasteMeasure(copied)
        self.assertEqual(len(measure2), 16)
        self.assertEqual(measure2.numNotes(), 2)
        self.assertEqual(measure2.getNote(NotePosition(None, None, 0, 0)), "x")
        self.assertEqual(measure2.getNote(NotePosition(None, None, 1, 1)), "o")

    def testCopyPasteWithDecorations(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "x")
        self.measure.addNote(NotePosition(noteTime=1, drumIndex=1), "o")
        self.measure.setRepeatEnd(True)
        self.measure.setRepeatStart(True)
        self.measure.setLineBreak(True)
        self.measure.setSectionEnd(True)
        measure2 = Measure(8)
        self.assertFalse(measure2.isRepeatEnd())
        self.assertFalse(measure2.isRepeatStart())
        self.assertFalse(measure2.isLineBreak())
        self.assertFalse(measure2.isSectionEnd())
        copied = self.measure.copyMeasure()
        measure2.pasteMeasure(copied, True)
        self.assertEqual(len(measure2), 16)
        self.assertEqual(measure2.numNotes(), 2)
        self.assertEqual(measure2.getNote(NotePosition(None, None, 0, 0)), "x")
        self.assertEqual(measure2.getNote(NotePosition(None, None, 1, 1)), "o")
        self.assertTrue(measure2.isRepeatEnd())
        self.assertTrue(measure2.isRepeatStart())
        self.assertTrue(measure2.isLineBreak())
        self.assertTrue(measure2.isSectionEnd())

    def testChangeCount_Shorter(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "a")
        self.measure.addNote(NotePosition(noteTime=1, drumIndex=1), "b")
        self.measure.addNote(NotePosition(noteTime=2, drumIndex=0), "c")
        self.measure.addNote(NotePosition(noteTime=3, drumIndex=1), "d")
        self.measure.addNote(NotePosition(noteTime=4, drumIndex=0), "e")
        self.measure.addNote(NotePosition(noteTime=5, drumIndex=1), "f")
        self.measure.addNote(NotePosition(noteTime=6, drumIndex=0), "g")
        self.measure.addNote(NotePosition(noteTime=7, drumIndex=1), "h")
        self.measure.addNote(NotePosition(noteTime=8, drumIndex=0), "i")
        self.measure.addNote(NotePosition(noteTime=9, drumIndex=1), "j")
        self.measure.addNote(NotePosition(noteTime=10, drumIndex=0), "k")
        self.measure.addNote(NotePosition(noteTime=11, drumIndex=1), "l")
        self.measure.addNote(NotePosition(noteTime=12, drumIndex=0), "m")
        self.measure.addNote(NotePosition(noteTime=13, drumIndex=1), "n")
        self.measure.addNote(NotePosition(noteTime=14, drumIndex=0), "o")
        self.measure.addNote(NotePosition(noteTime=15, drumIndex=1), "p")
        counter = self.reg.getCounterByName("8ths")
        mc = MeasureCount()
        mc.addSimpleBeats(counter, 3)
        self.measure.setBeatCount(mc)
        self.assertEqual(len(self.measure), 6)
        self.assertEqual(self.measure.numNotes(), 6)
        self.assertEqual(self.measure.noteAt(noteTime=0, drumIndex=0), "a")
        self.assertEqual(self.measure.noteAt(noteTime=1, drumIndex=0), "c")
        self.assertEqual(self.measure.noteAt(noteTime=2, drumIndex=0), "e")
        self.assertEqual(self.measure.noteAt(noteTime=3, drumIndex=0), "g")
        self.assertEqual(self.measure.noteAt(noteTime=4, drumIndex=0), "i")
        self.assertEqual(self.measure.noteAt(noteTime=5, drumIndex=0), "k")

    def testChangeCount_Longer(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "a")
        self.measure.addNote(NotePosition(noteTime=1, drumIndex=1), "b")
        self.measure.addNote(NotePosition(noteTime=2, drumIndex=0), "c")
        self.measure.addNote(NotePosition(noteTime=3, drumIndex=1), "d")
        self.measure.addNote(NotePosition(noteTime=4, drumIndex=0), "e")
        self.measure.addNote(NotePosition(noteTime=5, drumIndex=1), "f")
        self.measure.addNote(NotePosition(noteTime=6, drumIndex=0), "g")
        self.measure.addNote(NotePosition(noteTime=7, drumIndex=1), "h")
        self.measure.addNote(NotePosition(noteTime=8, drumIndex=0), "i")
        self.measure.addNote(NotePosition(noteTime=9, drumIndex=1), "j")
        self.measure.addNote(NotePosition(noteTime=10, drumIndex=0), "k")
        self.measure.addNote(NotePosition(noteTime=11, drumIndex=1), "l")
        self.measure.addNote(NotePosition(noteTime=12, drumIndex=0), "m")
        self.measure.addNote(NotePosition(noteTime=13, drumIndex=1), "n")
        self.measure.addNote(NotePosition(noteTime=14, drumIndex=0), "o")
        self.measure.addNote(NotePosition(noteTime=15, drumIndex=1), "p")
        counter = self.reg.getCounterByName("32nds")
        mc = MeasureCount()
        mc.addSimpleBeats(counter, 5)
        self.measure.setBeatCount(mc)
        self.assertEqual(len(self.measure), 40)
        self.assertEqual(self.measure.numNotes(), 16)
        self.assertEqual(self.measure.noteAt(noteTime=0, drumIndex=0), "a")
        self.assertEqual(self.measure.noteAt(noteTime=2, drumIndex=1), "b")
        self.assertEqual(self.measure.noteAt(noteTime=4, drumIndex=0), "c")
        self.assertEqual(self.measure.noteAt(noteTime=6, drumIndex=1), "d")
        self.assertEqual(self.measure.noteAt(noteTime=8, drumIndex=0), "e")
        self.assertEqual(self.measure.noteAt(noteTime=10, drumIndex=1), "f")
        self.assertEqual(self.measure.noteAt(noteTime=12, drumIndex=0), "g")
        self.assertEqual(self.measure.noteAt(noteTime=14, drumIndex=1), "h")
        self.assertEqual(self.measure.noteAt(noteTime=16, drumIndex=0), "i")
        self.assertEqual(self.measure.noteAt(noteTime=18, drumIndex=1), "j")
        self.assertEqual(self.measure.noteAt(noteTime=20, drumIndex=0), "k")
        self.assertEqual(self.measure.noteAt(noteTime=22, drumIndex=1), "l")
        self.assertEqual(self.measure.noteAt(noteTime=24, drumIndex=0), "m")
        self.assertEqual(self.measure.noteAt(noteTime=26, drumIndex=1), "n")
        self.assertEqual(self.measure.noteAt(noteTime=28, drumIndex=0), "o")
        self.assertEqual(self.measure.noteAt(noteTime=30, drumIndex=1), "p")

    def testLineIsVisible(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "a")
        self.measure.addNote(NotePosition(noteTime=2, drumIndex=2), "a")
        self.measure.addNote(NotePosition(noteTime=3, drumIndex=7), "a")
        self.assert_(self.measure.lineIsVisible(0))
        self.assert_(self.measure.lineIsVisible(2))
        self.assert_(self.measure.lineIsVisible(7))
        self.assertFalse(self.measure.lineIsVisible(1))
        self.assertFalse(self.measure.lineIsVisible(3))
        self.assertFalse(self.measure.lineIsVisible(4))
        self.assertFalse(self.measure.lineIsVisible(5))
        self.assertFalse(self.measure.lineIsVisible(6))
        self.assertFalse(self.measure.lineIsVisible(8))
Пример #30
0
 def setUp(self):
     self.measure = Measure(16)
     counter = self.reg.getCounterByName("16ths")
     mc = MeasureCount()
     mc.addSimpleBeats(counter, 4)
     self.measure.setBeatCount(mc)
Пример #31
0
 def setUp(self):
     self.measure = Measure(16)
     self.calls = []
     def myCallBack(position):
         self.calls.append((position.noteTime, position.drumIndex))
     self.measure.setCallBack(myCallBack)
Пример #32
0
class TestWriteMeasure(unittest.TestCase):
    reg = CounterRegistry()

    def setUp(self):
        self.measure = Measure(16)
        counter = self.reg.getCounterByName("16ths")
        mc = MeasureCount.MeasureCount()
        mc.addSimpleBeats(counter, 4)
        self.measure.setBeatCount(mc)

    def get_output(self):
        handle = StringIO()
        indenter = fileUtils.Indenter(handle)
        dbfsv0.MeasureStructureV0().write(self.measure, indenter)
        return handle.getvalue().splitlines()

    def testWriteEmpty(self):
        output = self.get_output()
        self.assertEqual(output, [
            'START_BAR 16', '  COUNT_INFO_START', '    REPEAT_BEATS 4',
            '    BEAT_START', '      COUNT |^e+a|', '    BEAT_END',
            '  COUNT_INFO_END', '  BARLINE NORMAL_BAR,NO_BAR',
            '  BARLINE NORMAL_BAR,NO_BAR', 'END_BAR'
        ])

    def testWriteSimple(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "a")
        self.measure.addNote(NotePosition(noteTime=1, drumIndex=1), "b")
        self.measure.addNote(NotePosition(noteTime=2, drumIndex=0), "c")
        self.measure.addNote(NotePosition(noteTime=3, drumIndex=1), "d")
        self.measure.addNote(NotePosition(noteTime=4, drumIndex=0), "e")
        self.measure.addNote(NotePosition(noteTime=5, drumIndex=1), "f")
        self.measure.addNote(NotePosition(noteTime=6, drumIndex=0), "g")
        self.measure.addNote(NotePosition(noteTime=7, drumIndex=1), "h")
        self.measure.addNote(NotePosition(noteTime=8, drumIndex=0), "i")
        self.measure.addNote(NotePosition(noteTime=9, drumIndex=1), "j")
        self.measure.addNote(NotePosition(noteTime=10, drumIndex=0), "k")
        self.measure.addNote(NotePosition(noteTime=11, drumIndex=1), "l")
        self.measure.addNote(NotePosition(noteTime=12, drumIndex=0), "m")
        self.measure.addNote(NotePosition(noteTime=13, drumIndex=1), "n")
        self.measure.addNote(NotePosition(noteTime=14, drumIndex=0), "o")
        self.measure.addNote(NotePosition(noteTime=15, drumIndex=1), "p")
        output = self.get_output()
        self.assertEqual(output, [
            'START_BAR 16', '  COUNT_INFO_START', '    REPEAT_BEATS 4',
            '    BEAT_START', '      COUNT |^e+a|', '    BEAT_END',
            '  COUNT_INFO_END', '  BARLINE NORMAL_BAR,NO_BAR', '  NOTE 0,0,a',
            '  NOTE 1,1,b', '  NOTE 2,0,c', '  NOTE 3,1,d', '  NOTE 4,0,e',
            '  NOTE 5,1,f', '  NOTE 6,0,g', '  NOTE 7,1,h', '  NOTE 8,0,i',
            '  NOTE 9,1,j', '  NOTE 10,0,k', '  NOTE 11,1,l', '  NOTE 12,0,m',
            '  NOTE 13,1,n', '  NOTE 14,0,o', '  NOTE 15,1,p',
            '  BARLINE NORMAL_BAR,NO_BAR', 'END_BAR'
        ])

    def testWriteDecorations(self):
        self.measure.setLineBreak(True)
        self.measure.setSectionEnd(True)
        self.measure.setRepeatEnd(True)
        self.measure.setRepeatStart(True)
        self.measure.alternateText = "xxx"
        self.measure.repeatCount = 10
        self.measure.simileDistance = 2
        self.measure.simileIndex = 1
        output = self.get_output()
        self.assertEqual(output, [
            'START_BAR 16', '  COUNT_INFO_START', '    REPEAT_BEATS 4',
            '    BEAT_START', '      COUNT |^e+a|', '    BEAT_END',
            '  COUNT_INFO_END', '  BARLINE NORMAL_BAR,REPEAT_START,NO_BAR',
            ('  BARLINE NORMAL_BAR,LINE_BREAK,NO_BAR,' +
             'SECTION_END,REPEAT_END'), '  REPEAT_COUNT 10', '  ALTERNATE xxx',
            '  SIMILE 2', '  SIMINDEX 1', 'END_BAR'
        ])
Пример #33
0
 def testInsertMeasureAtStart(self):
     self.staff.addMeasure(Measure(2))
     self.staff.insertMeasure(NotePosition(measureIndex=0), Measure(1))
     for i, measure in enumerate(self.staff):
         self.assertEqual(len(measure), i + 1)
Пример #34
0
class TestWriteMeasure(unittest.TestCase):
    reg = CounterRegistry()

    def setUp(self):
        self.measure = Measure(16)
        counter = self.reg.getCounterByName("16ths")
        mc = MeasureCount.MeasureCount()
        mc.addSimpleBeats(counter, 4)
        self.measure.setBeatCount(mc)

    def get_output(self):
        handle = StringIO()
        indenter = fileUtils.Indenter(handle)
        dbfsv1.MeasureStructureV1().write(self.measure, indenter)
        return handle.getvalue().splitlines()

    def testWriteEmpty(self):
        output = self.get_output()
        self.assertEqual(output,
                         ['START_MEASURE',
                          '  START_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_MEASURE_COUNT',
                          '  STARTBARLINE 1',
                          '  ENDBARLINE 1',
                          '  REPEAT_COUNT 1',
                          '  SHOWABOVE False',
                          '  SHOWBELOW False',
                          'END_MEASURE'])

    def testWriteSimple(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "a")
        self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "b")
        self.measure.addNote(NotePosition(noteTime = 2, drumIndex = 0), "c")
        self.measure.addNote(NotePosition(noteTime = 3, drumIndex = 1), "d")
        self.measure.addNote(NotePosition(noteTime = 4, drumIndex = 0), "e")
        self.measure.addNote(NotePosition(noteTime = 5, drumIndex = 1), "f")
        self.measure.addNote(NotePosition(noteTime = 6, drumIndex = 0), "g")
        self.measure.addNote(NotePosition(noteTime = 7, drumIndex = 1), "h")
        self.measure.addNote(NotePosition(noteTime = 8, drumIndex = 0), "i")
        self.measure.addNote(NotePosition(noteTime = 9, drumIndex = 1), "j")
        self.measure.addNote(NotePosition(noteTime = 10, drumIndex = 0), "k")
        self.measure.addNote(NotePosition(noteTime = 11, drumIndex = 1), "l")
        self.measure.addNote(NotePosition(noteTime = 12, drumIndex = 0), "m")
        self.measure.addNote(NotePosition(noteTime = 13, drumIndex = 1), "n")
        self.measure.addNote(NotePosition(noteTime = 14, drumIndex = 0), "o")
        self.measure.addNote(NotePosition(noteTime = 15, drumIndex = 1), "p")
        output = self.get_output()
        self.assertEqual(output,
                         ['START_MEASURE',
                          '  START_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_MEASURE_COUNT',
                          '  STARTBARLINE 1',
                          '  NOTE 0,0,a',
                          '  NOTE 1,1,b',
                          '  NOTE 2,0,c',
                          '  NOTE 3,1,d',
                          '  NOTE 4,0,e',
                          '  NOTE 5,1,f',
                          '  NOTE 6,0,g',
                          '  NOTE 7,1,h',
                          '  NOTE 8,0,i',
                          '  NOTE 9,1,j',
                          '  NOTE 10,0,k',
                          '  NOTE 11,1,l',
                          '  NOTE 12,0,m',
                          '  NOTE 13,1,n',
                          '  NOTE 14,0,o',
                          '  NOTE 15,1,p',
                          '  ENDBARLINE 1',
                          '  REPEAT_COUNT 1',
                          '  SHOWABOVE False',
                          '  SHOWBELOW False',
                          'END_MEASURE'])

    def testWriteDecorations(self):
        self.measure.setLineBreak(True)
        self.measure.setSectionEnd(True)
        self.measure.setRepeatEnd(True)
        self.measure.setRepeatStart(True)
        self.measure.alternateText = "xxx"
        self.measure.repeatCount = 10
        self.measure.simileDistance = 2
        self.measure.simileIndex = 1
        self.measure.showAbove = True
        self.measure.setAbove(1, "R")
        output = self.get_output()
        self.assertEqual(output,
                         ['START_MEASURE',
                          '  START_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_MEASURE_COUNT',
                          '  STARTBARLINE 3',
                          '  ENDBARLINE 29',
                          '  REPEAT_COUNT 10',
                          '  ALTERNATE xxx',
                          '  SIMILE 2',
                          '  SIMINDEX 1',
                          '  SHOWABOVE True',
                          '  ABOVETEXT IFIgICAgICAgICAgICAgIA==',
                          '  SHOWBELOW False',
                          'END_MEASURE'])
Пример #35
0
 def testDeleteMeasure(self):
     self.staff.addMeasure(Measure(1))
     self.staff.addMeasure(Measure(2))
     self.staff.deleteMeasure(NotePosition(measureIndex=0))
     self.assertEqual(self.staff.numMeasures(), 1)
     self.assertEqual(len(self.staff), 2)
Пример #36
0
 def testCopyPasteWithDecorations(self):
     self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "x")
     self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "o")
     self.measure.setRepeatEnd(True)
     self.measure.setRepeatStart(True)
     self.measure.setLineBreak(True)
     self.measure.setSectionEnd(True)
     measure2 = Measure(8)
     self.assertFalse(measure2.isRepeatEnd())
     self.assertFalse(measure2.isRepeatStart())
     self.assertFalse(measure2.isLineBreak())
     self.assertFalse(measure2.isSectionEnd())
     copied = self.measure.copyMeasure()
     measure2.pasteMeasure(copied, True)
     self.assertEqual(len(measure2), 16)
     self.assertEqual(measure2.numNotes(), 2)
     self.assertEqual(measure2.getNote(NotePosition(None, None, 0, 0)), "x")
     self.assertEqual(measure2.getNote(NotePosition(None, None, 1, 1)), "o")
     self.assertTrue(measure2.isRepeatEnd())
     self.assertTrue(measure2.isRepeatStart())
     self.assertTrue(measure2.isLineBreak())
     self.assertTrue(measure2.isSectionEnd())
Пример #37
0
 def testCopyPasteWithDecorations(self):
     self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "x")
     self.measure.addNote(NotePosition(noteTime=1, drumIndex=1), "o")
     self.measure.setRepeatEnd(True)
     self.measure.setRepeatStart(True)
     self.measure.setLineBreak(True)
     self.measure.setSectionEnd(True)
     measure2 = Measure(8)
     self.assertFalse(measure2.isRepeatEnd())
     self.assertFalse(measure2.isRepeatStart())
     self.assertFalse(measure2.isLineBreak())
     self.assertFalse(measure2.isSectionEnd())
     copied = self.measure.copyMeasure()
     measure2.pasteMeasure(copied, True)
     self.assertEqual(len(measure2), 16)
     self.assertEqual(measure2.numNotes(), 2)
     self.assertEqual(measure2.getNote(NotePosition(None, None, 0, 0)), "x")
     self.assertEqual(measure2.getNote(NotePosition(None, None, 1, 1)), "o")
     self.assertTrue(measure2.isRepeatEnd())
     self.assertTrue(measure2.isRepeatStart())
     self.assertTrue(measure2.isLineBreak())
     self.assertTrue(measure2.isSectionEnd())
Пример #38
0
class TestCallBack(unittest.TestCase):
    def setUp(self):
        self.measure = Measure(16)
        self.calls = []
        def myCallBack(position):
            self.calls.append((position.noteTime, position.drumIndex))
        self.measure.setCallBack(myCallBack)

    def testAddNoteCallBack(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0))
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "x")
        self.assertEqual(len(self.calls), 1)
        self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "o")
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (1, 1))

    def testDeleteNoteCallBack(self):
        self.measure.deleteNote(NotePosition(noteTime = 0, drumIndex = 0))
        self.assertEqual(len(self.calls), 0)
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0))
        self.measure.deleteNote(NotePosition(noteTime = 0, drumIndex = 0))
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (0, 0))

    def testToggleNoteCallBack(self):
        np = NotePosition(noteTime = 0, drumIndex = 0)
        self.measure.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0))
        self.measure.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (0, 0))
        self.measure.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 3)
        self.assertEqual(self.calls[2], (0, 0))
        self.measure.toggleNote(np, "o")
        self.assertEqual(len(self.calls), 4)
        self.assertEqual(self.calls[2], (0, 0))

    def testClearMeasureCallback(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "x")
        self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "o")
        self.assertEqual(len(self.calls), 2)
        self.measure.clear()
        self.assertEqual(len(self.calls), 3)
        self.assertEqual(self.calls[2], (None, None))

    def testClearCallBack(self):
        self.measure.clearCallBack()
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "x")
        self.assertEqual(len(self.calls), 0)
Пример #39
0
class TestCallBack(unittest.TestCase):
    def setUp(self):
        self.measure = Measure(16)
        self.calls = []

        def myCallBack(position):
            self.calls.append((position.noteTime, position.drumIndex))

        self.measure.setCallBack(myCallBack)

    def testAddNoteCallBack(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0))
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "x")
        self.assertEqual(len(self.calls), 1)
        self.measure.addNote(NotePosition(noteTime=1, drumIndex=1), "o")
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (1, 1))

    def testDeleteNoteCallBack(self):
        self.measure.deleteNote(NotePosition(noteTime=0, drumIndex=0))
        self.assertEqual(len(self.calls), 0)
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0))
        self.measure.deleteNote(NotePosition(noteTime=0, drumIndex=0))
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (0, 0))

    def testToggleNoteCallBack(self):
        np = NotePosition(noteTime=0, drumIndex=0)
        self.measure.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 1)
        self.assertEqual(self.calls[0], (0, 0))
        self.measure.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 2)
        self.assertEqual(self.calls[1], (0, 0))
        self.measure.toggleNote(np, "x")
        self.assertEqual(len(self.calls), 3)
        self.assertEqual(self.calls[2], (0, 0))
        self.measure.toggleNote(np, "o")
        self.assertEqual(len(self.calls), 4)
        self.assertEqual(self.calls[2], (0, 0))

    def testClearMeasureCallback(self):
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "x")
        self.measure.addNote(NotePosition(noteTime=1, drumIndex=1), "o")
        self.assertEqual(len(self.calls), 2)
        self.measure.clear()
        self.assertEqual(len(self.calls), 3)
        self.assertEqual(self.calls[2], (None, None))

    def testClearCallBack(self):
        self.measure.clearCallBack()
        self.measure.addNote(NotePosition(noteTime=0, drumIndex=0), "x")
        self.assertEqual(len(self.calls), 0)
Пример #40
0
class TestMeasure(unittest.TestCase):
    reg = CounterRegistry()

    def setUp(self):
        self.measure = Measure(16)
        counter = self.reg.getCounterByName("16ths")
        mc = MeasureCount()
        mc.addSimpleBeats(counter, 4)
        self.measure.setBeatCount(mc)

    def testCount(self):
        count = self.measure.count()
        self.assertEqual(count,
                         ["1", "e", "+", "a",
                          "2", "e", "+", "a",
                          "3", "e", "+", "a",
                          "4", "e", "+", "a"])
        measure = Measure(16)
        self.assertEqual(measure.count(), [" "] * 16)

    def testEmptyMeasure(self):
        self.assertEqual(len(self.measure), 16)
        self.assertEqual(self.measure.numNotes(), 0)
        self.assertEqual(self.measure.getNote(NotePosition(noteTime = 0,
                                                           drumIndex = 0)),
                         EMPTY_NOTE)
        self.assertFalse(self.measure.isSectionEnd())
        self.assertFalse(self.measure.isRepeatEnd())
        self.assertFalse(self.measure.isRepeatStart())

    def testIsEmpty_True(self):
        self.assert_(self.measure.isEmpty())

    def testIsEmpty_False(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "o")
        self.assertFalse(self.measure.isEmpty())

    def testGetNote_BadTime(self):
        self.assertRaises(BadTimeError, self.measure.getNote,
                          NotePosition(noteTime = -1, drumIndex = 0))
        self.assertRaises(BadTimeError, self.measure.getNote,
                          NotePosition(noteTime = 20, drumIndex = 0))

    def testNumNotes(self):
        for i in range(0, 16):
            self.measure.addNote(NotePosition(noteTime = i, drumIndex = 0), "o")
        self.assertEqual(self.measure.numNotes(), 16)

    def testAddNote(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "o")
        notePos = NotePosition(noteTime = 0, drumIndex = 0)
        self.assertEqual(self.measure.getNote(notePos), "o")

    def testAddNote_BadTime(self):
        self.assertRaises(BadTimeError, self.measure.addNote,
                          NotePosition(noteTime = -1, drumIndex = 0), "x")
        self.assertRaises(BadTimeError, self.measure.addNote,
                          NotePosition(noteTime = 20, drumIndex = 0), "x")

    def testIterNotes(self):
        for i in range(0, 4):
            self.measure.addNote(NotePosition(noteTime = 4 * i,
                                              drumIndex = i), str(i))
        for i, (np, head) in enumerate(self.measure):
            self.assertEqual(head, str(i))
            self.assertEqual(np.noteTime, 4 * i)
            self.assertEqual(np.drumIndex, i)


    def testDeleteNote(self):
        np = NotePosition(noteTime = 0, drumIndex = 0)
        self.measure.addNote(np, "o")
        self.measure.deleteNote(np)
        self.assertEqual(self.measure.numNotes(), 0)
        self.assertEqual(self.measure.getNote(np), EMPTY_NOTE)

    def testDeleteNote_BadTime(self):
        self.assertRaises(BadTimeError, self.measure.deleteNote,
                          NotePosition(noteTime = -1, drumIndex = 0))
        self.assertRaises(BadTimeError, self.measure.deleteNote,
                          NotePosition(noteTime = 20, drumIndex = 0))

    def testToggleNote(self):
        np = NotePosition(noteTime = 0, drumIndex = 0)
        self.measure.toggleNote(np, "o")
        self.assertEqual(self.measure.getNote(np), "o")
        self.assertEqual(self.measure.numNotes(), 1)
        self.measure.toggleNote(np, "o")
        self.assertEqual(self.measure.numNotes(), 0)
        self.assertEqual(self.measure.getNote(np), EMPTY_NOTE)

    def testToggleNote_ChangeNote(self):
        np = NotePosition(noteTime = 0, drumIndex = 0)
        self.measure.toggleNote(np, "o")
        self.measure.toggleNote(np, "x")
        self.assertEqual(self.measure.getNote(np), "x")

    def testToggleNote_BadTime(self):
        self.assertRaises(BadTimeError, self.measure.toggleNote,
                          NotePosition(noteTime = -1, drumIndex = 0), "x")
        self.assertRaises(BadTimeError, self.measure.toggleNote,
                          NotePosition(noteTime = 20, drumIndex = 0), "x")

    def testSetSectionEnd_NoRepeat(self):
        self.assertFalse(self.measure.isSectionEnd())
        self.assertFalse(self.measure.isLineEnd())
        self.measure.setSectionEnd(True)
        self.assert_(self.measure.isSectionEnd())
        self.assert_(self.measure.isLineEnd())
        self.measure.setSectionEnd(False)
        self.assertFalse(self.measure.isSectionEnd())
        self.assertFalse(self.measure.isLineEnd())

    def testSetSectionEnd_Repeat(self):
        self.measure.setRepeatEnd(True)
        self.assertFalse(self.measure.isSectionEnd())
        self.measure.setSectionEnd(True)
        self.assert_(self.measure.isSectionEnd())
        self.assert_(self.measure.isRepeatEnd())
        self.measure.setSectionEnd(False)
        self.assertFalse(self.measure.isSectionEnd())
        self.assert_(self.measure.isRepeatEnd())
        self.measure.setRepeatEnd(False)
        self.assertFalse(self.measure.isSectionEnd())
        self.assertFalse(self.measure.isRepeatEnd())

    def testSetRepeatStart(self):
        self.measure.setRepeatStart(True)
        self.assert_(self.measure.isRepeatStart())
        self.measure.setRepeatStart(False)
        self.assertFalse(self.measure.isRepeatStart())

    def testSetRepeatEnd_NotSectionEnd(self):
        self.measure.setRepeatEnd(True)
        self.assert_(self.measure.isRepeatEnd())
        self.measure.setRepeatEnd(False)
        self.assertFalse(self.measure.isRepeatEnd())

    def testSetRepeatEnd_IsSectionEnd(self):
        self.measure.setSectionEnd(True)
        self.measure.setRepeatEnd(True)
        self.assert_(self.measure.isRepeatEnd())
        self.measure.setRepeatEnd(False)
        self.assertFalse(self.measure.isRepeatEnd())

    def testLineBreak(self):
        self.assertFalse(self.measure.isLineBreak())
        self.assertFalse(self.measure.isLineEnd())
        self.measure.setLineBreak(True)
        self.assert_(self.measure.isLineBreak())
        self.assert_(self.measure.isLineEnd())
        self.measure.setLineBreak(False)
        self.assertFalse(self.measure.isLineBreak())
        self.assertFalse(self.measure.isLineEnd())

    def testClearMeasure(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "x")
        self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "o")
        self.assertEqual(self.measure.numNotes(), 2)
        self.assertFalse(self.measure.isEmpty())
        self.measure.clear()
        self.assert_(self.measure.isEmpty())

    def testCopyPaste(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "x")
        self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "o")
        measure2 = Measure(8)
        copied = self.measure.copyMeasure()
        measure2.pasteMeasure(copied)
        self.assertEqual(len(measure2), 16)
        self.assertEqual(measure2.numNotes(), 2)
        self.assertEqual(measure2.getNote(NotePosition(None, None, 0, 0)), "x")
        self.assertEqual(measure2.getNote(NotePosition(None, None, 1, 1)), "o")

    def testCopyPasteWithDecorations(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "x")
        self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "o")
        self.measure.setRepeatEnd(True)
        self.measure.setRepeatStart(True)
        self.measure.setLineBreak(True)
        self.measure.setSectionEnd(True)
        measure2 = Measure(8)
        self.assertFalse(measure2.isRepeatEnd())
        self.assertFalse(measure2.isRepeatStart())
        self.assertFalse(measure2.isLineBreak())
        self.assertFalse(measure2.isSectionEnd())
        copied = self.measure.copyMeasure()
        measure2.pasteMeasure(copied, True)
        self.assertEqual(len(measure2), 16)
        self.assertEqual(measure2.numNotes(), 2)
        self.assertEqual(measure2.getNote(NotePosition(None, None, 0, 0)), "x")
        self.assertEqual(measure2.getNote(NotePosition(None, None, 1, 1)), "o")
        self.assertTrue(measure2.isRepeatEnd())
        self.assertTrue(measure2.isRepeatStart())
        self.assertTrue(measure2.isLineBreak())
        self.assertTrue(measure2.isSectionEnd())

    def testChangeCount_Shorter(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "a")
        self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "b")
        self.measure.addNote(NotePosition(noteTime = 2, drumIndex = 0), "c")
        self.measure.addNote(NotePosition(noteTime = 3, drumIndex = 1), "d")
        self.measure.addNote(NotePosition(noteTime = 4, drumIndex = 0), "e")
        self.measure.addNote(NotePosition(noteTime = 5, drumIndex = 1), "f")
        self.measure.addNote(NotePosition(noteTime = 6, drumIndex = 0), "g")
        self.measure.addNote(NotePosition(noteTime = 7, drumIndex = 1), "h")
        self.measure.addNote(NotePosition(noteTime = 8, drumIndex = 0), "i")
        self.measure.addNote(NotePosition(noteTime = 9, drumIndex = 1), "j")
        self.measure.addNote(NotePosition(noteTime = 10, drumIndex = 0), "k")
        self.measure.addNote(NotePosition(noteTime = 11, drumIndex = 1), "l")
        self.measure.addNote(NotePosition(noteTime = 12, drumIndex = 0), "m")
        self.measure.addNote(NotePosition(noteTime = 13, drumIndex = 1), "n")
        self.measure.addNote(NotePosition(noteTime = 14, drumIndex = 0), "o")
        self.measure.addNote(NotePosition(noteTime = 15, drumIndex = 1), "p")
        counter = self.reg.getCounterByName("8ths")
        mc = MeasureCount()
        mc.addSimpleBeats(counter, 3)
        self.measure.setBeatCount(mc)
        self.assertEqual(len(self.measure), 6)
        self.assertEqual(self.measure.numNotes(), 6)
        self.assertEqual(self.measure.noteAt(noteTime = 0, drumIndex = 0), "a")
        self.assertEqual(self.measure.noteAt(noteTime = 1, drumIndex = 0), "c")
        self.assertEqual(self.measure.noteAt(noteTime = 2, drumIndex = 0), "e")
        self.assertEqual(self.measure.noteAt(noteTime = 3, drumIndex = 0), "g")
        self.assertEqual(self.measure.noteAt(noteTime = 4, drumIndex = 0), "i")
        self.assertEqual(self.measure.noteAt(noteTime = 5, drumIndex = 0), "k")


    def testChangeCount_Longer(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "a")
        self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "b")
        self.measure.addNote(NotePosition(noteTime = 2, drumIndex = 0), "c")
        self.measure.addNote(NotePosition(noteTime = 3, drumIndex = 1), "d")
        self.measure.addNote(NotePosition(noteTime = 4, drumIndex = 0), "e")
        self.measure.addNote(NotePosition(noteTime = 5, drumIndex = 1), "f")
        self.measure.addNote(NotePosition(noteTime = 6, drumIndex = 0), "g")
        self.measure.addNote(NotePosition(noteTime = 7, drumIndex = 1), "h")
        self.measure.addNote(NotePosition(noteTime = 8, drumIndex = 0), "i")
        self.measure.addNote(NotePosition(noteTime = 9, drumIndex = 1), "j")
        self.measure.addNote(NotePosition(noteTime = 10, drumIndex = 0), "k")
        self.measure.addNote(NotePosition(noteTime = 11, drumIndex = 1), "l")
        self.measure.addNote(NotePosition(noteTime = 12, drumIndex = 0), "m")
        self.measure.addNote(NotePosition(noteTime = 13, drumIndex = 1), "n")
        self.measure.addNote(NotePosition(noteTime = 14, drumIndex = 0), "o")
        self.measure.addNote(NotePosition(noteTime = 15, drumIndex = 1), "p")
        counter = self.reg.getCounterByName("32nds")
        mc = MeasureCount()
        mc.addSimpleBeats(counter, 5)
        self.measure.setBeatCount(mc)
        self.assertEqual(len(self.measure), 40)
        self.assertEqual(self.measure.numNotes(), 16)
        self.assertEqual(self.measure.noteAt(noteTime = 0, drumIndex = 0), "a")
        self.assertEqual(self.measure.noteAt(noteTime = 2, drumIndex = 1), "b")
        self.assertEqual(self.measure.noteAt(noteTime = 4, drumIndex = 0), "c")
        self.assertEqual(self.measure.noteAt(noteTime = 6, drumIndex = 1), "d")
        self.assertEqual(self.measure.noteAt(noteTime = 8, drumIndex = 0), "e")
        self.assertEqual(self.measure.noteAt(noteTime = 10, drumIndex = 1), "f")
        self.assertEqual(self.measure.noteAt(noteTime = 12, drumIndex = 0), "g")
        self.assertEqual(self.measure.noteAt(noteTime = 14, drumIndex = 1), "h")
        self.assertEqual(self.measure.noteAt(noteTime = 16, drumIndex = 0), "i")
        self.assertEqual(self.measure.noteAt(noteTime = 18, drumIndex = 1), "j")
        self.assertEqual(self.measure.noteAt(noteTime = 20, drumIndex = 0), "k")
        self.assertEqual(self.measure.noteAt(noteTime = 22, drumIndex = 1), "l")
        self.assertEqual(self.measure.noteAt(noteTime = 24, drumIndex = 0), "m")
        self.assertEqual(self.measure.noteAt(noteTime = 26, drumIndex = 1), "n")
        self.assertEqual(self.measure.noteAt(noteTime = 28, drumIndex = 0), "o")
        self.assertEqual(self.measure.noteAt(noteTime = 30, drumIndex = 1), "p")

    def testLineIsVisible(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "a")
        self.measure.addNote(NotePosition(noteTime = 2, drumIndex = 2), "a")
        self.measure.addNote(NotePosition(noteTime = 3, drumIndex = 7), "a")
        self.assert_(self.measure.lineIsVisible(0))
        self.assert_(self.measure.lineIsVisible(2))
        self.assert_(self.measure.lineIsVisible(7))
        self.assertFalse(self.measure.lineIsVisible(1))
        self.assertFalse(self.measure.lineIsVisible(3))
        self.assertFalse(self.measure.lineIsVisible(4))
        self.assertFalse(self.measure.lineIsVisible(5))
        self.assertFalse(self.measure.lineIsVisible(6))
        self.assertFalse(self.measure.lineIsVisible(8))
Пример #41
0
class TestWrite(unittest.TestCase):
    reg = CounterRegistry()

    def setUp(self):
        self.measure = Measure(16)
        counter = self.reg.getCounterByName("16ths")
        mc = MeasureCount()
        mc.addSimpleBeats(counter, 4)
        self.measure.setBeatCount(mc)

    def get_output(self):
        handle = StringIO()
        indenter = fileUtils.Indenter(handle)
        self.measure.write(indenter)
        return handle.getvalue().splitlines()

    def testWriteEmpty(self):
        output = self.get_output()
        self.assertEqual(output,
                         ['START_BAR 16',
                          '  COUNT_INFO_START',
                          '    REPEAT_BEATS 4',
                          '    BEAT_START',
                          '      COUNT |^e+a|',
                          '    BEAT_END',
                          '  COUNT_INFO_END',
                          '  BARLINE NORMAL_BAR,NO_BAR',
                          '  BARLINE NORMAL_BAR,NO_BAR',
                          'END_BAR'])

    def testWriteSimple(self):
        self.measure.addNote(NotePosition(noteTime = 0, drumIndex = 0), "a")
        self.measure.addNote(NotePosition(noteTime = 1, drumIndex = 1), "b")
        self.measure.addNote(NotePosition(noteTime = 2, drumIndex = 0), "c")
        self.measure.addNote(NotePosition(noteTime = 3, drumIndex = 1), "d")
        self.measure.addNote(NotePosition(noteTime = 4, drumIndex = 0), "e")
        self.measure.addNote(NotePosition(noteTime = 5, drumIndex = 1), "f")
        self.measure.addNote(NotePosition(noteTime = 6, drumIndex = 0), "g")
        self.measure.addNote(NotePosition(noteTime = 7, drumIndex = 1), "h")
        self.measure.addNote(NotePosition(noteTime = 8, drumIndex = 0), "i")
        self.measure.addNote(NotePosition(noteTime = 9, drumIndex = 1), "j")
        self.measure.addNote(NotePosition(noteTime = 10, drumIndex = 0), "k")
        self.measure.addNote(NotePosition(noteTime = 11, drumIndex = 1), "l")
        self.measure.addNote(NotePosition(noteTime = 12, drumIndex = 0), "m")
        self.measure.addNote(NotePosition(noteTime = 13, drumIndex = 1), "n")
        self.measure.addNote(NotePosition(noteTime = 14, drumIndex = 0), "o")
        self.measure.addNote(NotePosition(noteTime = 15, drumIndex = 1), "p")
        output = self.get_output()
        self.assertEqual(output,
                         ['START_BAR 16',
                          '  COUNT_INFO_START',
                          '    REPEAT_BEATS 4',
                          '    BEAT_START',
                          '      COUNT |^e+a|',
                          '    BEAT_END',
                          '  COUNT_INFO_END',
                          '  BARLINE NORMAL_BAR,NO_BAR',
                          '  NOTE 0,0,a',
                          '  NOTE 1,1,b',
                          '  NOTE 2,0,c',
                          '  NOTE 3,1,d',
                          '  NOTE 4,0,e',
                          '  NOTE 5,1,f',
                          '  NOTE 6,0,g',
                          '  NOTE 7,1,h',
                          '  NOTE 8,0,i',
                          '  NOTE 9,1,j',
                          '  NOTE 10,0,k',
                          '  NOTE 11,1,l',
                          '  NOTE 12,0,m',
                          '  NOTE 13,1,n',
                          '  NOTE 14,0,o',
                          '  NOTE 15,1,p',
                          '  BARLINE NORMAL_BAR,NO_BAR',
                          'END_BAR'])

    def testWriteDecorations(self):
        self.measure.setLineBreak(True)
        self.measure.setSectionEnd(True)
        self.measure.setRepeatEnd(True)
        self.measure.setRepeatStart(True)
        self.measure.alternateText = "xxx"
        self.measure.repeatCount = 10
        output = self.get_output()
        self.assertEqual(output,
                         ['START_BAR 16',
                          '  COUNT_INFO_START',
                          '    REPEAT_BEATS 4',
                          '    BEAT_START',
                          '      COUNT |^e+a|',
                          '    BEAT_END',
                          '  COUNT_INFO_END',
                          '  BARLINE NORMAL_BAR,REPEAT_START,NO_BAR',
                          ('  BARLINE NORMAL_BAR,LINE_BREAK,NO_BAR,' +
                           'SECTION_END,REPEAT_END'),
                          '  REPEAT_COUNT 10',
                          '  ALTERNATE xxx',
                          'END_BAR'])
Пример #42
0
 def testGetMeasureByIndex(self):
     for i in range(1, 16):
         self.staff.addMeasure(Measure(i))
     for i in range(1, 16):
         self.assertEqual(len(self.staff[i - 1]), i)
Пример #43
0
 def testIterateOverMeasures(self):
     for i in range(1, 16):
         self.staff.addMeasure(Measure(i))
     for i, measure in enumerate(self.staff):
         self.assertEqual(len(measure), i + 1)