Skip to content

About

Web MIDI library for the Novation Launchkey Mk2, with a browser-based MIDI tester.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

liblaunchkey

A zero-dependency Web MIDI library for the Novation Launchkey Mk2 (49-key). It exposes the keys, 16 velocity pads, 8 pots, 9 sliders, buttons, wheels, and the RGB pad LEDs.

Launchkey Mk2 49 control map

# Area Message
1 Keys notes 36–84, ch 1
2 Pitch / Mod pitch bend, CC 1
3 Octave / Transpose no MIDI
4 Display tempo and parameter value
5 Track / MIDI channel CC 102–103
6 Sliders 1–9 CC 41–48, CC 7
7 Buttons 1–9 CC 51–59
8 Pots 1–8 CC 21–28
9 InControl notes 13–15, ch 16, Extended
10 Pads 1–16 notes 36–51, ch 10
11 Round pads / Scene CC 104–105
12 Transport CC 112–117

Values are Basic mode unless noted. Product image © Focusrite Audio Engineering Ltd. Used for identification.

Run

./probe/serve.sh      # http://localhost:8787
  • http://localhost:8787/demo/ — live demo.
  • http://localhost:8787/probe/ — raw MIDI tester.

Quick start

<script type="module">
  import { LaunchkeyMk2, COLORS } from './lib/launchkey-mk2.js';

  const lk = new LaunchkeyMk2();
  await lk.connect(); // waits up to 8 s for the device

  lk.on('pad', ({ pad, down }) => {
    lk.setPad(pad, down ? COLORS.GREEN : COLORS.OFF);
  });

  lk.on('pot', ({ pot, normalized }) => {
    console.log(`pot ${pot} = ${normalized.toFixed(2)}`);
  });
</script>

The browser will ask for MIDI device access/control. Approve this so it can connect.

Events

lk.on(name, handler) returns an unsubscribe function.

Event Payload Notes
key { note, name, velocity, down } name uses scientific pitch, for example C4.
pad { pad, row, col, note, name, velocity, down } pad is 1-16. Row 1 is the top row.
pot { pot, value, normalized } pot is 1-8.
slider { slider, value, normalized } slider is 1-9. Slider 9 is Master.
button { button, value, down } Buttons 1-9 under the sliders.
transport { button, value, down } play, stop, record, loop, rewind, fastForward.
nav { button, value, down } trackLeft, trackRight.
round { which, value, down } upper or lower.
wheel { wheel, value, normalized, raw? } pitch (-8192..8191) or mod (0..127).
section { section, on } Extended mode only.
mode { extended } Device mode echo.
ledStatus { pads, pots, sliders, muteSolo } Reply to requestStatus().
connect { names } Device found.
disconnect { names } Device lost.
statechange { connected, names } Any connection change.
raw { data, hex, event } Every message. event is decoded or null.

value is the raw 7-bit number (0-127). normalized is the same value in 0-1. Pitch uses -1 to 1.

LEDs

The 16 pads have RGB LEDs where the color byte is a palette index.

lk.setPad(1, COLORS.RED);
lk.setPadFlash(2, COLORS.BLUE);   // flashes between current and blue
lk.setPadPulse(3, COLORS.GREEN);  // fades in and out
lk.setAllPads(COLORS.OFF);
lk.setPadRow(1, COLORS.WHITE);
lk.setPads([COLORS.RED, COLORS.OFF, /* ...16 values... */]);

lk.setRound('upper', COLORS.RED);
lk.setMuteSolo(true);
lk.resetPads();

Palette values: OFF 0, WHITE 3, RED 5, BLUE 45, GREEN 64. Any 0-127 value works. The vendor guide has the full palette.

Flash and pulse use MIDI clock. Call lk.sendClock() 24 times per beat for sync. Without clock, the device uses 120 BPM.

LED writes go to every matched output. On Linux, both ports share one name, so the library broadcasts each LED message.

Example: pad grid

const grid = document.querySelector('#grid');
const cells = Array.from({ length: 16 }, (_, i) => {
  const b = document.createElement('button');
  b.textContent = i + 1;
  b.onclick = () => lk.setPad(i + 1, COLORS.BLUE);
  grid.append(b);
  return b;
});

