function parseevents(chunk) {
		var events = [];
		var i = 0;
		var ch;
		var time = 0;
		var command = 0;
		var CMDLEN = [0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 2, 0];

		while (i < chunk.length) {

			var delay = 0;
			do {
				ch = chunk[i++];
				delay <<= 7;
				delay |= ch & 0x7f;
			} while (ch & 0x80);

			time += delay;

			// ----

			var ch = chunk[i];

			if (ch == 0xff) { // meta
				var p = 2;
				var len = 0;
				do {
					ch = chunk[i + p++];
					len <<= 7;
					len |= ch & 0x7f;
				} while (ch & 0x80);

				var evt = { time: time, command: chunk.subarray(i, i + p + len) };
				events.push(evt);
				i += p + len;
				command = 0;
				continue;
			} else if (ch == 0xf0) { // sysex
				var len = 1;
				while (chunk[i + len++] != 0xf7); // <-- that semicolon should be there
				var evt = { time: time, command: chunk.subarray(i, i + len) };
				events.push(evt);
				i += len;
				command = 0;
				continue;
			} else if ((ch & 0x80) != 0) {
				command = ch;
				i++;
			}

			if ((command & 0x80) == 0) {
				throw ['command error', 'index', i, 'track', chunk];
			}

			var l = CMDLEN[command >> 4];
			if (l > 0) {
				var evt = { time: time, command: [command].concat(Array.prototype.slice.call(chunk.subarray(i, i + l))), };
				events.push(evt);
				i += l;
			}
		}

		return events;
	}
/*
	take a byte array of midi events and convert them to an array standard javascript objects
	*/
take a byte array of midi events and convert them to an array standard javascript objects
take a byte array of midi events and convert them to an array standard javascript objects
function parseevents(chunk) {
		var events = [];
		var i = 0;
		var ch;
		var time = 0;
		var command = 0;
		var CMDLEN = [0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 2, 0];
		while (i < chunk.length) {
			var delay = 0;
			do {
				ch = chunk[i++];
				delay <<= 7;
				delay |= ch & 0x7f;
			} while (ch & 0x80);
			time += delay;
			var ch = chunk[i];
			if (ch == 0xff) { 
				var p = 2;
				var len = 0;
				do {
					ch = chunk[i + p++];
					len <<= 7;
					len |= ch & 0x7f;
				} while (ch & 0x80);
				var evt = { time: time, command: chunk.subarray(i, i + p + len) };
				events.push(evt);
				i += p + len;
				command = 0;
				continue;
			} else if (ch == 0xf0) { 
				var len = 1;
				while (chunk[i + len++] != 0xf7); 
				var evt = { time: time, command: chunk.subarray(i, i + len) };
				events.push(evt);
				i += len;
				command = 0;
				continue;
			} else if ((ch & 0x80) != 0) {
				command = ch;
				i++;
			}
			if ((command & 0x80) == 0) {
				throw ['command error', 'index', i, 'track', chunk];
			}
			var l = CMDLEN[command >> 4];
			if (l > 0) {
				var evt = { time: time, command: [command].concat(Array.prototype.slice.call(chunk.subarray(i, i + l))), };
				events.push(evt);
				i += l;
			}
		}
		return events;
	}
function parseevents ( chunk ) { var events = [ ] ; var i = 0 ; var ch ; var time = 0 ; var command = 0 ; var CMDLEN = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 2 , 2 , 2 , 1 , 1 , 2 , 0 ] ; while ( i < chunk . length ) { var delay = 0 ; do { ch = chunk [ i ++ ] ; delay <<= 7 ; delay |= ch & 0x7f ; } while ( ch & 0x80 ) ; time += delay ; var ch = chunk [ i ] ; if ( ch == 0xff ) { var p = 2 ; var len = 0 ; do { ch = chunk [ i + p ++ ] ; len <<= 7 ; len |= ch & 0x7f ; } while ( ch & 0x80 ) ; var evt = { time : time , command : chunk . subarray ( i , i + p + len ) } ; events . push ( evt ) ; i += p + len ; command = 0 ; continue ; } else if ( ch == 0xf0 ) { var len = 1 ; while ( chunk [ i + len ++ ] != 0xf7 ) ; var evt = { time : time , command : chunk . subarray ( i , i + len ) } ; events . push ( evt ) ; i += len ; command = 0 ; continue ; } else if ( ( ch & 0x80 ) != 0 ) { command = ch ; i ++ ; } if ( ( command & 0x80 ) == 0 ) { throw [ 'command error' , 'index' , i , 'track' , chunk ] ; } var l = CMDLEN [ command >> 4 ] ; if ( l > 0 ) { var evt = { time : time , command : [ command ] . concat ( Array . prototype . slice . call ( chunk . subarray ( i , i + l ) ) ) , } ; events . push ( evt ) ; i += l ; } } return events ; }
take a byte array of midi events and convert them to an array standard javascript objects
take a byte array of midi events and convert them to an array standard javascript objects
// ---- // meta // sysex // <-- that semicolon should be there