Beispiel #1
0
    def testText(self):
        #import pdb; pdb.set_trace()
        text = "2016(C) MCW"
        MyMIDI = MIDIFile(1)
        MyMIDI.addText(0, 0, text)
        MyMIDI.close()

        payload_encoded = text.encode("ISO-8859-1")
        payloadLength = len(payload_encoded)
        payloadLengthVar = writeVarLength(payloadLength)

        data = Decoder(MyMIDI.tracks[1].MIDIdata)

        self.assertEqual(MyMIDI.tracks[1].MIDIEventList[0].type, 'Text')

        self.assertEqual(data.unpack_into_byte(0), 0x00)  # time
        self.assertEqual(data.unpack_into_byte(1), 0xff)  # Code
        self.assertEqual(data.unpack_into_byte(2), 0x01)  # Subcode
        index = 3
        for i in range(len(payloadLengthVar)):
            self.assertEqual(data.unpack_into_byte(index), payloadLengthVar[i])
            index = index + 1
        for i in range(len(payload_encoded)):
            if sys.version_info < (3, ):
                test_char = ord(payload_encoded[i])
            else:
                test_char = payload_encoded[i]
            self.assertEqual(data.unpack_into_byte(index), test_char)
            index = index + 1
Beispiel #2
0
    def testNonRealTimeUniversalSysEx(self):
        code           = 1
        subcode        = 2
        payload_number = 42

        payload = struct.pack('>B', payload_number)

        MyMIDI = MIDIFile(1, adjust_origin=False)

        # Just for fun we'll use a multi-byte time
        time = 1
        time_bytes = writeVarLength(time * MyMIDI.ticks_per_quarternote)
        MyMIDI.addUniversalSysEx(0, time, code, subcode, payload, realTime=False)
        MyMIDI.close()

        data = Decoder(MyMIDI.tracks[1].MIDIdata)

        self.assertEqual(MyMIDI.tracks[1].MIDIEventList[0].evtname, 'UniversalSysEx')

        self.assertEqual(data.unpack_into_byte(0), time_bytes[0]) # Time
        self.assertEqual(data.unpack_into_byte(1), time_bytes[1]) # Time
        self.assertEqual(data.unpack_into_byte(2), 0xf0) # UniversalSysEx == 0xF0
        self.assertEqual(data.unpack_into_byte(3), 5 + len(payload))    # Payload length = 5+actual pyayload
        self.assertEqual(data.unpack_into_byte(4), 0x7E) # 0x7E == non-realtime
        self.assertEqual(data.unpack_into_byte(5), 0x7F) # Sysex channel (always 0x7F)
        self.assertEqual(data.unpack_into_byte(6), code)
        self.assertEqual(data.unpack_into_byte(7), subcode)
        self.assertEqual(data.unpack_into_byte(8), payload_number) # Data
        self.assertEqual(data.unpack_into_byte(9), 0xf7) # End of message
Beispiel #3
0
    def testCopyright(self):
        notice = "2016(C) MCW"
        MyMIDI = MIDIFile(1)
        MyMIDI.addCopyright(0, 0, notice)
        MyMIDI.close()

        payload_encoded = notice.encode("ISO-8859-1")
        payloadLength = len(payload_encoded)
        payloadLengthVar = writeVarLength(payloadLength)

        data = Decoder(MyMIDI.tracks[1].MIDIdata)

        self.assertEqual(MyMIDI.tracks[1].MIDIEventList[0].evtname, 'Copyright')

        self.assertEqual(data.unpack_into_byte(0), 0x00)  # time
        self.assertEqual(data.unpack_into_byte(1), 0xff)  # Code
        self.assertEqual(data.unpack_into_byte(2), 0x02)  # Subcode
        index = 3
        for i in range(len(payloadLengthVar)):
            self.assertEqual(data.unpack_into_byte(index), payloadLengthVar[i])
            index = index + 1
        for i in range(len(payload_encoded)):
            if sys.version_info < (3,):
                test_char = ord(payload_encoded[i])
            else:
                test_char = payload_encoded[i]
            self.assertEqual(data.unpack_into_byte(index), test_char)
            index = index + 1
Beispiel #4
0
 def testWriteVarLength(self):
     self.assertEqual(writeVarLength(0x70), [0x70])
     self.assertEqual(writeVarLength(0x80), [0x81, 0x00])
     self.assertEqual(writeVarLength(0x1FFFFF), [0xFF, 0xFF, 0x7F])
     self.assertEqual(writeVarLength(0x08000000), [0xC0, 0x80, 0x80, 0x00])
Beispiel #5
0
 def testWriteVarLength(self):
     self.assertEquals(writeVarLength(0x70), [0x70])
     self.assertEquals(writeVarLength(0x80), [0x81, 0x00])
     self.assertEquals(writeVarLength(0x1FFFFF), [0xFF, 0xFF, 0x7F])
     self.assertEquals(writeVarLength(0x08000000), [0xC0, 0x80, 0x80, 0x00])