Code Monkey home page Code Monkey logo

launchpad.js's Introduction

Launchpad.js

Interact with your launchpads in Node.js

Launchpad running an example script

Launchpad displaying a cross

This project started as a module for my own stream system to make several things interact with OBS studio, named rewards-interaction. 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.

Some sample programs can be found in the examples folder.

Launchpad models currently supported

  • Launchpad MK2
  • Launchpad MK3 (only tested with Mini)

Why are only these launchpads supported?

These launchpads are supported because I own them myself and have been able to test them. 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.

Examples

More examples can be found in the examples folder, this is just a simple button listener.

const { autoDetect, colors } = require('launchpad.js');
const { colorFromHex, defaultColors } = colors;

const lp = autoDetect();

// Alternatively:
//
//    await waitForReady(lp);

lp.once('ready', (deviceName) => {
  console.log(`${deviceName} is ready!!`);

  lp.on('buttonDown', (button) => {
    // Generate a random color on each button press
    const randHex = Math.floor(Math.random() * 16777215).toString(16);

    // The Launchpad accepts an RGB-triple between 0 and 1. This converts the
    // hex code to the appropriate number array.
    const color = colorFromHex(randHex);

    console.log(`Button pressed ${button.nr} (x: ${button.xy[0]}, y: ${button.xy[1]}`);

    lp.setButtonColor(button, color);
  });

  lp.on('buttonUp', (button) => {
    lp.setButtonColor(button, defaultColors.off);
  });
});

Low-level API

A number of methods are available to control the button colors on the LaunchPad. In all of these methods, the button to control can be specified in one of the following ways:

  • number, indicating a Launchpad-specific button number
  • [x, y], a Launchpad-independent button coordinate with (0, 0) in the top-left.
  • Button, a Button object (as returned by the buttonDown or buttonUp event handlers).

The follow methods control a button's color:

  • lp.setButtonColor(button, colorOrRGB): set a button to a solid color. colorOrRGB is either:
    • number between 0..127, a color in the 128-color palette of the Launchpad.
    • [r, g, b], an array of RGB values between 0 and 1.
  • lp.flash(button, color, colorB?): flash a button between two palette colors. For colors that don't support a second color, the button will flash to black.
  • lp.pulse(button, color): a button will pulse between black and the given palette color.

Surface API

There is also a buffer-oriented API you can use, which works much like how graphics cards work. The class Surface addresses the Launchpad grid as one or more layers of 9x9 buttons. You can set and get the individual button styles, and call update() to send all changes to the Launchpad.

A helper class Drawing exists to help with performing common drawing operations.

See the examples/surface.js example for more information on how to use this API.

TODO

  • Add support for the same launchpads as launchpad.py

Links

Notice

This project contains modified code from https://github.com/Lokua/launchpad which was released under the MIT license

launchpad.js's People

Contributors

bglw avatar duncte123 avatar rix0rrr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

launchpad.js's Issues

ERR_REQUIRE_ESM

Node.JS gives me this error when using the example button listener script:

const { LaunchpadMK2, colors } = require('launchpad.js');
                                 ^

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\User\Desktop\Launched\node_modules\launchpad.js\dist\index.js from C:\Users\User\Desktop\Launched\index.ts not supported.
Instead change the require of index.js in C:\Users\User\Desktop\Launched\index.ts to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (C:\Users\User\Desktop\Launched\index.ts:2:34) {
  code: 'ERR_REQUIRE_ESM'
}

What would i do?

Doesn't work with LaunchPad Mini MK3

Error:

Error: Could not find connected launchpad for name "/^Launchpad MK2/"

Actual device names:

Launchpad Mini MK3 LPMiniMK3 DAW Out
Launchpad Mini MK3 LPMiniMK3 MIDI Out
Launchpad Mini MK3 LPMiniMK3 DAW In
Launchpad Mini MK3 LPMiniMK3 MIDI In

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.