-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunchpad.min.js
2 lines (2 loc) · 3.73 KB
/
launchpad.min.js
1
2
!function(t){var n=t.Observable=function(){this.observers={}};n.prototype.on=function(t,n){"function"==typeof n&&(this.observers[t]=this.observers[t]||[]).push(n)},n.prototype.emit=function(t){var n=Array.prototype.slice.call(arguments,1);(this.observers[t]||[]).forEach(function(t){t.apply(void 0,n)})}}(window.launchpad=window.launchpad||{}),function(t){var n=t.Button=function(n,e,i){t.Observable.call(this),this.channel=n,this.note=e,this.midiAdapter=i,this.id=this.note,this.isControl()?this.id-=104:(this.x=this.note%16,this.y=Math.floor(this.note/16))};n.prototype=Object.create(t.Observable.prototype),n.prototype.constructor=n,n.prototype.turn=function(n){this.paint(t.defaults.paintNames[n])},n.prototype.paint=function(n){n=t.extend(n,{red:0,green:0});var e=n.green%4*16+n.red%4;this.send(e)},n.prototype.send=function(t){this.midiAdapter.send(this.channel,this.note,t)},n.prototype.isControl=function(){return 176===this.channel}}(window.launchpad=window.launchpad||{}),function(t,n){function e(t){return{from:function(e){for(var i=e.next();!i.done;){if(i.value.name===t)return i.value;i=e.next()}return n}}}var i=t.defaults={};i.paintNames={red:{red:3,green:0},green:{red:0,green:3},orange:{red:3,green:3}},i.name="Launchpad Mini MIDI 1",i.sysex=!1,i.midiAdapterFactory=function(n,i){if(navigator.requestMIDIAccess){var o=this.name;navigator.requestMIDIAccess({sysex:this.sysex}).then(function(t){return{input:e(o).from(t.inputs.values()),output:e(o).from(t.outputs.values())}}).then(function(n){return new t.MidiAdapter(n.input,n.output)}).then(function(n){return new t.Launchpad(n)}).then(function(t){n(t)})["catch"](i)}else i()}}(window.launchpad=window.launchpad||{}),function(t){t.extend=function(){return Array.prototype.slice.call(arguments).reduce(function(t,n){for(var e in n)n.hasOwnProperty(e)&&!t.hasOwnProperty(e)&&(t[e]=n[e]);return t},{})}}(window.launchpad=window.launchpad||{}),function(t){t.connect=function(n){return n=t.extend(n||{},t.defaults),new Promise(n.midiAdapterFactory.bind(n))}}(window.launchpad=window.launchpad||{}),function(t){var n=t.MidiAdapter=function(n,e){t.Observable.call(this),this.input=n,this.output=e,this.input.onmidimessage=this.onMidiMessageCallback.bind(this)};n.prototype=Object.create(t.Observable.prototype),n.prototype.constructor=n,n.prototype.onMidiMessageCallback=function(t){var n=t.data[0],e=t.data[1],i=t.data[2];this.emit("input",n,e,i)},n.prototype.send=function(t,n,e){this.output.send([t,n,e])}}(window.launchpad=window.launchpad||{}),function(t){var n=[{applies:function(t,n,e){return 127===e},handle:function(n,e,i,o){n.emit("press",new t.Button(e,i,n.midiAdapter))}},{applies:function(t,n,e){return 0===e},handle:function(n,e,i,o){n.emit("release",new t.Button(e,i,n.midiAdapter))}}],e=[{applies:function(t){return 1===t.length},lookup:function(n,e){return new t.Button(144,e[0],n.midiAdapter)}},{applies:function(t){return 2===t.length},lookup:function(n,e){return new t.Button(144,e[0]+16*e[1],n.midiAdapter)}}],i=t.Launchpad=function(n){t.Observable.call(this),this.midiAdapter=n,this.midiAdapter.on("input",this.handleInput.bind(this))};i.prototype=Object.create(t.Observable.prototype),i.prototype.constructor=i,i.prototype.handleInput=function(t,e,i){n.filter(function(n){return n.applies(t,e,i)}).forEach(function(n){n.handle(this,t,e,i)}.bind(this))},i.prototype.clear=function(){this.midiAdapter.send(176,0,0)},i.prototype.button=function(){var t=Array.prototype.slice.call(arguments);return e.filter(function(n){return n.applies(t)}).map(function(n){return n.lookup(this,t)}.bind(this))[0]},i.prototype.controlButton=function(n){return new t.Button(176,104+n,this.midiAdapter)}}(window.launchpad=window.launchpad||{}),function(t){t.version="1.0.0"}(window.launchpad=window.launchpad||{});
//# sourceMappingURL=launchpad.min.js.map