Ejemplo n.º 1
0
 def getKit(self):
     item = self.defaultKitList.currentItem()
     isUser = item.data(_IS_USER_KIT).toBool()
     kitName = unicode(item.text())
     if isUser:
         kitString = str(self._settings.value(kitName).toString())
         handle = StringIO(kitString)
         dbfile = fileUtils.dbFileIterator(handle)
         kit = DrumKit.DrumKit()
         kit.read(dbfile)
         return kit
     else:
         return DrumKit.getNamedDefaultKit(kitName)
Ejemplo n.º 2
0
 def getValues(self):
     mc = self.measureTabs.getCounter()
     kitName = unicode(self.kitCombobox.currentText())
     kitIndex = self.kitCombobox.currentIndex()
     isUserKit = self.kitCombobox.itemData(kitIndex).toBool()
     if isUserKit:
         kitString = str(self._settings.value(kitName).toString())
         handle = StringIO(kitString)
         dbfile = fileUtils.dbFileIterator(handle)
         kit = DrumKit.DrumKit()
         kit.read(dbfile)
     else:
         kit = DrumKit.getNamedDefaultKit(kitName)
     return (self.numMeasuresSpinBox.value(), mc, kit)
Ejemplo n.º 3
0
 def testWrite(self):
     kit = DrumKit.DrumKit()
     drum = Drum("One", "d1", "x", True)
     drum.addNoteHead("x", HeadData())
     drum.addNoteHead("g", HeadData(effect="ghost", notationEffect="ghost"))
     drum.checkShortcuts()
     kit.addDrum(drum)
     drum = Drum("Two", "d2", "o")
     drum.addNoteHead("o", HeadData(notationLine=-5, stemDirection=1))
     drum.addNoteHead(
         "O",
         HeadData(effect="accent",
                  notationEffect="accent",
                  notationLine=-5,
                  stemDirection=1))
     drum.checkShortcuts()
     kit.addDrum(drum)
     handle = StringIO()
     indenter = fileUtils.Indenter(handle)
     dbfsv0.DrumKitStructureV0().write(kit, indenter)
     outlines = handle.getvalue().splitlines()
     self.assertEqual(outlines, [
         "KIT_START", "  DRUM One,d1,x,True",
         "    NOTEHEAD x 71,96,normal,default,0,none,0,x",
         "    NOTEHEAD g 71,96,ghost,default,0,ghost,0,g",
         "  DRUM Two,d2,o,False",
         "    NOTEHEAD o 71,96,normal,default,-5,none,1,o",
         "    NOTEHEAD O 71,96,accent,default,-5,accent,1,a", "KIT_END"
     ])
Ejemplo n.º 4
0
 def testStaffs(self):
     score = Score()
     settings = ASCIISettings()
     settings.omitEmpty = False
     score.drumKit = DrumKit.DrumKit()
     score.drumKit.addDrum(Drum.Drum("HiHat", "Hh", "x"))
     score.drumKit.addDrum(Drum.Drum("Crash", "Cr", "x"))
     counter = MeasureCount.counterMaker(4, 16)
     score.insertMeasureByIndex(16, counter=counter)
     score.insertMeasureByIndex(16, counter=counter)
     score.insertMeasureByIndex(16, counter=counter)
     score.addNote(NotePosition(0, 0, 0, 0), "x")
     score.addNote(NotePosition(0, 1, 0, 0), "y")
     score.addNote(NotePosition(0, 2, 0, 0), "z")
     score.formatScore(40)
     output = self.getOutput(score, settings)
     self.assertEqual(output, [
         'Tabbed with DrumBurp, a drum tab editor from www.whatang.org', '',
         'Title     : ', 'Artist    : ', 'BPM       : 120', 'Tabbed by : ',
         'Date      : ' + self.exportDate, '', 'Cr - Crash', 'Hh - HiHat',
         '', 'Cr|----------------|----------------|',
         'Hh|x---------------|y---------------|',
         '   1e+a2e+a3e+a4e+a 1e+a2e+a3e+a4e+a ', '',
         'Cr|----------------|', 'Hh|z---------------|',
         '   1e+a2e+a3e+a4e+a ', '',
         'Tabbed with DrumBurp, a drum tab editor from www.whatang.org'
     ])
Ejemplo n.º 5
0
 def testDeleteDrumByIndex(self):
     self.kit = DrumKit.getNamedDefaultKit()
     numDrums = len(self.kit)
     self.assert_(numDrums > 0)
     drum = self.kit[0]
     self.kit.deleteDrum(index = 0)
     self.assertEqual(len(self.kit), numDrums - 1)
     for remainingDrum in self.kit:
         self.assertNotEqual(drum, remainingDrum)
