Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 1 file changed
  • 0 comments
  • 2 contributors
Nov 02, 2011
Werner Almesberger input.c: synchronize with MIDI status and ignore real-time messages
This patch synchronizes the first (status) byte of each message and
it also ignores real-time messages which can appear _inside_ the
data of other messages.

I didn't make provisions for doing anything clever about SysEx,
because we don't handle them anyway.
248ea5a
Sébastien Bourdeauducq input: remove MIDI timeout d753464

Showing 1 changed file with 12 additions and 13 deletions. Show diff stats Hide diff stats

  1. 25  src/input.c
25  src/input.c
@@ -253,29 +253,28 @@ static int handle_midi_msg(mtk_event *e, unsigned char *msg)
253 253
 	}
254 254
 }
255 255
 
256  
-#define MIDI_TIMEOUT 20
257  
-
258  
-static int midi_p;
259  
-static rtems_interval midi_last;
  256
+static unsigned char *midi_p = NULL;
260 257
 static unsigned char midi_msg[3];
261 258
 
262 259
 static int handle_midi_event(mtk_event *e, unsigned char *msg)
263 260
 {
264  
-	rtems_interval t;
265 261
 	int r;
266 262
 
267  
-	t = rtems_clock_get_ticks_since_boot();
268  
-	if(t > (midi_last + MIDI_TIMEOUT))
269  
-		midi_p = 0;
270  
-	midi_last = t;
  263
+	if((*msg & 0xf8) == 0xf8)
  264
+		return 0; /* ignore system real-time */
  265
+
  266
+	if(*msg & 0x80)
  267
+		midi_p = midi_msg; /* status byte */
  268
+
  269
+	if(!midi_p)
  270
+		return 0; /* ignore extra or unsynchronized data */
271 271
 
272  
-	midi_msg[midi_p] = msg[0];
273  
-	midi_p++;
  272
+	*midi_p++ = *msg;
274 273
 
275  
-	if(midi_p == 3) {
  274
+	if(midi_p == midi_msg+3) {
276 275
 		/* received a complete MIDI message */
277 276
 		r = handle_midi_msg(e, midi_msg);
278  
-		midi_p = 0;
  277
+		midi_p = NULL;
279 278
 		return r;
280 279
 	}
281 280
 	

No commit comments for this range

Something went wrong with that request. Please try again.