⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seq_midi_event.c

📁 linux2.6.16版本
💻 C
📖 第 1 页 / 共 2 页
字号:
			/* process this byte as argument */			dev->buf[dev->read++] = c;			dev->qlen = status_event[dev->type].qlen - 1;		}	}	if (dev->qlen == 0) {		ev->type = status_event[dev->type].event;		ev->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK;		ev->flags |= SNDRV_SEQ_EVENT_LENGTH_FIXED;		if (status_event[dev->type].encode) /* set data values */			status_event[dev->type].encode(dev, ev);		rc = 1;	} else 	if (dev->type == ST_SYSEX) {		if (c == MIDI_CMD_COMMON_SYSEX_END ||		    dev->read >= dev->bufsize) {			ev->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK;			ev->flags |= SNDRV_SEQ_EVENT_LENGTH_VARIABLE;			ev->type = SNDRV_SEQ_EVENT_SYSEX;			ev->data.ext.len = dev->read;			ev->data.ext.ptr = dev->buf;			if (c != MIDI_CMD_COMMON_SYSEX_END)				dev->read = 0; /* continue to parse */			else				reset_encode(dev); /* all parsed */			rc = 1;		}	}	spin_unlock_irqrestore(&dev->lock, flags);	return rc;}/* encode note event */static void note_event(struct snd_midi_event *dev, struct snd_seq_event *ev){	ev->data.note.channel = dev->buf[0] & 0x0f;	ev->data.note.note = dev->buf[1];	ev->data.note.velocity = dev->buf[2];}/* encode one parameter controls */static void one_param_ctrl_event(struct snd_midi_event *dev, struct snd_seq_event *ev){	ev->data.control.channel = dev->buf[0] & 0x0f;	ev->data.control.value = dev->buf[1];}/* encode pitch wheel change */static void pitchbend_ctrl_event(struct snd_midi_event *dev, struct snd_seq_event *ev){	ev->data.control.channel = dev->buf[0] & 0x0f;	ev->data.control.value = (int)dev->buf[2] * 128 + (int)dev->buf[1] - 8192;}/* encode midi control change */static void two_param_ctrl_event(struct snd_midi_event *dev, struct snd_seq_event *ev){	ev->data.control.channel = dev->buf[0] & 0x0f;	ev->data.control.param = dev->buf[1];	ev->data.control.value = dev->buf[2];}/* encode one parameter value*/static void one_param_event(struct snd_midi_event *dev, struct snd_seq_event *ev){	ev->data.control.value = dev->buf[1];}/* encode song position */static void songpos_event(struct snd_midi_event *dev, struct snd_seq_event *ev){	ev->data.control.value = (int)dev->buf[2] * 128 + (int)dev->buf[1];}/* * decode from a sequencer event to midi bytes * return the size of decoded midi events */long snd_midi_event_decode(struct snd_midi_event *dev, unsigned char *buf, long count,			   struct snd_seq_event *ev){	unsigned int cmd, type;	if (ev->type == SNDRV_SEQ_EVENT_NONE)		return -ENOENT;	for (type = 0; type < ARRAY_SIZE(status_event); type++) {		if (ev->type == status_event[type].event)			goto __found;	}	for (type = 0; type < ARRAY_SIZE(extra_event); type++) {		if (ev->type == extra_event[type].event)			return extra_event[type].decode(dev, buf, count, ev);	}	return -ENOENT;      __found:	if (type >= ST_SPECIAL)		cmd = 0xf0 + (type - ST_SPECIAL);	else		/* data.note.channel and data.control.channel is identical */		cmd = 0x80 | (type << 4) | (ev->data.note.channel & 0x0f);	if (cmd == MIDI_CMD_COMMON_SYSEX) {		snd_midi_event_reset_decode(dev);		return snd_seq_expand_var_event(ev, count, buf, 1, 0);	} else {		int qlen;		unsigned char xbuf[4];		unsigned long flags;		spin_lock_irqsave(&dev->lock, flags);		if ((cmd & 0xf0) == 0xf0 || dev->lastcmd != cmd || dev->nostat) {			dev->lastcmd = cmd;			spin_unlock_irqrestore(&dev->lock, flags);			xbuf[0] = cmd;			if (status_event[type].decode)				status_event[type].decode(ev, xbuf + 1);			qlen = status_event[type].qlen + 1;		} else {			spin_unlock_irqrestore(&dev->lock, flags);			if (status_event[type].decode)				status_event[type].decode(ev, xbuf + 0);			qlen = status_event[type].qlen;		}		if (count < qlen)			return -ENOMEM;		memcpy(buf, xbuf, qlen);		return qlen;	}}/* decode note event */static void note_decode(struct snd_seq_event *ev, unsigned char *buf){	buf[0] = ev->data.note.note & 0x7f;	buf[1] = ev->data.note.velocity & 0x7f;}/* decode one parameter controls */static void one_param_decode(struct snd_seq_event *ev, unsigned char *buf){	buf[0] = ev->data.control.value & 0x7f;}/* decode pitch wheel change */static void pitchbend_decode(struct snd_seq_event *ev, unsigned char *buf){	int value = ev->data.control.value + 8192;	buf[0] = value & 0x7f;	buf[1] = (value >> 7) & 0x7f;}/* decode midi control change */static void two_param_decode(struct snd_seq_event *ev, unsigned char *buf){	buf[0] = ev->data.control.param & 0x7f;	buf[1] = ev->data.control.value & 0x7f;}/* decode song position */static void songpos_decode(struct snd_seq_event *ev, unsigned char *buf){	buf[0] = ev->data.control.value & 0x7f;	buf[1] = (ev->data.control.value >> 7) & 0x7f;}/* decode 14bit control */static int extra_decode_ctrl14(struct snd_midi_event *dev, unsigned char *buf,			       int count, struct snd_seq_event *ev){	unsigned char cmd;	int idx = 0;	cmd = MIDI_CMD_CONTROL|(ev->data.control.channel & 0x0f);	if (ev->data.control.param < 0x20) {		if (count < 4)			return -ENOMEM;		if (dev->nostat && count < 6)			return -ENOMEM;		if (cmd != dev->lastcmd || dev->nostat) {			if (count < 5)				return -ENOMEM;			buf[idx++] = dev->lastcmd = cmd;		}		buf[idx++] = ev->data.control.param;		buf[idx++] = (ev->data.control.value >> 7) & 0x7f;		if (dev->nostat)			buf[idx++] = cmd;		buf[idx++] = ev->data.control.param + 0x20;		buf[idx++] = ev->data.control.value & 0x7f;	} else {		if (count < 2)			return -ENOMEM;		if (cmd != dev->lastcmd || dev->nostat) {			if (count < 3)				return -ENOMEM;			buf[idx++] = dev->lastcmd = cmd;		}		buf[idx++] = ev->data.control.param & 0x7f;		buf[idx++] = ev->data.control.value & 0x7f;	}	return idx;}/* decode reg/nonreg param */static int extra_decode_xrpn(struct snd_midi_event *dev, unsigned char *buf,			     int count, struct snd_seq_event *ev){	unsigned char cmd;	char *cbytes;	static char cbytes_nrpn[4] = { MIDI_CTL_NONREG_PARM_NUM_MSB,				       MIDI_CTL_NONREG_PARM_NUM_LSB,				       MIDI_CTL_MSB_DATA_ENTRY,				       MIDI_CTL_LSB_DATA_ENTRY };	static char cbytes_rpn[4] =  { MIDI_CTL_REGIST_PARM_NUM_MSB,				       MIDI_CTL_REGIST_PARM_NUM_LSB,				       MIDI_CTL_MSB_DATA_ENTRY,				       MIDI_CTL_LSB_DATA_ENTRY };	unsigned char bytes[4];	int idx = 0, i;	if (count < 8)		return -ENOMEM;	if (dev->nostat && count < 12)		return -ENOMEM;	cmd = MIDI_CMD_CONTROL|(ev->data.control.channel & 0x0f);	bytes[0] = ev->data.control.param & 0x007f;	bytes[1] = (ev->data.control.param & 0x3f80) >> 7;	bytes[2] = ev->data.control.value & 0x007f;	bytes[3] = (ev->data.control.value & 0x3f80) >> 7;	if (cmd != dev->lastcmd && !dev->nostat) {		if (count < 9)			return -ENOMEM;		buf[idx++] = dev->lastcmd = cmd;	}	cbytes = ev->type == SNDRV_SEQ_EVENT_NONREGPARAM ? cbytes_nrpn : cbytes_rpn;	for (i = 0; i < 4; i++) {		if (dev->nostat)			buf[idx++] = dev->lastcmd = cmd;		buf[idx++] = cbytes[i];		buf[idx++] = bytes[i];	}	return idx;}/* *  exports */ EXPORT_SYMBOL(snd_midi_event_new);EXPORT_SYMBOL(snd_midi_event_free);EXPORT_SYMBOL(snd_midi_event_reset_encode);EXPORT_SYMBOL(snd_midi_event_reset_decode);EXPORT_SYMBOL(snd_midi_event_no_status);EXPORT_SYMBOL(snd_midi_event_encode);EXPORT_SYMBOL(snd_midi_event_encode_byte);EXPORT_SYMBOL(snd_midi_event_decode);static int __init alsa_seq_midi_event_init(void){	return 0;}static void __exit alsa_seq_midi_event_exit(void){}module_init(alsa_seq_midi_event_init)module_exit(alsa_seq_midi_event_exit)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -