!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Keyboard=t():e.Keyboard=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return e[r].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}var a=function(){function e(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:36,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:4;i(this,t);var s=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return s._lowest=n,s._octaves=r,s._audioKeys=new c.default({polyphony:88,rows:1,octaveControls:!1}),s._audioKeys.down(function(e){s.keyDown(e.note),s.emit("keyDown",e.note)}),s._audioKeys.up(function(e){s.keyUp(e.note),s.emit("keyUp",e.note)}),s._keyboardInterface=new p.KeyboardElement(e,48,2),s._keyboardInterface.on("keyDown",function(e){s.keyDown(e),s.emit("keyDown",e)}),s._keyboardInterface.on("keyUp",function(e){s.keyUp(e),s.emit("keyUp",e)}),window.addEventListener("resize",s._resize.bind(s)),s._resize(),s._midi=new f.Midi,s._midi.on("keyDown",function(e){s.keyDown(e),s.emit("keyDown",e)}),s._midi.on("keyUp",function(e){s.keyUp(e),s.emit("keyUp",e)}),s}return s(t,e),a(t,[{key:"keyDown",value:function(e){this._keyboardInterface.keyDown(e)}},{key:"keyUp",value:function(e){this._keyboardInterface.keyUp(e)}},{key:"_resize",value:function(){this._keyboardInterface.resize(this._lowest,this._octaves)}},{key:"octaves",get:function(){return this._octaves},set:function(e){this._octaves=e,this._resize()}},{key:"rootNote",get:function(){return this._rootNote},set:function(e){this._lowest=e,this._resize()}}]),t}(l.default.EventEmitter);e.exports=d},function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(e){return"function"==typeof e}function i(e){return"number"==typeof e}function o(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}e.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,i,a,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}if(n=this._events[e],s(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:a=Array.prototype.slice.call(arguments,1),n.apply(this,a)}else if(o(n))for(a=Array.prototype.slice.call(arguments,1),c=n.slice(),i=c.length,u=0;u0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),i||(i=!0,t.apply(this,arguments))}if(!r(t))throw TypeError("listener must be a function");var i=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,i,s,a;if(!r(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],s=n.length,i=-1,n===t||r(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(n)){for(a=s;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){i=a;break}if(i<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],r(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?r(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(r(t))return 1;if(t)return t.length}return 0},n.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0}),t.KeyboardElement=void 0;var a=function(){function e(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:36,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:4;i(this,t);var s=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return s._container=document.createElement("div"),s._container.id="keyboard",e.setAttribute("touch-action","none"),e.addEventListener("pointerup",function(){return s._mousedown=!1}),e.appendChild(s._container),s._keys={},s._mousedown=!1,s.resize(n,r),s._aiNotes={},s._notes={},s}return s(t,e),a(t,[{key:"resize",value:function(e,t){this._keys={},this._container.innerHTML="";for(var n=1/7/t,r=e;r1&&void 0!==arguments[1]&&arguments[1];if(this._keys.hasOwnProperty(e)){var n=this._keys[e];n.classList.remove("hover");var r=new h.Note(n.querySelector("#fill"),t),i=t?this._aiNotes:this._notes;i[e]||(i[e]=[]),i[e].push(r)}}},{key:"keyUp",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this._keys.hasOwnProperty(e)){var n=t?this._aiNotes:this._notes;if(!n[e].length)throw new Error("note off without note on");n[e].shift().noteOff()}}}]),t}(c.default.EventEmitter);t.KeyboardElement=p},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0}),t.Midi=void 0;var a=function(){function e(e,t){for(var n=0;n=e._state.keys.length?e._state.keys=e._state.keys.map(function(e){return e.isActive=!0,e}):(e._state.keys=e._state.keys.map(function(e){return e.isActive=!1,e}),e["_"+e._state.priority]()),e._state.buffer=[],void e._state.keys.forEach(function(t){t.isActive&&e._state.buffer.push(t)})):void(e._state.buffer=[])},r.prototype._last=function(){for(var e=this,t=e._state.keys.length-e._state.polyphony;t=a}return this.firstXY=null,t}},findTouch:function(e,t){for(var n,r=0,i=e.length;r=t.length){var n=[];F.forEach(function(e,r){if(1!==r&&!this.findTouch(t,r-2)){var i=e.out;n.push(i)}},this),n.forEach(this.cancelOut,this)}},touchstart:function(e){this.vacuumTouches(e),this.setPrimaryTouch(e.changedTouches[0]),this.dedupSynthMouse(e),this.scrolling||(this.clickCount++,this.processTouches(e,this.overDown))},overDown:function(e){F.set(e.pointerId,{target:e.target,out:e,outTarget:e.target}),b.enterOver(e),b.down(e)},touchmove:function(e){this.scrolling||(this.shouldScroll(e)?(this.scrolling=!0,this.touchcancel(e)):(e.preventDefault(),this.processTouches(e,this.moveOverOut)))},moveOverOut:function(e){var t=e,n=F.get(t.pointerId);if(n){var r=n.out,i=n.outTarget;b.move(t),r&&i!==t.target&&(r.relatedTarget=t.target,t.relatedTarget=i,r.target=i,t.target?(b.leaveOut(r),b.enterOver(t)):(t.target=i,t.relatedTarget=null,this.cancelOut(t))),n.out=t,n.outTarget=t.target}},touchend:function(e){this.dedupSynthMouse(e),this.processTouches(e,this.upOut)},upOut:function(e){this.scrolling||(b.up(e),b.leaveOut(e)),this.cleanUpPointer(e)},touchcancel:function(e){this.processTouches(e,this.cancelOut)},cancelOut:function(e){b.cancel(e),b.leaveOut(e),this.cleanUpPointer(e)},cleanUpPointer:function(e){F.delete(e.pointerId),this.removePrimaryPointer(e)},dedupSynthMouse:function(e){var t=G.lastTouches,n=e.changedTouches[0];if(this.isPrimaryTouch(n)){var r={x:n.clientX,y:n.clientY};t.push(r);var i=function(e,t){var n=e.indexOf(t);n>-1&&e.splice(n,1)}.bind(null,t,r);setTimeout(i,K)}}};H=new n(z.elementAdded,z.elementRemoved,z.elementChanged,z);var q,W,V=b.pointermap,Q=window.MSPointerEvent&&"number"==typeof window.MSPointerEvent.MSPOINTER_TYPE_MOUSE,J={events:["MSPointerDown","MSPointerMove","MSPointerUp","MSPointerOut","MSPointerOver","MSPointerCancel","MSGotPointerCapture","MSLostPointerCapture"],register:function(e){b.listen(e,this.events)},unregister:function(e){b.unlisten(e,this.events)},POINTER_TYPES:["","unavailable","touch","pen","mouse"],prepareEvent:function(e){var t=e;return Q&&(t=b.cloneEvent(e),t.pointerType=this.POINTER_TYPES[e.pointerType]),t},cleanup:function(e){V.delete(e)},MSPointerDown:function(e){V.set(e.pointerId,e);var t=this.prepareEvent(e);b.down(t)},MSPointerMove:function(e){var t=this.prepareEvent(e);b.move(t)},MSPointerUp:function(e){var t=this.prepareEvent(e);b.up(t),this.cleanup(e.pointerId)},MSPointerOut:function(e){var t=this.prepareEvent(e);b.leaveOut(t)},MSPointerOver:function(e){var t=this.prepareEvent(e);b.enterOver(t)},MSPointerCancel:function(e){var t=this.prepareEvent(e);b.cancel(t),this.cleanup(e.pointerId)},MSLostPointerCapture:function(e){var t=b.makeEvent("lostpointercapture",e);b.dispatchEvent(t)},MSGotPointerCapture:function(e){var t=b.makeEvent("gotpointercapture",e);b.dispatchEvent(t)}},$=window.navigator;$.msPointerEnabled?(q=function(e){u(e),c(this),h(e)&&this.msSetPointerCapture(e)},W=function(e){u(e),this.msReleasePointerCapture(e)}):(q=function(e){u(e),c(this),h(e)&&b.setCapture(e,this)},W=function(e){u(e),b.releaseCapture(e,this)}),s(),a(),l();var Z={dispatcher:b,Installer:n,PointerEvent:e,PointerMap:v,targetFinding:g};return Z})},function(e,t,n){function r(e,t){for(var n=0;n=0&&E.splice(t,1)}function a(e){var t=document.createElement("style");return t.type="text/css",o(e,t),t}function u(e){var t=document.createElement("link");return t.rel="stylesheet",o(e,t),t}function c(e,t){var n,r,i;if(t.singleton){var o=_++;n=m||(m=a(t)),r=h.bind(null,n,o,!1),i=h.bind(null,n,o,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=u(t),r=p.bind(null,n),i=function(){s(n),n.href&&URL.revokeObjectURL(n.href)}):(n=a(t),r=l.bind(null,n),i=function(){s(n)});return r(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;r(e=t)}else i()}}function h(e,t,n,r){var i=n?"":r.css;if(e.styleSheet)e.styleSheet.cssText=b(t,i);else{var o=document.createTextNode(i),s=e.childNodes;s[t]&&e.removeChild(s[t]),s.length?e.insertBefore(o,s[t]):e.appendChild(o)}}function l(e,t){var n=t.css,r=t.media;if(r&&e.setAttribute("media",r),e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}function p(e,t){var n=t.css,r=t.sourceMap;r&&(n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");var i=new Blob([n],{type:"text/css"}),o=e.href;e.href=URL.createObjectURL(i),o&&URL.revokeObjectURL(o)}var f={},d=function(e){var t;return function(){return"undefined"==typeof t&&(t=e.apply(this,arguments)),t}},v=d(function(){return/msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase())}),y=d(function(){return document.head||document.getElementsByTagName("head")[0]}),m=null,_=0,E=[];e.exports=function(e,t){t=t||{},"undefined"==typeof t.singleton&&(t.singleton=v()),"undefined"==typeof t.insertAt&&(t.insertAt="bottom");var n=i(e);return r(n,t),function(e){for(var o=[],s=0;s=0))throw new TypeError("The specified event type is not supported.");return this._userHandlers[e].push(t),this},o.prototype.hasListener=function(e,t){if(!this.enabled)throw new Error("WebMidi must be enabled before checking event listeners.");if("function"!=typeof t)throw new TypeError("The 'listener' parameter must be a function.");if(!(this._midiInterfaceEvents.indexOf(e)>=0))throw new TypeError("The specified event type is not supported.");for(var n=0;n=0)if(t)for(var n=0;n=0&&127>=e?t=Math.round(e):parseInt(e)>=0&&parseInt(e)<=127?t=parseInt(e):("string"==typeof e||e instanceof String)&&(t=this.noteNameToNumber(e)),t===!1)throw new Error("Invalid note number ("+e+").");return t},o.prototype.noteNameToNumber=function(e){"string"!=typeof e&&(e="");var t=e.match(/([CDEFGAB])(#{0,2}|b{0,2})(-?\d+)/i);if(!t)throw new RangeError("Invalid note name.");var n=u._semitones[t[1].toUpperCase()],r=parseInt(t[3]),i=12*(r+2)+n;if(t[2].toLowerCase().indexOf("b")>-1?i-=t[2].length:t[2].toLowerCase().indexOf("#")>-1&&(i+=t[2].length),0>n||-2>r||r>8||0>i||i>127)throw new RangeError("Invalid note name or note outside valid range.");return i},o.prototype._updateInputsAndOutputs=function(){this._updateInputs(),this._updateOutputs()},o.prototype._updateInputs=function(){for(var e=0;e0;)this._processStateChange(this._stateChangeQueue.shift());this._processingStateChange=!1}},o.prototype._processStateChange=function(e){if(this._updateInputsAndOutputs(),null!==e){var t={timestamp:e.timeStamp,type:e.port.state,id:e.port.id,manufacturer:e.port.manufacturer,name:e.port.name};"connected"===e.port.state&&("output"===e.port.type?t.output=this.getOutputById(e.port.id):"input"===e.port.type&&(t.input=this.getInputById(e.port.id))),this._userHandlers[e.port.state].forEach(function(e){e(t)})}},o.prototype._resetInterfaceUserHandlers=function(){for(var e=0;e=1&&16>=e))throw new RangeError("The 'channel' parameter is invalid.")}),"function"!=typeof n)throw new TypeError("The 'listener' parameter must be a function.");if(u.MIDI_SYSTEM_MESSAGES[e])this._userHandlers.system[e]||(this._userHandlers.system[e]=[]),this._userHandlers.system[e].push(n);else{if(!u.MIDI_CHANNEL_MESSAGES[e])throw new TypeError("The specified event type is not supported.");if(t.indexOf("all")>-1){t=[];for(var i=1;16>=i;i++)t.push(i)}this._userHandlers.channel[e]||(this._userHandlers.channel[e]=[]),t.forEach(function(t){r._userHandlers.channel[e][t]||(r._userHandlers.channel[e][t]=[]),r._userHandlers.channel[e][t].push(n)})}return this},s.prototype.on=s.prototype.addListener,s.prototype.hasListener=function(e,t,n){var r=this;if("function"!=typeof n)throw new TypeError("The 'listener' parameter must be a function.");if(void 0===t&&(t="all"),t.constructor!==Array&&(t=[t]),u.MIDI_SYSTEM_MESSAGES[e]){for(var i=0;i-1){t=[];for(var o=1;16>=o;o++)t.push(o)}return!!this._userHandlers.channel[e]&&t.every(function(t){var i=r._userHandlers.channel[e][t];return i&&i.indexOf(n)>-1})}return!1},s.prototype.removeListener=function(e,t,n){ var r=this;if(void 0!==n&&"function"!=typeof n)throw new TypeError("The 'listener' parameter must be a function.");if(void 0===t&&(t="all"),t.constructor!==Array&&(t=[t]),u.MIDI_SYSTEM_MESSAGES[e])if(void 0===n)this._userHandlers.system[e]=[];else for(var i=0;i-1){t=[];for(var o=1;16>=o;o++)t.push(o)}if(!this._userHandlers.channel[e])return this;t.forEach(function(t){var i=r._userHandlers.channel[e][t];if(i)if(void 0===n)r._userHandlers.channel[e][t]=[];else for(var o=0;o>4,i=(15&e.data[0])+1;e.data.length>1&&(t=e.data[1],n=e.data.length>2?e.data[2]:void 0);var o={target:this,data:e.data,timestamp:e.timeStamp,channel:i};r===u.MIDI_CHANNEL_MESSAGES.noteoff||r===u.MIDI_CHANNEL_MESSAGES.noteon&&0===n?(o.type="noteoff",o.note={number:t,name:u._notes[t%12],octave:Math.floor(t/12-1)-3},o.velocity=n/127,o.rawVelocity=n):r===u.MIDI_CHANNEL_MESSAGES.noteon?(o.type="noteon",o.note={number:t,name:u._notes[t%12],octave:Math.floor(t/12-1)-3},o.velocity=n/127,o.rawVelocity=n):r===u.MIDI_CHANNEL_MESSAGES.keyaftertouch?(o.type="keyaftertouch",o.note={number:t,name:u._notes[t%12],octave:Math.floor(t/12-1)-3},o.value=n/127):r===u.MIDI_CHANNEL_MESSAGES.controlchange&&t>=0&&119>=t?(o.type="controlchange",o.controller={number:t,name:this.getCcNameByNumber(t)},o.value=n):r===u.MIDI_CHANNEL_MESSAGES.channelmode&&t>=120&&127>=t?(o.type="channelmode",o.controller={number:t,name:this.getChannelModeByNumber(t)},o.value=n):r===u.MIDI_CHANNEL_MESSAGES.programchange?(o.type="programchange",o.value=t):r===u.MIDI_CHANNEL_MESSAGES.channelaftertouch?(o.type="channelaftertouch",o.value=t/127):r===u.MIDI_CHANNEL_MESSAGES.pitchbend?(o.type="pitchbend",o.value=((n<<7)+t-8192)/8192):o.type="unknownchannelmessage",this._userHandlers.channel[o.type]&&this._userHandlers.channel[o.type][i]&&this._userHandlers.channel[o.type][i].forEach(function(e){e(o)})},s.prototype.getCcNameByNumber=function(e){if(e=parseInt(e),!(e>=0&&119>=e))throw new RangeError("The control change number must be between 0 and 119.");for(var t in u.MIDI_CONTROL_CHANGE_MESSAGES)if(e===u.MIDI_CONTROL_CHANGE_MESSAGES[t])return t},s.prototype.getChannelModeByNumber=function(e){if(e=parseInt(e),!(e>=120&&status<=127))throw new RangeError("The control change number must be between 120 and 127.");for(var t in u.MIDI_CHANNEL_MODE_MESSAGES)if(e===u.MIDI_CHANNEL_MODE_MESSAGES[t])return t},s.prototype._parseSystemEvent=function(e){var t=e.data[0],n={target:this,data:e.data,timestamp:e.timeStamp};t===u.MIDI_SYSTEM_MESSAGES.sysex?n.type="sysex":t===u.MIDI_SYSTEM_MESSAGES.timecode?n.type="timecode":t===u.MIDI_SYSTEM_MESSAGES.songposition?n.type="songposition":t===u.MIDI_SYSTEM_MESSAGES.songselect?(n.type="songselect",n.song=e.data[1]):t===u.MIDI_SYSTEM_MESSAGES.tuningrequest?n.type="tuningrequest":t===u.MIDI_SYSTEM_MESSAGES.clock?n.type="clock":t===u.MIDI_SYSTEM_MESSAGES.start?n.type="start":t===u.MIDI_SYSTEM_MESSAGES.continue?n.type="continue":t===u.MIDI_SYSTEM_MESSAGES.stop?n.type="stop":t===u.MIDI_SYSTEM_MESSAGES.activesensing?n.type="activesensing":t===u.MIDI_SYSTEM_MESSAGES.reset?n.type="reset":n.type="unknownsystemmessage",this._userHandlers.system[n.type]&&this._userHandlers.system[n.type].forEach(function(e){e(n)})},a.prototype.send=function(e,t,n){if(!(e>=128&&255>=e))throw new RangeError("The status byte must be an integer between 128 (0x80) and 255 (0xFF).");Array.isArray(t)||(t=parseInt(t)>=0&&parseInt(t)<=127?[parseInt(t)]:[]);var r=[e];return t.forEach(function(e){if(!(e>=0&&255>=e))throw new RangeError("The data bytes must be integers between 0 (0x00) and 255 (0xFF).");r.push(e)}),this._midiOutput.send(r,parseFloat(n)||0),this},a.prototype.sendSysex=function(e,t,n){if(!u.sysexEnabled)throw new Error("SysEx message support must first be activated.");return n=n||{},e=[].concat(e),t.forEach(function(e){if(0>e||e>127)throw new RangeError("The data bytes of a SysEx message must be integers between 0 (0x00) and 127 (0x7F).")}),t=e.concat(t,u.MIDI_SYSTEM_MESSAGES.sysexend),this.send(u.MIDI_SYSTEM_MESSAGES.sysex,t,n.time),this},a.prototype.sendTimecodeQuarterFrame=function(e,t){return t=t||{},this.send(u.MIDI_SYSTEM_MESSAGES.timecode,e,t.time),this},a.prototype.sendSongPosition=function(e,t){e=parseInt(e)||0,t=t||{};var n=e>>7&127,r=127&e;return this.send(u.MIDI_SYSTEM_MESSAGES.songposition,[n,r],t.time),this},a.prototype.sendSongSelect=function(e,t){if(e=parseInt(e),t=t||{},!(e>=0&&127>=e))throw new RangeError("The song number must be between 0 and 127.");return this.send(u.MIDI_SYSTEM_MESSAGES.songselect,[e],t.time),this},a.prototype.sendTuningRequest=function(e){return e=e||{},this.send(u.MIDI_SYSTEM_MESSAGES.tuningrequest,void 0,e.time),this},a.prototype.sendClock=function(e){return e=e||{},this.send(u.MIDI_SYSTEM_MESSAGES.clock,void 0,e.time),this},a.prototype.sendStart=function(e){return e=e||{},this.send(u.MIDI_SYSTEM_MESSAGES.start,void 0,e.time),this},a.prototype.sendContinue=function(e){return e=e||{},this.send(u.MIDI_SYSTEM_MESSAGES.continue,void 0,e.time),this},a.prototype.sendStop=function(e){return e=e||{},this.send(u.MIDI_SYSTEM_MESSAGES.stop,void 0,e.time),this},a.prototype.sendActiveSensing=function(e){return e=e||{},this.send(u.MIDI_SYSTEM_MESSAGES.activesensing,void 0,e.time),this},a.prototype.sendReset=function(e){return e=e||{},this.send(u.MIDI_SYSTEM_MESSAGES.reset,void 0,e.time),this},a.prototype.stopNote=function(e,t,n){if("all"===e)return this.sendChannelMode("allnotesoff",0,t,n);var r=64;return n=n||{},n.velocity=parseFloat(n.velocity),n.rawVelocity?!isNaN(n.velocity)&&n.velocity>=0&&n.velocity<=127&&(r=n.velocity):!isNaN(n.velocity)&&n.velocity>=0&&n.velocity<=1&&(r=127*n.velocity),this._convertNoteToArray(e).forEach(function(e){this._convertChannelToArray(t).forEach(function(t){this.send((u.MIDI_CHANNEL_MESSAGES.noteoff<<4)+(t-1),[e,Math.round(r)],this._parseTimeParameter(n.time))}.bind(this))}.bind(this)),this},a.prototype.playNote=function(e,t,n){var r=64;if(n=n||{},n.velocity=parseFloat(n.velocity),n.rawVelocity?!isNaN(n.velocity)&&n.velocity>=0&&n.velocity<=127&&(r=n.velocity):!isNaN(n.velocity)&&n.velocity>=0&&n.velocity<=1&&(r=127*n.velocity),n.time=this._parseTimeParameter(n.time)||0,this._convertNoteToArray(e).forEach(function(e){this._convertChannelToArray(t).forEach(function(t){this.send((u.MIDI_CHANNEL_MESSAGES.noteon<<4)+(t-1),[e,Math.round(r)],n.time)}.bind(this))}.bind(this)),void 0!==n.duration){var i=64;n.release=parseFloat(n.release),n.rawVelocity?!isNaN(n.release)&&n.release>=0&&n.release<=127&&(i=n.release):!isNaN(n.release)&&n.release>=0&&n.release<=1&&(i=127*n.release),this._convertNoteToArray(e).forEach(function(e){this._convertChannelToArray(t).forEach(function(t){this.send((u.MIDI_CHANNEL_MESSAGES.noteoff<<4)+(t-1),[e,Math.round(i)],n.time+n.duration)}.bind(this))}.bind(this))}return this},a.prototype.sendKeyAftertouch=function(e,t,n,r){var i=this;if(r=r||{},1>t||t>16)throw new RangeError("The channel must be between 1 and 16.");n=parseFloat(n),(isNaN(n)||0>n||n>1)&&(n=.5);var o=Math.round(127*n);return this._convertNoteToArray(e).forEach(function(e){i._convertChannelToArray(t).forEach(function(t){i.send((u.MIDI_CHANNEL_MESSAGES.keyaftertouch<<4)+(t-1),[e,o],i._parseTimeParameter(r.time))})}),this},a.prototype.sendControlChange=function(e,t,n,r){if(r=r||{},"string"==typeof e){if(e=u.MIDI_CONTROL_CHANGE_MESSAGES[e],!e)throw new TypeError("Invalid controller name.")}else if(e=parseInt(e),!(e>=0&&119>=e))throw new RangeError("Controller numbers must be between 0 and 119.");if(t=parseInt(t)||0,!(t>=0&&127>=t))throw new RangeError("Controller value must be between 0 and 127.");return this._convertChannelToArray(n).forEach(function(n){this.send((u.MIDI_CHANNEL_MESSAGES.controlchange<<4)+(n-1),[e,t],this._parseTimeParameter(r.time))}.bind(this)),this},a.prototype._selectRegisteredParameter=function(e,t,n){var r=this;if(e[0]=parseInt(e[0]),!(e[0]>=0&&e[0]<=127))throw new RangeError("The control65 value must be between 0 and 127");if(e[1]=parseInt(e[1]),!(e[1]>=0&&e[1]<=127))throw new RangeError("The control64 value must be between 0 and 127");return this._convertChannelToArray(t).forEach(function(i){r.sendControlChange(101,e[0],t,{time:n}),r.sendControlChange(100,e[1],t,{time:n})}),this},a.prototype._selectNonRegisteredParameter=function(e,t,n){var r=this;if(e[0]=parseInt(e[0]),!(e[0]>=0&&e[0]<=127))throw new RangeError("The control63 value must be between 0 and 127");if(e[1]=parseInt(e[1]),!(e[1]>=0&&e[1]<=127))throw new RangeError("The control62 value must be between 0 and 127");return this._convertChannelToArray(t).forEach(function(i){r.sendControlChange(99,e[0],t,{time:n}),r.sendControlChange(98,e[1],t,{time:n})}),this},a.prototype._setCurrentRegisteredParameter=function(e,t,n){var r=this;if(e=[].concat(e),e[0]=parseInt(e[0]),!(e[0]>=0&&e[0]<=127))throw new RangeError("The msb value must be between 0 and 127");return this._convertChannelToArray(t).forEach(function(i){r.sendControlChange(6,e[0],t,{time:n})}),e[1]=parseInt(e[1]),e[1]>=0&&e[1]<=127&&this._convertChannelToArray(t).forEach(function(i){r.sendControlChange(38,e[1],t,{time:n})}),this},a.prototype._deselectRegisteredParameter=function(e,t){var n=this;return this._convertChannelToArray(e).forEach(function(r){n.sendControlChange(101,127,e,{time:t}),n.sendControlChange(100,127,e,{time:t})}),this},a.prototype.setRegisteredParameter=function(e,t,n,r){var i=this;if(r=r||{},!Array.isArray(e)){if(!u.MIDI_REGISTERED_PARAMETER[e])throw new Error("The specified parameter is not available.");e=u.MIDI_REGISTERED_PARAMETER[e]}return this._convertChannelToArray(n).forEach(function(o){i._selectRegisteredParameter(e,n,r.time),i._setCurrentRegisteredParameter(t,n,r.time),i._deselectRegisteredParameter(n,r.time)}),this},a.prototype.setNonRegisteredParameter=function(e,t,n,r){var i=this;if(r=r||{},!(e[0]>=0&&e[0]<=127&&e[1]>=0&&e[1]<=127))throw new Error("Position 0 and 1 of the 2-position parameter array must both be between 0 and 127.");return t=[].concat(t),this._convertChannelToArray(n).forEach(function(o){i._selectNonRegisteredParameter(e,n,r.time),i._setCurrentRegisteredParameter(t,n,r.time),i._deselectRegisteredParameter(n,r.time)}),this},a.prototype.incrementRegisteredParameter=function(e,t,n){var r=this;if(n=n||{},!Array.isArray(e)){if(!u.MIDI_REGISTERED_PARAMETER[e])throw new Error("The specified parameter is not available.");e=u.MIDI_REGISTERED_PARAMETER[e]}return this._convertChannelToArray(t).forEach(function(i){r._selectRegisteredParameter(e,t,n.time),r.sendControlChange(96,0,t,{time:n.time}),r._deselectRegisteredParameter(t,n.time)}),this},a.prototype.decrementRegisteredParameter=function(e,t,n){if(n=n||{},!Array.isArray(e)){if(!u.MIDI_REGISTERED_PARAMETER[e])throw new TypeError("The specified parameter is not available.");e=u.MIDI_REGISTERED_PARAMETER[e]}return this._convertChannelToArray(t).forEach(function(r){this._selectRegisteredParameter(e,t,n.time),this.sendControlChange(97,0,t,{time:n.time}),this._deselectRegisteredParameter(t,n.time)}.bind(this)),this},a.prototype.setPitchBendRange=function(e,t,n,r){var i=this;if(r=r||{},e=parseInt(e)||0,!(e>=0&&127>=e))throw new RangeError("The semitones value must be between 0 and 127");if(t=parseInt(t)||0,!(t>=0&&127>=t))throw new RangeError("The cents value must be between 0 and 127");return this._convertChannelToArray(n).forEach(function(o){i.setRegisteredParameter("pitchbendrange",[e,t],n,{time:r.time})}),this},a.prototype.setModulationRange=function(e,t,n,r){var i=this;if(r=r||{},e=parseInt(e)||0,!(e>=0&&127>=e))throw new RangeError("The semitones value must be between 0 and 127");if(t=parseInt(t)||0,!(t>=0&&127>=t))throw new RangeError("The cents value must be between 0 and 127");return this._convertChannelToArray(n).forEach(function(o){i.setRegisteredParameter("modulationrange",[e,t],n,{time:r.time})}),this},a.prototype.setMasterTuning=function(e,t,n){var r=this;if(n=n||{},e=parseFloat(e)||0,-65>=e||e>=64)throw new RangeError("The value must be a decimal number larger than -65 and smaller than 64.");var i=parseInt(e)+64,o=e-parseInt(e);o=Math.round((o+1)/2*16383);var s=o>>7&127,a=127&o;return this._convertChannelToArray(t).forEach(function(e){r.setRegisteredParameter("channelcoarsetuning",i,t,{time:n.time}),r.setRegisteredParameter("channelfinetuning",[s,a],t,{time:n.time})}),this},a.prototype.setTuningProgram=function(e,t,n){var r=this;if(n=n||{},e=parseInt(e)||0,!(e>=0&&127>=e))throw new RangeError("The program value must be between 0 and 127");return this._convertChannelToArray(t).forEach(function(i){r.setRegisteredParameter("tuningprogram",e,t,{time:n.time})}),this},a.prototype.setTuningBank=function(e,t,n){var r=this;if(n=n||{},e=parseInt(e)||0,!(e>=0&&127>=e))throw new RangeError("The bank value must be between 0 and 127");return this._convertChannelToArray(t).forEach(function(i){r.setRegisteredParameter("tuningbank",e,t,{time:n.time})}),this},a.prototype.sendChannelMode=function(e,t,n,r){var i=this;if(r=r||{},"string"==typeof e){if(e=u.MIDI_CHANNEL_MODE_MESSAGES[e],!e)throw new TypeError("Invalid channel mode message name.")}else if(e=parseInt(e),!(e>=120&&127>=e))throw new RangeError("Channel mode numerical identifiers must be between 120 and 127.");if(t=parseInt(t),isNaN(t)||0>t||t>127)throw new RangeError("Value must be integers between 0 and 127.");return this._convertChannelToArray(n).forEach(function(n){i.send((u.MIDI_CHANNEL_MESSAGES.channelmode<<4)+(n-1),[e,t],i._parseTimeParameter(r.time))}),this},a.prototype.sendProgramChange=function(e,t,n){var r=this;if(n=n||{},e=parseInt(e),isNaN(e)||0>e||e>127)throw new RangeError("Program numbers must be between 0 and 127.");return this._convertChannelToArray(t).forEach(function(t){r.send((u.MIDI_CHANNEL_MESSAGES.programchange<<4)+(t-1),[e],r._parseTimeParameter(n.time))}),this},a.prototype.sendChannelAftertouch=function(e,t,n){var r=this;n=n||{},e=parseFloat(e),(isNaN(e)||0>e||e>1)&&(e=.5);var i=Math.round(127*e);return this._convertChannelToArray(t).forEach(function(e){r.send((u.MIDI_CHANNEL_MESSAGES.channelaftertouch<<4)+(e-1),[i],r._parseTimeParameter(n.time))}),this},a.prototype.sendPitchBend=function(e,t,n){var r=this;if(n=n||{},e=parseFloat(e),isNaN(e)||-1>e||e>1)throw new RangeError("Pitch bend value must be between -1 and 1.");var i=Math.round((e+1)/2*16383),o=i>>7&127,s=127&i;return this._convertChannelToArray(t).forEach(function(e){r.send((u.MIDI_CHANNEL_MESSAGES.pitchbend<<4)+(e-1),[s,o],r._parseTimeParameter(n.time))}),this},a.prototype._parseTimeParameter=function(e){var t;if(void 0===e)return 0;if(e&&e.substring&&"+"===e.substring(0,1)){if(t=parseFloat(e),!t)throw new TypeError("Invalid relative time format.");return t+u.time}if(t=parseFloat(e),!t)throw new TypeError("Invalid absolute time format.");return t},a.prototype._convertNoteToArray=function(e){var t=[];return Array.isArray(e)||(e=[e]),e.forEach(function(e){t.push(u.guessNoteNumber(e))}),t},a.prototype._convertChannelToArray=function(e){if(("all"===e||void 0===e)&&(e=["all"]),Array.isArray(e)||(e=[e]),e.indexOf("all")>-1){e=[];for(var t=1;16>=t;t++)e.push(t)}return e.forEach(function(e){if(!(e>=1&&16>=e))throw new RangeError("MIDI channels must be between 1 and 16.")}),e},a.prototype._onMidiMessage=function(e){},r=[],i=function(){return u}.apply(t,r),!(void 0!==i&&(e.exports=i))}(this)}])});