aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2007-08-10 03:38:36 -0400
committerJaroslav Kysela <perex@perex.cz>2007-10-16 09:58:35 -0400
commit394d051686d846c6cd86fe086166a4ea5507ccb5 (patch)
tree4917352ed93ec95cfcb48354e3134bd3cfa7e9e3
parent0f28ecd3323bb7df52e50493f78803fe4d61794a (diff)
[ALSA] seq_midi_event: fix encoding of data bytes after end of sysex
Create a new state ST_INVALID for the encoder to prevent data bytes at the beginning of a stream or after a sysex message being interpreted as note-off parameters. Signed-off-by: Clemens Ladisch <clemens@ladisch.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
-rw-r--r--sound/core/seq/seq_midi_event.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/sound/core/seq/seq_midi_event.c b/sound/core/seq/seq_midi_event.c
index 5ff80b776906..cb38ff33f628 100644
--- a/sound/core/seq/seq_midi_event.c
+++ b/sound/core/seq/seq_midi_event.c
@@ -32,10 +32,9 @@ MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>, Jaroslav Kysela <perex@suse.cz>");
32MODULE_DESCRIPTION("MIDI byte <-> sequencer event coder"); 32MODULE_DESCRIPTION("MIDI byte <-> sequencer event coder");
33MODULE_LICENSE("GPL"); 33MODULE_LICENSE("GPL");
34 34
35/* queue type */ 35/* event type, index into status_event[] */
36/* from 0 to 7 are normal commands (note off, on, etc.) */ 36/* from 0 to 6 are normal commands (note off, on, etc.) for 0x9?-0xe? */
37#define ST_NOTEOFF 0 37#define ST_INVALID 7
38#define ST_NOTEON 1
39#define ST_SPECIAL 8 38#define ST_SPECIAL 8
40#define ST_SYSEX ST_SPECIAL 39#define ST_SYSEX ST_SPECIAL
41/* from 8 to 15 are events for 0xf0-0xf7 */ 40/* from 8 to 15 are events for 0xf0-0xf7 */
@@ -65,7 +64,7 @@ static struct status_event_list {
65 void (*encode)(struct snd_midi_event *dev, struct snd_seq_event *ev); 64 void (*encode)(struct snd_midi_event *dev, struct snd_seq_event *ev);
66 void (*decode)(struct snd_seq_event *ev, unsigned char *buf); 65 void (*decode)(struct snd_seq_event *ev, unsigned char *buf);
67} status_event[] = { 66} status_event[] = {
68 /* 0x80 - 0xf0 */ 67 /* 0x80 - 0xef */
69 {SNDRV_SEQ_EVENT_NOTEOFF, 2, note_event, note_decode}, 68 {SNDRV_SEQ_EVENT_NOTEOFF, 2, note_event, note_decode},
70 {SNDRV_SEQ_EVENT_NOTEON, 2, note_event, note_decode}, 69 {SNDRV_SEQ_EVENT_NOTEON, 2, note_event, note_decode},
71 {SNDRV_SEQ_EVENT_KEYPRESS, 2, note_event, note_decode}, 70 {SNDRV_SEQ_EVENT_KEYPRESS, 2, note_event, note_decode},
@@ -73,7 +72,8 @@ static struct status_event_list {
73 {SNDRV_SEQ_EVENT_PGMCHANGE, 1, one_param_ctrl_event, one_param_decode}, 72 {SNDRV_SEQ_EVENT_PGMCHANGE, 1, one_param_ctrl_event, one_param_decode},
74 {SNDRV_SEQ_EVENT_CHANPRESS, 1, one_param_ctrl_event, one_param_decode}, 73 {SNDRV_SEQ_EVENT_CHANPRESS, 1, one_param_ctrl_event, one_param_decode},
75 {SNDRV_SEQ_EVENT_PITCHBEND, 2, pitchbend_ctrl_event, pitchbend_decode}, 74 {SNDRV_SEQ_EVENT_PITCHBEND, 2, pitchbend_ctrl_event, pitchbend_decode},
76 {SNDRV_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf0 */ 75 /* invalid */
76 {SNDRV_SEQ_EVENT_NONE, 0, NULL, NULL},
77 /* 0xf0 - 0xff */ 77 /* 0xf0 - 0xff */
78 {SNDRV_SEQ_EVENT_SYSEX, 1, NULL, NULL}, /* sysex: 0xf0 */ 78 {SNDRV_SEQ_EVENT_SYSEX, 1, NULL, NULL}, /* sysex: 0xf0 */
79 {SNDRV_SEQ_EVENT_QFRAME, 1, one_param_event, one_param_decode}, /* 0xf1 */ 79 {SNDRV_SEQ_EVENT_QFRAME, 1, one_param_event, one_param_decode}, /* 0xf1 */
@@ -129,6 +129,7 @@ int snd_midi_event_new(int bufsize, struct snd_midi_event **rdev)
129 } 129 }
130 dev->bufsize = bufsize; 130 dev->bufsize = bufsize;
131 dev->lastcmd = 0xff; 131 dev->lastcmd = 0xff;
132 dev->type = ST_INVALID;
132 spin_lock_init(&dev->lock); 133 spin_lock_init(&dev->lock);
133 *rdev = dev; 134 *rdev = dev;
134 return 0; 135 return 0;
@@ -149,7 +150,7 @@ static inline void reset_encode(struct snd_midi_event *dev)
149{ 150{
150 dev->read = 0; 151 dev->read = 0;
151 dev->qlen = 0; 152 dev->qlen = 0;
152 dev->type = 0; 153 dev->type = ST_INVALID;
153} 154}
154 155
155void snd_midi_event_reset_encode(struct snd_midi_event *dev) 156void snd_midi_event_reset_encode(struct snd_midi_event *dev)