/* resize buffer read bytes and encode to sequencer event if finished return the size of encoded bytes  */
long snd_midi_event_encode(struct snd_midi_event *dev, unsigned char *buf, long count, struct snd_seq_event *ev)
/* resize buffer read bytes and encode to sequencer event if finished return the size of encoded bytes  */
long snd_midi_event_encode(struct snd_midi_event *dev, unsigned char *buf, long count, struct snd_seq_event *ev)
{
	long result = 0;
	int rc;
	ev->type = SNDRV_SEQ_EVENT_NONE;
	while (count-- > 0) {
		rc = snd_midi_event_encode_byte(dev, *buf++, ev);
		result++;
		if (rc < 0)
			return rc;
		else if (rc > 0)
			return result;
	}
	return result;
}