├── .gitignore ├── LICENSE ├── README.md ├── examples ├── basic-example.html └── whack-the-mole.html └── src └── launchpad.js /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Bas Biesheuvel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # web-midi-launchpad 2 | A Web Midi Api implementation of the Novation Launchpad functionality. 3 | 4 | Currently supports only the old Launchpad MK1 (because that is the one I have). 5 | 6 | > ONLY WORKS in browsers that support the web-midi-api 7 | 8 | ### Initialization 9 | web-midi-launchpad uses (as the name suggests) the web midi api (https://webaudio.github.io/web-midi-api/). 10 | Therefore it is required to initialize this api first by requesting midi access. Once midi access has been 11 | granted, a launchpad instance can be created using the autoDetectLaunchpad function: 12 | 13 | ```javascript 14 | navigator.requestMIDIAccess().then(midiAccess => { 15 | const launchpad = autoDetectLaunchpad(midiAccess); //new Launchpad(inputPort.port, outputPort.port); 16 | launchpad.clear(); 17 | 18 | // Do your stuff with launchpad 19 | 20 | }, msg => { 21 | console.log("Failed to get MIDI access - " + msg); 22 | }); 23 | ``` 24 | 25 | It is also possible to specify a midi interface name to retrieve the inputs and outputs for 26 | that specific midi interface: 27 | 28 | ```javascript 29 | autoDetectLaunchpad(midiAccess, 'Launchpad S'); 30 | ``` 31 | 32 | A Launchpad instance can also be created manually, specifying both input and output ports. 33 | This can be useful if multiple launchpads are combined and the inputs of one need to work 34 | with the outputs of another.. 35 | 36 | ```javascript 37 | new Launchpad(midiInputPort, midiOutputPort); 38 | ``` 39 | 40 | It is recommended to clear the launchpad state upon connecting to it to reset any previous state. 41 | 42 | ```javascript 43 | launchpad.clear(); 44 | ``` 45 | 46 | ### Setting / Clearing LEDs 47 | It's pretty simple to enable/disable the LEDs of the pads. web-midi-launchpad comes with two 48 | additional interfaces to make this easy, Pad (containing X Y coordinates) and Color (containing 49 | the green/red led values). 50 | 51 | ```javascript 52 | const pad = new Pad(row, column); 53 | 54 | // Make the led full green 55 | launchpad.ledOn(pad, new Color(3, 0)); 56 | 57 | // Make the led full red 58 | launchpad.ledOn(pad, new Color(0, 3)); 59 | 60 | // Make the led full yellow 61 | launchpad.ledOn(pad, new Color(3, 3)); 62 | 63 | // Dim the LED to off status 64 | launchpad.ledOff(pad); 65 | ``` 66 | 67 | > Note that row can contain a value from 1 to 8, column can contain a value from 1 to 9 (9 being the 68 | round button located at the end of the row). 69 | 70 | > Colors (green/red) can contain values from 0 (off) to 3 (full on). 71 | 72 | ### Control pads 73 | The top row of buttons on the Launchpad are generally used for Automap or Live features. Those buttons 74 | are called control pads. They work in the same way as normal pads. 75 | 76 | ```javascript 77 | // Make the led full green 78 | launchpad.controlLedOn(1, new Color(3, 0)); 79 | 80 | // Make the led full red 81 | launchpad.controlLedOn(1, new Color(0, 3)); 82 | 83 | // Make the led full yellow 84 | launchpad.controlLedOn(1, new Color(3, 3)); 85 | 86 | // Dim the LED to off status 87 | launchpad.controlLedOff(1); 88 | ``` 89 | 90 | > The control led number can range from 1 to 8 91 | 92 | ### Led flashing 93 | It is possible to configure the Launchpad so that it can flash specific LEDs. To enable 94 | flashing: 95 | 96 | ```javascript 97 | launchpad.enableFlashing(); 98 | ``` 99 | 100 | Then use the Color interface to specify flashing behavior per LED: 101 | 102 | ```javascript 103 | launchpad.controlLedOn(1, new Color(3, 0, true)); // True means flashing 104 | ``` 105 | 106 | Flashing can also be disabled. 107 | 108 | ```javascript 109 | launchpad.disableFlashing(); 110 | ``` 111 | 112 | Example 1, flashing all leds using the flashing mechanism. 113 | 114 | ```javascript 115 | launchpad.enableFlashing(); 116 | for (let row = 1; row < 9; row++) { 117 | for (let column = 1; column < 10; column++) { 118 | launchpad.ledOn(new Pad(row, column), new Color(3, 0, true)); 119 | } 120 | } 121 | ``` 122 | 123 | Example 2, flashing all leds manually. 124 | 125 | ```javascript 126 | const flashSpeed = 250; 127 | setInterval(() => { 128 | for (let row = 1; row < 9; row++) { 129 | for (let column = 1; column < 10; column++) { 130 | launchpad.ledOn(new Pad(row, column), new Color(3, 0, true)); 131 | } 132 | } 133 | setTimeout(() => { 134 | for (let row = 1; row < 9; row++) { 135 | for (let column = 1; column < 10; column++) { 136 | launchpad.ledOff(new Pad(row, column), new Color(3, 0, true)); 137 | } 138 | } 139 | }, flashSpeed / 2) 140 | }, flashSpeed); 141 | ``` 142 | 143 | ### Setting mapping mode 144 | It is possible to configure the Launchpad in one of two possible mapping modes. Drum mapping 145 | is experimental and Pad positions change so the Pad interface might not work as expected. 146 | 147 | ```javascript 148 | launchpad.setDrumMappingMode(); 149 | ``` 150 | 151 | Default is the XY mapping mode. 152 | 153 | ```javascript 154 | launchpad.setXYMappingMode(); 155 | ``` 156 | 157 | ### Handling pad presses 158 | The pads on the Launchpad can send events when either a pad is pressed or released, it is 159 | pretty easy to listen to those events. 160 | 161 | ```javascript 162 | launchpad.onPadPress(pad => console.log('Pad pressed', pad)); 163 | 164 | launchpad.onPadRelease(pad => console.log('Pad released', pad)); 165 | 166 | launchpad.onControlPadPress(pad => console.log('Control pad pressed', pad)); 167 | 168 | launchpad.onControlPadRelease(pad => console.log('Control pad released', pad)); 169 | 170 | ``` 171 | -------------------------------------------------------------------------------- /examples/basic-example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |Refresh the page with your launchpad attached and play a game of whack the mole. Check the console.log for your score.
23 | 24 |27 | | 28 | | 29 | | 30 | | 31 | | 32 | | 33 | | 34 | |
37 | | 38 | | 39 | | 40 | | 41 | | 42 | | 43 | | 44 | |
47 | | 48 | | 49 | | 50 | | 51 | | 52 | | 53 | | 54 | |
57 | | 58 | | 59 | | 60 | | 61 | | 62 | | 63 | | 64 | |
67 | | 68 | | 69 | | 70 | | 71 | | 72 | | 73 | | 74 | |
77 | | 78 | | 79 | | 80 | | 81 | | 82 | | 83 | | 84 | |
87 | | 88 | | 89 | | 90 | | 91 | | 92 | | 93 | | 94 | |
97 | | 98 | | 99 | | 100 | | 101 | | 102 | | 103 | | 104 | |