Skip to content
Daan van Berkel edited this page Aug 13, 2018 · 14 revisions

This page describes the public API of LaunchpadJS. To see it in use, look at the example

launchpad

The launchpad namespace is used to expose all the functionality that LaunchpadJS offers.

#connect

The connect method is used to create a connection with a Launchpad. Per default it tries to connect to a Launchpad Mini. You override the default by providing an options hash as argument with a key name and value the name of the corresponding Launchpad.

connect returns a promise. If the promise resolves correctly it returns a Launchpad.

If you do not know the name of your Launchpad you can list all connected midi devices with the following code.

navigator
    .requestMIDIAccess({sysex: false})
    .then(function(midiAccess){ 
        for(var input of midiAccess.inputs.values()){
            console.log(input.name)
        };
    });

Launchpad

Object that interfaces with the physical Launchpad. You can use it to either lookup buttons or register press and release events.

#clear

Turns off all the buttons of the Launchpad.

#button

arguments
  • id the id for the button or
  • x, y the x and y coordinates for the button

Returns a Button from the Launchpad. Each button has an id that can be found from the x and y coordinates in the following fashion.

var id = 16 * y + x;

The allowed x values are [0, 1, 2, 3, 4, 5, 6, 7, 8] and the allowed y values are [0, 1, 2, 3, 4, 5, 6, 7].

#controlButton

arguments
  • id the id for the button

Returns a control button, i.e. a button in the top row. The allowed values for id are [0, 1, 2, 3, 4, 5, 6, 7].

#on

arguments
  • 'press', callback register a callbacks for when a button is pressed or
  • 'release', callback register a callback for when a button is released.

The callbacks are functions that accept one Button argument.

Button

An object to interact with a physical button.

turn

arguments
  • 'color' the color the button should turn in to.

The allowed colors are 'off', 'red', 'green', 'orange'. To change or add color names, alter launchpad.defaults.paintNames.

paint

arguments
  • hash a hash of paint values

The hash arguments should have the keys red and green and values in the range [0, 1, 2, 3].

isControl

Return true if the button is a control button, false otherwise.