Ejemplo n.º 6
0
 def getNewKit(self):
     newKit = DrumKit.DrumKit()
     oldLines = []
     for drum in reversed(self._currentKit):
         newKit.addDrum(drum)
         if self._oldLines[drum] == -1:
             oldLines.append(-1)
         else:
             oldLines.append(len(self._initialKit)
                             - self._oldLines[drum] - 1)
     return newKit, oldLines
Ejemplo n.º 7
0
def main():
    from PyQt4.QtGui import QApplication
    import sys
    app = QApplication(sys.argv)
    app.setOrganizationName("Whatang Software")
    app.setOrganizationDomain("whatang.org")
    app.setApplicationName("DefaultKitManagerTest")
    oldkit = DrumKit.getNamedDefaultKit()
    dialog = QDefaultKitManager(oldkit)
    dialog.show()
    app.exec_()
    if dialog.result():
        print dialog.getKit()
Ejemplo n.º 8
0
 def getKit(self):
     item = self.defaultKitList.currentItem()
     isUser = item.data(_IS_USER_KIT).toBool()
     kitName = unicode(item.text())
     if isUser:
         kitString = str(self._settings.value(kitName).toString())
         handle = StringIO(kitString)
         dbfile = fileUtils.dbFileIterator(handle)
         kit = DrumKit.DrumKit()
         kit.read(dbfile)
         return kit
     else:
         return DrumKit.getNamedDefaultKit(kitName)
Ejemplo n.º 9
0
def main():
    from PyQt4.QtGui import QApplication
    import sys
    app = QApplication(sys.argv)
    app.setOrganizationName("Whatang Software")
    app.setOrganizationDomain("whatang.org")
    app.setApplicationName("DefaultKitManagerTest")
    oldkit = DrumKit.getNamedDefaultKit()
    dialog = QDefaultKitManager(oldkit)
    dialog.show()
    app.exec_()
    if dialog.result():
        print dialog.getKit()
Ejemplo n.º 10
0
 def testWithKit(self):
     score = Score()
     settings = ASCIISettings()
     score.drumKit = DrumKit.DrumKit()
     score.drumKit.addDrum(Drum.Drum("HiHat", "Hh", "x"))
     score.drumKit.addDrum(Drum.Drum("Crash", "Cr", "x"))
     output = self.getOutput(score, settings)
     self.assertEqual(output, [
         'Tabbed with DrumBurp, a drum tab editor from www.whatang.org', '',
         'Title     : ', 'Artist    : ', 'BPM       : 120', 'Tabbed by : ',
         'Date      : ' + self.exportDate, '', 'Cr - Crash', 'Hh - HiHat',
         '', 'Tabbed with DrumBurp, a drum tab editor from www.whatang.org'
     ])
Ejemplo n.º 11
0
 def getValues(self):
     mc = self.measureTabs.getCounter()
     kitName = unicode(self.kitCombobox.currentText())
     kitIndex = self.kitCombobox.currentIndex()
     isUserKit = self.kitCombobox.itemData(kitIndex).toBool()
     if isUserKit:
         kitString = str(self._settings.value(kitName).toString())
         handle = StringIO(kitString)
         dbfile = fileUtils.dbFileIterator(handle)
         kit = DrumKit.DrumKit()
         kit.read(dbfile)
     else:
         kit = DrumKit.getNamedDefaultKit(kitName)
     return (self.numMeasuresSpinBox.value(), mc, kit)
Ejemplo n.º 12
0
 def testRead_NoNoteHeads(self):
     kitData = """KIT_START
     DRUM Snare,Sn,x,True
     DRUM Kick,Bd,o,True
     KIT_END
     """
     handle = StringIO(kitData)
     iterator = fileUtils.dbFileIterator(handle)
     kit = DrumKit.DrumKit()
     kit.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)
Ejemplo n.º 13
0
 def testRead_BadLine(self):
     kitData = """KIT_START
     DRUM Snare,Sn,x,True
     NOTEHEAD x 1,100,default
     NOTEHEAD g 1,50,ghost
     DRUM Kick,Bd,o,True
     NOTEHEAD o 2,100,default
     NOTEHEAD O 2,127,accent
     BAD_LINE
     KIT_END
     """
     handle = StringIO(kitData)
     iterator = fileUtils.dbFileIterator(handle)
     kit = DrumKit.DrumKit()
     self.assertRaises(DBErrors.UnrecognisedLine, kit.read, iterator)
Ejemplo n.º 14
0
 def testNoteHeads(self):
     kitData = """KIT_START
     DRUM Snare,Sn,x,True
     NOTEHEAD x 1,100,default
     NOTEHEAD g 1,50,ghost
     DRUM Kick,Bd,o,True
     NOTEHEAD o 2,100,default
     NOTEHEAD O 2,127,accent
     KIT_END
     """
     handle = StringIO(kitData)
     iterator = fileUtils.dbFileIterator(handle)
     kit = DrumKit.DrumKit()
     kit.read(iterator)
     self.assertEqual(kit.getDefaultHead(0), "x")
     self.assertEqual(kit.getDefaultHead(1), "o")
     self.assertEqual(kit.allowedNoteHeads(0),
                      ["x", "g"])
     self.assertEqual(kit.shortcutsAndNoteHeads(0), [("x", "x"), ("g", "g")])
Ejemplo n.º 15
0
 def testRead_NewNoteHeads(self):
     kitData = """KIT_START
     DRUM Snare,Sn,x,True
     NOTEHEAD x 1,100,normal,default,0,none,0,x
     NOTEHEAD g 1,50,ghost,default,0,ghost,0,g
     DRUM Kick,Bd,o,True
     NOTEHEAD o 2,100,normal,default,-5,none,1,o
     NOTEHEAD O 2,127,accent,default,-5,accent,1,a
     KIT_END
     """
     handle = StringIO(kitData)
     iterator = fileUtils.dbFileIterator(handle)
     kit = DrumKit.DrumKit()
     kit.read(iterator)
     self.assertEqual(len(kit), 2)
     self.assertEqual(len(kit), 2)
     self.assertEqual(kit[0].name, "Snare")
     self.assertEqual(len(kit[0]), 2)
     self.assertEqual(kit[1].name, "Kick")
     self.assertEqual(len(kit[1]), 2)
Ejemplo n.º 16
0
 def _loadKit(self):
     directory = self._scoreDirectory
     if directory is None:
         home = QDesktopServices.HomeLocation
         directory = unicode(QDesktopServices.storageLocation(home))
     fname = QFileDialog.getOpenFileName(parent = self,
                                         caption = "Load DrumBurp kit",
                                         directory = directory,
                                         filter = _KIT_FILTER)
     if len(fname) == 0:
         return
     with open(fname, 'rU') as handle:
         fileIterator = fileUtils.dbFileIterator(handle)
         newKit = DrumKit.DrumKit()
         newKit.read(fileIterator)
     self._currentKit = list(reversed(newKit))
     self._oldLines.clear()
     for drum in self._currentKit:
         self._oldLines[drum] = -1
     self._populate()
Ejemplo n.º 17
0
 def testDeleteDrumByIndex_BadIndex(self):
     self.kit = DrumKit.getNamedDefaultKit()
     self.assertRaises(NoSuchDrumError,
                       self.kit.deleteDrum, index = -1)
     self.assertRaises(NoSuchDrumError,
                       self.kit.deleteDrum, index = len(self.kit))
Ejemplo n.º 18
0
 def testDeleteDrumByName_DrumNotFound(self):
     self.kit = DrumKit.getNamedDefaultKit()
     self.assertRaises(NoSuchDrumError,
                       self.kit.deleteDrum, name = "no such drum")
Ejemplo n.º 19
0
 def emptyKit():
     return DrumKit.DrumKit()
Ejemplo n.º 20
0
 def testWrite(self):
     kit = DrumKit.DrumKit()
     drum = Drum("One", "d1", "x", True)
     drum.addNoteHead("x", HeadData())
     drum.addNoteHead("g",
                      HeadData(effect="ghost", notationEffect="ghost"))
     drum.checkShortcuts()
     kit.addDrum(drum)
     drum = Drum("Two", "d2", "o")
     drum.addNoteHead("o", HeadData(notationLine=-5, stemDirection=1))
     drum.addNoteHead("O", HeadData(effect="accent",
                                    notationEffect="accent",
                                    notationLine=-5, stemDirection=1))
     drum.checkShortcuts()
     kit.addDrum(drum)
     handle = StringIO()
     indenter = fileUtils.Indenter(handle)
     dbfsv1.DrumKitStructureV1().write(kit, indenter)
     outlines = handle.getvalue().splitlines()
     self.assertEqual(outlines,
                      ['START_KIT',
                       '  START_DRUM',
                       '    NAME One',
                       '    ABBR d1',
                       '    DEFAULT_HEAD x',
                       '    LOCKED True',
                       '    HEADLIST xg',
                       '    START_NOTEHEAD',
                       '      MIDINOTE 71',
                       '      MIDIVOLUME 96',
                       '      EFFECT normal',
                       '      NOTATIONHEAD default',
                       '      NOTATIONLINE 0',
                       '      NOTATIONEFFECT none',
                       '      STEM 0',
                       '      SHORTCUT x',
                       '    END_NOTEHEAD',
                       '    START_NOTEHEAD',
                       '      MIDINOTE 71',
                       '      MIDIVOLUME 96',
                       '      EFFECT ghost',
                       '      NOTATIONHEAD default',
                       '      NOTATIONLINE 0',
                       '      NOTATIONEFFECT ghost',
                       '      STEM 0',
                       '      SHORTCUT g',
                       '    END_NOTEHEAD',
                       '  END_DRUM',
                       '  START_DRUM',
                       '    NAME Two',
                       '    ABBR d2',
                       '    DEFAULT_HEAD o',
                       '    LOCKED False',
                       '    HEADLIST oO',
                       '    START_NOTEHEAD',
                       '      MIDINOTE 71',
                       '      MIDIVOLUME 96',
                       '      EFFECT normal',
                       '      NOTATIONHEAD default',
                       '      NOTATIONLINE -5',
                       '      NOTATIONEFFECT none',
                       '      STEM 1',
                       '      SHORTCUT o',
                       '    END_NOTEHEAD',
                       '    START_NOTEHEAD',
                       '      MIDINOTE 71',
                       '      MIDIVOLUME 96',
                       '      EFFECT accent',
                       '      NOTATIONHEAD default',
                       '      NOTATIONLINE -5',
                       '      NOTATIONEFFECT accent',
                       '      STEM 1',
                       '      SHORTCUT a',
                       '    END_NOTEHEAD',
                       '  END_DRUM',
                       'END_KIT'])
Ejemplo n.º 21
0
 def setUp(self):
     self.kit = DrumKit.DrumKit()
Ejemplo n.º 22
0
 def testLoadDefault(self):
     self.kit = DrumKit.getNamedDefaultKit()
     self.assert_(len(self.kit) > 0)
Ejemplo n.º 23
0
def main():
    from PyQt4.QtGui import QApplication
    import sys
    app = QApplication(sys.argv)
    kit = DrumKit.getNamedDefaultKit()
    dialog = QEditKitDialog(kit, [kit[0]])
    dialog.show()
    app.exec_()
    if dialog.result():
        kitname, ok = QInputDialog.getText(None, "Enter new kit name",
                                           "Kit name")
        if not ok:
            return
        kitname = unicode(kitname)
        kitvar = kitname.upper()
        kitvar = "".join([ch if ch.isalnum() else "_" for ch in kitvar])
        kitvar = "_" + kitvar
        newKit, changes_ = dialog.getNewKit()
        lines = []
        indent = '%s_DRUMS = [' % kitvar
        for drum in newKit:
            line = indent
            headData = drum.headData(drum.head)
            values = (drum.name, drum.abbr, drum.head, str(drum.locked),
                      headData.midiNote, headData.notationHead,
                      headData.notationLine,
                      "UP" if headData.stemDirection == DrumKit.STEM_UP
                      else "DOWN")
            line += '(("%s", "%s", "%s", %s), %d, "%s", %d, STEM_%s)' % values
            lines.append(line)
            indent = " " * len(indent)
        lines = ("," + os.linesep).join(lines) + "]"
        print lines
        indent = '%s_HEADS = {' % kitvar
        lines = []
        volumeSymbols = {GHOST_VOLUME: "GHOST_VOLUME",
                         ACCENT_VOLUME:"ACCENT_VOLUME"}
        for drum in newKit:
            headLines = []
            headIndent = indent + '"%s" : [' % drum.abbr
            defaultData = drum.headData(drum.head)
            for head in drum:
                if head == drum.head:
                    continue
                data = drum.headData(head)
                line = headIndent
                values = (head,
                          "None" if data.midiNote == defaultData.midiNote
                          else str(data.midiNote),
                          "None" if data.midiVolume == defaultData.midiVolume
                          else volumeSymbols.get(data.midiVolume,
                                                str(data.midiVolume)),
                          data.effect, data.notationHead,
                          data.notationEffect, data.shortcut)
                line += '("%s", %s, %s, "%s", "%s", "%s", "%s")' % values
                headLines.append(line)
                headIndent = ' ' * len(headIndent)
            if headLines:
                headLines = ("," + os.linesep).join(headLines) + "]"
                lines.append(headLines)
                indent = ' ' * len(indent)
        if lines:
            lines = ("," + os.linesep).join(lines) + "}"
        else:
            lines = '%s_HEADS = {}' % kitvar
        print lines
        print ('%s_KIT = {"drums":%s_DRUMS, "heads":%s_HEADS}'
               % (kitvar, kitvar, kitvar))
        print 'NAMED_DEFAULTS["%s"] = %s_KIT' % (kitname, kitvar)
        print 'DEFAULT_KIT_NAMES.append("%s")' % kitname
Ejemplo n.º 24
0
 def testAddDrum(self):
     self.kit = DrumKit.getNamedDefaultKit()
     numDrums = len(self.kit)
     drum = Drum("test drum", "td", "x")
     self.kit.addDrum(drum)
     self.assertEqual(len(self.kit), numDrums + 1)
Ejemplo n.º 25
0
 def testAddDuplicate(self):
     self.kit = DrumKit.getNamedDefaultKit()
     self.assertRaises(DuplicateDrumError,
                       self.kit.addDrum, self.kit[0])