{"ScriptPreparationCode":null,"TestCases":[{"Name":"Simple Lookup Version","Code":"function getLowBits(byte, numBits){\r\n return ((byte \u003E\u003E numBits \u003C\u003C numBits) ^ byte)\r\n}\r\n\r\nlet actions = {\r\n 0x9: [{id:\u0022note_on\u0022, hiByte0: 0x9, loByte0: \u0027\u0027, type:\u0022simple\u0022, getAction(bytes){return createAction(bytes, this)}}],\r\n 0x8: [\r\n {id:\u0022bank_select\u0022, hiByte0: 0x9, loByte0: \u0027\u0027, secondary:[0x00, 0x20], type:\u0022msblsb\u0022, getAction(bytes){return createAction2(bytes, this)}},\r\n {id:\u0022mod_wheel\u0022, hiByte0: 0x9, loByte0: \u0027\u0027, secondary:[0x01, 0x21], type:\u0022msblsb\u0022, getAction(bytes){return createAction2(bytes, this)}}\r\n ]\r\n}\r\n\r\nfunction createAction(bytes, action){\r\n return {id: action.id, channel: getLowBits(bytes[0], 4), type: \u0022\u0022, note: bytes[1], volume: bytes[2]} \r\n \r\n}\r\n\r\nfunction createAction2(bytes, action){\r\n if (action.type === \u0022msblsb\u0022){\r\n let i = action.secondary.indexOf(bytes[1])\r\n if (i!==-1){\r\n return {id: action.id, channel: getLowBits(bytes[0], 4), type: i=0?\u0022msb\u0022:\u0022lsb\u0022, value: bytes[2]} \r\n // its a match! dunno if high or low\r\n } else {\r\n return null // no match\r\n }\r\n }\r\n return null\r\n}\r\n\r\nlet midi = [0x85, 0x21, 0x64]\r\n//let midi = [0x95, 0x21, 0x64]\r\nlet hiByte = midi[0]\u003E\u003E 4\r\nlet matches = actions[hiByte]\r\nlet result\r\nif (matches.length \u003E 1){\r\n for (let i = 0; i \u003C matches.length; i\u002B\u002B) {\r\n result = matches[i].getAction(midi);\r\n if (result){\r\n //console.log(JSON.stringify(result)) \r\n break;\r\n }\r\n \r\n }\r\n} else {\r\n result = matches[0].getAction(midi)\r\n //console.log(JSON.stringify(result))\r\n}\r\n","IsDeferred":false},{"Name":"With lookup Loop","Code":"function getLowBits(byte, numBits){\r\n return ((byte \u003E\u003E numBits \u003C\u003C numBits) ^ byte)\r\n}\r\n\r\nlet actions = {\r\n 0x9: [{id:\u0022note_on\u0022, hiByte0: 0x9, loByte0: \u0027\u0027, type:\u0022simple\u0022, getAction(bytes){return createAction(bytes, this)}}],\r\n 0x8: [\r\n {id:\u0022bank_select\u0022, hiByte0: 0x9, loByte0: \u0027\u0027, secondary:[0x00, 0x20], type:\u0022msblsb\u0022, getAction(bytes){return createAction2(bytes, this)}},\r\n {id:\u0022mod_wheel\u0022, hiByte0: 0x9, loByte0: \u0027\u0027, secondary:[0x01, 0x21], type:\u0022msblsb\u0022, getAction(bytes){return createAction2(bytes, this)}}\r\n ]\r\n}\r\n\r\nfunction createAction(bytes, action){\r\n if (action.type===\u0022simple\u0022){\r\n return {id: action.id, channel: getLowBits(bytes[0], 4), type: \u0022\u0022, note: bytes[1], volume: bytes[2]} \r\n }\r\n}\r\n\r\nfunction createAction2(bytes, action){\r\n if (action.type === \u0022msblsb\u0022){\r\n let i = action.secondary.indexOf(bytes[1])\r\n if (i!==-1){\r\n return {id: action.id, channel: getLowBits(bytes[0], 4), type: i=0?\u0022msb\u0022:\u0022lsb\u0022, value: bytes[2]} \r\n // its a match! dunno if high or low\r\n } else {\r\n return null // no match\r\n }\r\n }\r\n return null\r\n}\r\n\r\n//let midi = [0x85, 0x21, 0x64]\r\nlet midi = [0x95, 0x21, 0x64]\r\nlet hiByte = midi[0]\u003E\u003E 4\r\nlet matches = actions[hiByte]\r\nlet result\r\nif (matches.length \u003E 1){\r\n for (let i = 0; i \u003C matches.length; i\u002B\u002B) {\r\n result = matches[i].getAction(midi);\r\n if (result){\r\n //console.log(JSON.stringify(result)) \r\n break;\r\n }\r\n \r\n }\r\n} else {\r\n result = matches[0].getAction(midi)\r\n //console.log(JSON.stringify(result))\r\n}\r\n","IsDeferred":false}]}