def testWrite_Different(self): handle = StringIO() headData = HeadData(72, 100, "ghost", "cross", 1, "choke", 1, "c") indenter = Indenter(handle) headData.write("x", indenter) self.assertEqual(handle.getvalue().rstrip(), "NOTEHEAD x 72,100,ghost,cross,1,choke,1,c")
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" ])
def _loadDefaultKit(kit, kitInfo=None): for (drumData, midiNote, notationHead, notationLine, stemDirection) in kitInfo["drums"]: drum = Drum(*drumData) headData = HeadData(midiNote=midiNote, notationHead=notationHead, notationLine=notationLine, stemDirection=stemDirection) drum.addNoteHead(drum.head, headData) for (extraHead, newMidi, newMidiVolume, newEffect, newNotationHead, newNotationEffect, shortcut) in kitInfo["heads"].get(drum.abbr, []): if newMidi is None: newMidi = midiNote if newMidiVolume is None: newMidiVolume = headData.midiVolume newData = HeadData(newMidi, newMidiVolume, newEffect, notationLine=notationLine, notationHead=newNotationHead, notationEffect=newNotationEffect, stemDirection=stemDirection, shortcut=shortcut) drum.addNoteHead(extraHead, newData) drum.checkShortcuts() kit.addDrum(drum)
def testWrite_Default(self): handle = StringIO() headData = HeadData() indenter = Indenter(handle) headData.write("x", indenter) self.assertEqual(handle.getvalue().rstrip(), "NOTEHEAD x 71,96,normal,default,0,none,0,")
def makeDrum(): drum = Drum("test", "td", "x") defaultHead = HeadData(shortcut="y") drum.addNoteHead("x", defaultHead) newHead = HeadData(100) drum.addNoteHead("y", newHead) drum.addNoteHead("z", None) return drum, defaultHead, newHead
def makeDrum(): drum = Drum("test", "td", "x") defaultHead = HeadData(shortcut="y") drum.addNoteHead("x", defaultHead) newHead = HeadData(100) drum.addNoteHead("y", newHead) headData = HeadData(72, 100, "ghost", "cross", 1, "choke", DefaultKits.STEM_DOWN, "c") drum.addNoteHead("z", headData) return drum, defaultHead, newHead
def testWriteExtraHeads(self): drum = Drum("test", "td", "x") defaultHead = HeadData(shortcut="y") drum.addNoteHead("x", defaultHead) newHead = HeadData(100, shortcut='a') drum.addNoteHead("y", newHead) headData = HeadData(72, 100, "ghost", "cross", 1, "choke", DefaultKits.STEM_DOWN, "c") drum.addNoteHead("z", headData) outstring = StringIO() indenter = fileUtils.Indenter(outstring) dbfsv1.DrumStructureV1().write(drum, indenter) outlines = outstring.getvalue().splitlines() self.assertEqual(outlines, ['START_DRUM', ' NAME test', ' ABBR td', ' DEFAULT_HEAD x', ' LOCKED False', ' HEADLIST xyz', ' START_NOTEHEAD', ' MIDINOTE 71', ' MIDIVOLUME 96', ' EFFECT normal', ' NOTATIONHEAD default', ' NOTATIONLINE 0', ' NOTATIONEFFECT none', ' STEM 0', ' SHORTCUT y', ' END_NOTEHEAD', ' START_NOTEHEAD', ' MIDINOTE 100', ' MIDIVOLUME 96', ' EFFECT normal', ' NOTATIONHEAD default', ' NOTATIONLINE 0', ' NOTATIONEFFECT none', ' STEM 0', ' SHORTCUT a', ' END_NOTEHEAD', ' START_NOTEHEAD', ' MIDINOTE 72', ' MIDIVOLUME 100', ' EFFECT ghost', ' NOTATIONHEAD cross', ' NOTATIONLINE 1', ' NOTATIONEFFECT choke', ' STEM 1', ' SHORTCUT c', ' END_NOTEHEAD', 'END_DRUM'])
def testWriteSimple(self): drum = Drum("test", "td", "x", True) defaultHead = HeadData(shortcut="y") drum.addNoteHead("x", defaultHead) outstring = StringIO() indenter = fileUtils.Indenter(outstring) dbfsv1.DrumStructureV1().write(drum, indenter) outlines = outstring.getvalue().splitlines() self.assertEqual(outlines, ['START_DRUM', ' NAME test', ' ABBR td', ' DEFAULT_HEAD x', ' LOCKED True', ' HEADLIST x', ' START_NOTEHEAD', ' MIDINOTE 71', ' MIDIVOLUME 96', ' EFFECT normal', ' NOTATIONHEAD default', ' NOTATIONLINE 0', ' NOTATIONEFFECT none', ' STEM 0', ' SHORTCUT y', ' END_NOTEHEAD', 'END_DRUM'])
def testRead_Old_Unrecognised_Drum(self): dataString = "g 72,100,ghost" head, data = HeadData.read("Xx", dataString) self.assertEqual(head, "g") self.assertEqual(data.midiNote, 72) self.assertEqual(data.midiVolume, 100) self.assertEqual(data.effect, "ghost") self.assertEqual(data.notationHead, "default") self.assertEqual(data.notationLine, 0) self.assertEqual(data.notationEffect, "none") self.assertEqual(data.stemDirection, 0) self.assertEqual(data.shortcut, "")
def testRead_New(self): dataString = "x 72,100,ghost,cross,1,choke,1,c" head, data = HeadData.read("Hh", dataString) self.assertEqual(head, "x") self.assertEqual(data.midiNote, 72) self.assertEqual(data.midiVolume, 100) self.assertEqual(data.effect, "ghost") self.assertEqual(data.notationHead, "cross") self.assertEqual(data.notationLine, 1) self.assertEqual(data.notationEffect, "choke") self.assertEqual(data.stemDirection, 1) self.assertEqual(data.shortcut, "c")
def testWriteDefault(self): output = self.get_output(HeadData()) self.assertEqual(output, ['START_NOTEHEAD', ' MIDINOTE 71', ' MIDIVOLUME 96', ' EFFECT normal', ' NOTATIONHEAD default', ' NOTATIONLINE 0', ' NOTATIONEFFECT none', ' STEM 0', 'END_NOTEHEAD'])
def testWriteWithData(self): output = self.get_output(HeadData(69, 127, 'ghost', 'triangle', -1, 'ghost', DefaultKits.STEM_DOWN, 'x')) self.assertEqual(output, ['START_NOTEHEAD', ' MIDINOTE 69', ' MIDIVOLUME 127', ' EFFECT ghost', ' NOTATIONHEAD triangle', ' NOTATIONLINE -1', ' NOTATIONEFFECT ghost', ' STEM 1', ' SHORTCUT x', 'END_NOTEHEAD'])
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'])