|
3 | 3 | Interact with your launchpads in Node.js
|
4 | 4 |
|
5 | 5 | Launchpad running an [example script](./examples/example.js)
|
6 |
| - |
| 6 | + |
| 7 | + |
7 | 8 |
|
8 | 9 | This project started as a module for my own stream system to make several things interact with OBS studio, named [rewards-interaction][rewards-interaction].
|
9 | 10 | After re-writing a broken launchpad library I decided to release the library to the public so everyone can enjoy easy programming on their launchpad.
|
10 | 11 |
|
11 | 12 | Some sample programs can be found in the [examples folder](./examples).
|
12 | 13 |
|
13 |
| -### Launchpad models currently supported |
| 14 | +## Launchpad models currently supported |
| 15 | + |
14 | 16 | - Launchpad MK2
|
| 17 | +- Launchpad MK3 (only tested with Mini) |
| 18 | + |
| 19 | +### Why are only these launchpads supported? |
15 | 20 |
|
16 |
| -##### Why are only these launchpads supported? |
17 | 21 | These launchpads are supported because I own them myself and have been able to test them.
|
18 | 22 | If a launchpad is not listed here it means that I do not own one and have not been able to test that one with the program.
|
19 | 23 |
|
20 |
| -### Examples |
| 24 | +## Examples |
| 25 | + |
21 | 26 | More examples can be found in the [examples folder](./examples), this is just a simple button listener.
|
| 27 | + |
22 | 28 | ```js
|
23 |
| -const { LaunchpadMK2, colors } = require('launchpad.js'); |
| 29 | +const { autoDetect, colors } = require('launchpad.js'); |
24 | 30 | const { colorFromHex, defaultColors } = colors;
|
25 | 31 |
|
26 |
| -// we are enabling xyMode here |
27 |
| -const lp = new lpJs.LaunchpadMK2({ xyMode: true }); |
| 32 | +const lp = autoDetect(); |
| 33 | + |
| 34 | +// Alternatively: |
| 35 | +// |
| 36 | +// await waitForReady(lp); |
28 | 37 |
|
29 | 38 | lp.once('ready', (deviceName) => {
|
30 | 39 | console.log(`${deviceName} is ready!!`);
|
31 | 40 |
|
32 |
| - lp.on('buttonDown', (button, value) => { |
33 |
| - // generate a random color on each button press |
| 41 | + lp.on('buttonDown', (button) => { |
| 42 | + // Generate a random color on each button press |
34 | 43 | const randHex = Math.floor(Math.random() * 16777215).toString(16);
|
35 |
| - // we have the parse the colors to a special RGB value as |
36 |
| - // the launchpad does not go from 0-255 but from 0-63 for each color |
| 44 | + |
| 45 | + // The Launchpad accepts an RGB-triple between 0 and 1. This converts the |
| 46 | + // hex code to the appropriate number array. |
37 | 47 | const color = colorFromHex(randHex);
|
38 | 48 |
|
39 |
| - console.log('Button pressed: ' + button); |
| 49 | + console.log(`Button pressed ${button.nr} (x: ${button.xy[0]}, y: ${button.xy[1]}`); |
40 | 50 |
|
41 | 51 | lp.setButtonColor(button, color);
|
42 | 52 | });
|
43 | 53 |
|
44 |
| - lp.on('buttonUp', (button, value) => { |
| 54 | + lp.on('buttonUp', (button) => { |
45 | 55 | lp.setButtonColor(button, defaultColors.off);
|
46 | 56 | });
|
47 | 57 | });
|
48 | 58 | ```
|
49 | 59 |
|
50 |
| -## TODO: |
| 60 | +## API |
| 61 | + |
| 62 | +A number of methods are available to control the button colors on |
| 63 | +the LaunchPad. In all of these methods, the button to control can be |
| 64 | +specified in one of the following ways: |
| 65 | + |
| 66 | +- `number`, indicating a Launchpad-specific button number |
| 67 | +- `[x, y]`, a Launchpad-independent button coordinate with (0, 0) in |
| 68 | + the top-left. |
| 69 | +- `Button`, a Button object (as returned by the `buttonDown` or `buttonUp` |
| 70 | + event handlers). |
| 71 | + |
| 72 | +The follow methods control a button's color: |
| 73 | + |
| 74 | +- `lp.setButtonColor(button, colorOrRGB)`: set a button to a solid color. |
| 75 | + `colorOrRGB` is either: |
| 76 | + - `number` between 0..127, a color in the 128-color palette of the Launchpad. |
| 77 | + - `[r, g, b]`, an array of RGB values between 0 and 1. |
| 78 | +- `lp.flash(button, color, colorB?)`: flash a button between two palette |
| 79 | + colors. For colors that don't support a second color, the button will flash |
| 80 | + to black. |
| 81 | +- `lp.pulse(button, color)`: a button will pulse between black and the given |
| 82 | + palette color. |
| 83 | + |
| 84 | +## TODO |
| 85 | + |
51 | 86 | - Add support for the same launchpads as launchpad.py
|
52 | 87 |
|
53 | 88 | ### Links
|
54 |
| -Launchpad developer manual: https://resource.novationmusic.com/support/product-downloads?product=Launchpad |
| 89 | + |
| 90 | +- [Launchpad developer manual](https://resource.novationmusic.com/support/product-downloads?product=Launchpad) |
55 | 91 |
|
56 | 92 | ### Notice
|
| 93 | + |
57 | 94 | This project contains modified code from https://github.com/Lokua/launchpad which was released under the MIT license
|
58 | 95 |
|
59 | 96 | [rewards-interaction]: https://github.com/duncte123/rewards-interaction
|
0 commit comments