lk.on('pad', ({ pad, velocity, down }) => {
  const cell = cells[pad - 1];
  cell.style.opacity = down ? 1 : 0.4;
  cell.dataset.velocity = velocity;
});

Modes and InControl sections

The device has two independent layers.

Layer Values Source
Device mode Basic, Extended Host, or device panel
Section state Basic (off), InControl (on) 3 InControl arrows, or host

Device mode

  • Basic mode is the power-on state. It sends the simple control map.
  • Extended mode enables the InControl feature. The 3 arrows become active. Enter it with setMode('extended') or 0x9F 0x0C 0x7F.

Section state

The 3 stacked arrows sit between the sliders and the knobs.

Arrow Note Section
Top 13 pots
Middle 14 sliders
Bottom 15 pads

The arrows send section state on channel 16 to the InControl port.

A section is never silent. Its state picks the protocol:

State Pots Sliders Pads
Basic (off) CC 21-28 CC 41-48, CC 7 notes 36-51, ch 10
InControl (on) DAW map DAW map DAW map

The library decodes Basic pots and sliders, and both Basic and Extended pads, round pads, transport, nav, and sections. It does not decode the DAW CC map for pots and sliders. A section in InControl stops the simple map. Send it back with setSection(section, false).

Use the modes

lk.on('mode', ({ extended }) => {});
lk.on('section', ({ section, on }) => {});
lk.setMode('extended');
lk.setSection('pots', false);

Guidance:

  • Keep Basic mode for a normal web app.
  • Use Extended mode only when you want the 3 arrows as UI.
  • Keep all three sections off. Then the controls keep the simple map.

Hold ○

The label means hold the top InControl arrow. Do not hold Loop or Record. While you hold it:

  • a pad picks the knob bank.
  • a transport button picks the velocity curve.
  • Track steps devices.
  • a long press enters Pot Selection mode.

API

Connection

Member Use
LaunchkeyMk2.supported True when the browser has Web MIDI.
new LaunchkeyMk2({ match }) Optional port name regex.
connect({ timeout }) Request MIDI and wait for the device.
disconnect() Release the ports.
connected Current state.
deviceNames Matched port names.
on(name, fn) Subscribe. Returns an unsubscribe function.
off(name, fn) Unsubscribe.

LEDs

Method Use
setPad(pad, color) Steady color.
setAllPads(color) All 16 pads.
setPadRow(row, color) Top or bottom row.
setPads(colors) 16 values. null leaves a pad alone.
setPadFlash(pad, color) Flash.
setPadPulse(pad, color) Pulse.
setRound(which, color) Round pad.
setMuteSolo(on) Mute/solo LED.
resetPads() All LEDs off.
sendClock() One MIDI clock tick.

Modes

Method Use
setMode('basic'|'extended') Device mode.
setSection(section, on) Put a section in or out of InControl.
requestStatus() Ask for the section LED state.

Helpers

Export Use
COLORS Verified palette values.
PAD_NOTES Pad 1-16 to note number.
SECTION_NOTES Section to note number.
noteName(note) Note number to name, for example C4.
padPosition(pad) Pad to { row, col }.
decodeMessage(data) Raw bytes to an event or null.
encodePad(pad, opts) Pad LED bytes.
encodeRound(which, opts) Round LED bytes.

Notes and limits

  • Octave and transpose buttons send no MIDI. They shift the keyboard only.
  • The pads send pressure as note velocity. There is no poly aftertouch.
  • A section in InControl reports a DAW map. The library does not decode it.
  • Chrome holds the raw MIDI devices while a tab has MIDI open. Close the tab before you use amidi.

Test

npm test

Layout

  • lib/ — the library and types.
  • demo/ — a browser demo.
  • probe/ — a raw MIDI tester.

Status

The library works in Chrome on Linux. The probe page is a MIDI tester. The demo shows the library in use.

Two controls (octave/transpose and the InControl arrows) send no MIDI in Basic mode. Octave and transpose send no MIDI in any mode.

About

Web MIDI library for the Novation Launchkey Mk2, with a browser-based MIDI tester.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages