Example #1
0
 def testSysEx(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.addSysEx(0,0, 0, struct.pack('>B', 0x01))
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'SysEx')
     self.assertEquals(get_byte(MyMIDI, 0, 0), 0x00)
     self.assertEquals(get_byte(MyMIDI, 0, 1), 0xf0)
     self.assertEquals(get_byte(MyMIDI, 0, 2), 3)
     self.assertEquals(get_byte(MyMIDI, 0, 3), 0x00)
     self.assertEquals(get_byte(MyMIDI, 0, 4), 0x01)
     self.assertEquals(get_byte(MyMIDI, 0, 5), 0xf7)
Example #2
0
 def testSysEx(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.addSysEx(0, 0, 0, struct.pack('>B', 0x01))
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'SysEx')
     self.assertEquals(get_byte(MyMIDI, 0, 0), 0x00)
     self.assertEquals(get_byte(MyMIDI, 0, 1), 0xf0)
     self.assertEquals(get_byte(MyMIDI, 0, 2), 3)
     self.assertEquals(get_byte(MyMIDI, 0, 3), 0x00)
     self.assertEquals(get_byte(MyMIDI, 0, 4), 0x01)
     self.assertEquals(get_byte(MyMIDI, 0, 5), 0xf7)
Example #3
0
 def testDeinterleaveNotes(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.addNote(0, 0, 100, 0, 2, 100)
     MyMIDI.addNote(0, 0, 100, 1, 2, 100)
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'NoteOn')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time,  0)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, 'NoteOff')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time,  128)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[2].type, 'NoteOn')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[2].time,  0)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[3].type, 'NoteOff')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[3].time,  256)
Example #4
0
 def testDeinterleaveNotes(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.addNote(0, 0, 100, 0, 2, 100)
     MyMIDI.addNote(0, 0, 100, 1, 2, 100)
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'NoteOn')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time, 0)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, 'NoteOff')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time, 128)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[2].type, 'NoteOn')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[2].time, 0)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[3].type, 'NoteOff')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[3].time, 256)
Example #5
0
 def testUniversalSysEx(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.addUniversalSysEx(0,0, 1, 2, struct.pack('>B', 0x01))
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'UniversalSysEx')
     self.assertEquals(get_byte(MyMIDI, 0, 0), 0x00)
     self.assertEquals(get_byte(MyMIDI, 0, 1), 0xf0)
     self.assertEquals(get_byte(MyMIDI, 0, 2), 6)
     self.assertEquals(get_byte(MyMIDI, 0, 3), 0x7E)
     self.assertEquals(get_byte(MyMIDI, 0, 4), 0x7F)
     self.assertEquals(get_byte(MyMIDI, 0, 5), 0x01)
     self.assertEquals(get_byte(MyMIDI, 0, 6), 0x02)
     self.assertEquals(get_byte(MyMIDI, 0, 7), 0x01)
     self.assertEquals(get_byte(MyMIDI, 0, 8), 0xf7)
Example #6
0
 def testUniversalSysEx(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.addUniversalSysEx(0, 0, 1, 2, struct.pack('>B', 0x01))
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type,
                       'UniversalSysEx')
     self.assertEquals(get_byte(MyMIDI, 0, 0), 0x00)
     self.assertEquals(get_byte(MyMIDI, 0, 1), 0xf0)
     self.assertEquals(get_byte(MyMIDI, 0, 2), 6)
     self.assertEquals(get_byte(MyMIDI, 0, 3), 0x7E)
     self.assertEquals(get_byte(MyMIDI, 0, 4), 0x7F)
     self.assertEquals(get_byte(MyMIDI, 0, 5), 0x01)
     self.assertEquals(get_byte(MyMIDI, 0, 6), 0x02)
     self.assertEquals(get_byte(MyMIDI, 0, 7), 0x01)
     self.assertEquals(get_byte(MyMIDI, 0, 8), 0xf7)
Example #7
0
 def testTimeShift(self):
     
     # With one track
     MyMIDI = MIDIFile(1)
     MyMIDI.addNote(0, 0, 100, 5, 1, 100)
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'NoteOn')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time,  0)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, 'NoteOff')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time,  128)
     
     # With two tracks
     MyMIDI = MIDIFile(2)
     MyMIDI.addNote(0, 0, 100, 5, 1, 100)
     MyMIDI.addNote(1, 0, 100, 6, 1, 100)
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'NoteOn')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time,  0)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, 'NoteOff')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time,  128)
     self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].type, 'NoteOn')
     self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].time,  128)
     self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].type, 'NoteOff')
     self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].time,  128)
     
     # Negative Time
     MyMIDI = MIDIFile(1)
     MyMIDI.addNote(0, 0, 100, -5, 1, 100)
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'NoteOn')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time,  0)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, 'NoteOff')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time,  128)
     
     # Negative time, two tracks
     
     MyMIDI = MIDIFile(2)
     MyMIDI.addNote(0, 0, 100, -1, 1, 100)
     MyMIDI.addNote(1, 0, 100, 0, 1, 100)
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'NoteOn')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time,  0)
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, 'NoteOff')
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time,  128)
     self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].type, 'NoteOn')
     self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].time,  128)
     self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].type, 'NoteOff')
     self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].time,  128)
Example #8
0
    def testTimeShift(self):

        # With one track
        MyMIDI = MIDIFile(1)
        MyMIDI.addNote(0, 0, 100, 5, 1, 100)
        MyMIDI.close()
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'NoteOn')
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time, 0)
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, 'NoteOff')
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time, 128)

        # With two tracks
        MyMIDI = MIDIFile(2)
        MyMIDI.addNote(0, 0, 100, 5, 1, 100)
        MyMIDI.addNote(1, 0, 100, 6, 1, 100)
        MyMIDI.close()
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'NoteOn')
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time, 0)
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, 'NoteOff')
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time, 128)
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].type, 'NoteOn')
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].time, 128)
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].type, 'NoteOff')
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].time, 128)

        # Negative Time
        MyMIDI = MIDIFile(1)
        MyMIDI.addNote(0, 0, 100, -5, 1, 100)
        MyMIDI.close()
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'NoteOn')
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time, 0)
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, 'NoteOff')
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time, 128)

        # Negative time, two tracks

        MyMIDI = MIDIFile(2)
        MyMIDI.addNote(0, 0, 100, -1, 1, 100)
        MyMIDI.addNote(1, 0, 100, 0, 1, 100)
        MyMIDI.close()
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'NoteOn')
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].time, 0)
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].type, 'NoteOff')
        self.assertEquals(MyMIDI.tracks[0].MIDIEventList[1].time, 128)
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].type, 'NoteOn')
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[0].time, 128)
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].type, 'NoteOff')
        self.assertEquals(MyMIDI.tracks[1].MIDIEventList[1].time, 128)
Example #9
0
 def testTuning(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.changeNoteTuning(0, [(1, 440), (2, 880)])
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type, 'UniversalSysEx')
     self.assertEquals(get_byte(MyMIDI, 0, 0), 0x00)
     self.assertEquals(get_byte(MyMIDI, 0, 1), 0xf0)
     self.assertEquals(get_byte(MyMIDI, 0, 2), 15)
     self.assertEquals(get_byte(MyMIDI, 0, 3), 0x7E)
     self.assertEquals(get_byte(MyMIDI, 0, 4), 0x7F)
     self.assertEquals(get_byte(MyMIDI, 0, 5), 0x08)
     self.assertEquals(get_byte(MyMIDI, 0, 6), 0x02)
     self.assertEquals(get_byte(MyMIDI, 0, 7), 0x00)
     self.assertEquals(get_byte(MyMIDI, 0, 8), 0x2)
     self.assertEquals(get_byte(MyMIDI, 0, 9), 0x1)
     self.assertEquals(get_byte(MyMIDI, 0, 10), 69)
     self.assertEquals(get_byte(MyMIDI, 0, 11), 0)
     self.assertEquals(get_byte(MyMIDI, 0, 12), 0)
     self.assertEquals(get_byte(MyMIDI, 0, 13), 0x2)
     self.assertEquals(get_byte(MyMIDI, 0, 14), 81)
     self.assertEquals(get_byte(MyMIDI, 0, 15), 0)
     self.assertEquals(get_byte(MyMIDI, 0, 16), 0)
     self.assertEquals(get_byte(MyMIDI, 0, 17), 0xf7)
Example #10
0
 def testTuning(self):
     MyMIDI = MIDIFile(1)
     MyMIDI.changeNoteTuning(0, [(1, 440), (2, 880)])
     MyMIDI.close()
     self.assertEquals(MyMIDI.tracks[0].MIDIEventList[0].type,
                       'UniversalSysEx')
     self.assertEquals(get_byte(MyMIDI, 0, 0), 0x00)
     self.assertEquals(get_byte(MyMIDI, 0, 1), 0xf0)
     self.assertEquals(get_byte(MyMIDI, 0, 2), 15)
     self.assertEquals(get_byte(MyMIDI, 0, 3), 0x7E)
     self.assertEquals(get_byte(MyMIDI, 0, 4), 0x7F)
     self.assertEquals(get_byte(MyMIDI, 0, 5), 0x08)
     self.assertEquals(get_byte(MyMIDI, 0, 6), 0x02)
     self.assertEquals(get_byte(MyMIDI, 0, 7), 0x00)
     self.assertEquals(get_byte(MyMIDI, 0, 8), 0x2)
     self.assertEquals(get_byte(MyMIDI, 0, 9), 0x1)
     self.assertEquals(get_byte(MyMIDI, 0, 10), 69)
     self.assertEquals(get_byte(MyMIDI, 0, 11), 0)
     self.assertEquals(get_byte(MyMIDI, 0, 12), 0)
     self.assertEquals(get_byte(MyMIDI, 0, 13), 0x2)
     self.assertEquals(get_byte(MyMIDI, 0, 14), 81)
     self.assertEquals(get_byte(MyMIDI, 0, 15), 0)
     self.assertEquals(get_byte(MyMIDI, 0, 16), 0)
     self.assertEquals(get_byte(MyMIDI, 0, 17), 0xf7)