def parse_midi_event(self, fp):
        """Parse a MIDI event.

        Return a dictionary and the number of bytes read.
        """
        chunk_size = 0
        try:
            ec = self.bytes_to_int(fp.read(1))
            chunk_size += 1
            self.bytes_read += 1
        except:
            raise IOError("Couldn't read event type "
                    "and channel data from file.")

        # Get the nibbles
        event_type = (ec & 0xf0) >> 4
        channel = ec & 0x0f

        # I don't know what these events are supposed to do, but I keep finding
        # them. The parser ignores them.
        if event_type < 8:
            raise FormatError('Unknown event type %d. Byte %d.' % (event_type,
                self.bytes_read))

        # Meta events can have strings of variable length
        if event_type == 0x0f:
            try:
                meta_event = self.bytes_to_int(fp.read(1))
                (length, chunk_delta) = self.parse_varbyte_as_int(fp)
                data = fp.read(length)
                chunk_size += 1 + chunk_delta + length
                self.bytes_read += 1 + length
            except:
                raise IOError("Couldn't read meta event from file.")
            return ({'event': event_type, 'meta_event': meta_event,
                'data': data}, chunk_size)
        elif event_type in [12, 13]:
            # Program change and Channel aftertouch events only have one
            # parameter
            try:
                param1 = fp.read(1)
                chunk_size += 1
                self.bytes_read += 1
            except:
                raise IOError("Couldn't read MIDI event parameters from file.")
            param1 = self.bytes_to_int(param1)
            return ({'event': event_type, 'channel': channel,
                'param1': param1}, chunk_size)
        else:
            try:
                param1 = fp.read(1)
                param2 = fp.read(1)
                chunk_size += 2
                self.bytes_read += 2
            except:
                raise IOError("Couldn't read MIDI event parameters from file.")
            param1 = self.bytes_to_int(param1)
            param2 = self.bytes_to_int(param2)
            return ({'event': event_type, 'channel': channel, 'param1': param1,
                'param2': param2}, chunk_size)
Parse a MIDI event.

        Return a dictionary and the number of bytes read.