Skip to content

Commit 028b794

Browse files
committed
Add dummy launchpad
1 parent ee3b5ea commit 028b794

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Some sample programs can be found in the [examples folder](./examples).
1919
- Launchpad MK2
2020
- Launchpad MK3 (only tested with Mini)
2121

22+
### Dummy launchpad
23+
24+
This library contains a `DummyLaunchpad` class. This can be used to test calls even if you don't have a launchpad attached/
25+
2226

2327
### Why are only these launchpads supported?
2428

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import SegfaultHandler from 'segfault-handler';
33
export * from './launchpads/MK1/LaunchpadMK1.js';
44
export * from './launchpads/MK2/LaunchpadMK2.js';
55
export * from './launchpads/MK3/LaunchpadMK3.js';
6+
export * from './launchpads/dummy/DummyLaunchpad.js';
67
export * from './launchpads/base/ILaunchpad.js';
78
export * from './launchpads/autoDetect.js';
89
export * from './launchpadHelpers.js';
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { CONTROL_NOTE, NORMAL_NOTE } from '../../internal/utils.js';
2+
import { BaseLaunchpad } from '../base/BaseLaunchpad';
3+
import { Button, ButtonIn, ButtonStyle, isButton, PaletteColor, RgbColor } from '../base/ILaunchpad';
4+
5+
/**
6+
* A dummy launchpad that has the size of a mk2
7+
*/
8+
export class DummyLaunchpad extends BaseLaunchpad {
9+
allOff(): void {
10+
this.logCall('allOff');
11+
}
12+
13+
flash(button: ButtonIn, color: number, color2?: number): void {
14+
this.logCall('flash', button, color, color2);
15+
}
16+
17+
protected makeSysEx(payload: number[]): number[] {
18+
this.logCall('makeSysEx', payload);
19+
return [];
20+
}
21+
22+
mapButtonFromXy(xy: ButtonIn): number {
23+
if (isButton(xy)) {
24+
return xy.nr;
25+
}
26+
27+
if (typeof xy === 'number') {
28+
return xy;
29+
}
30+
31+
const [x, y] = xy;
32+
33+
if (y === 0) {
34+
return x + 104;
35+
}
36+
37+
// eslint-disable-next-line no-extra-parens
38+
return 91 - (10 * y) + x;
39+
}
40+
41+
parseButtonToXy(state: number, note: number): Button {
42+
// The top row is selected
43+
let xy: [number, number] = [-1, -1];
44+
45+
if (state === CONTROL_NOTE && note >= 104) {
46+
xy = [
47+
note - 104, // x
48+
0, // y
49+
];
50+
}
51+
52+
if (state === NORMAL_NOTE) {
53+
xy = [
54+
// % 10 is because we want to have one more than the buttons in one row
55+
// that way we get a number from 1 - 9
56+
(note - 1) % 10, // x
57+
Math.floor((99 - note) / 10), // y
58+
];
59+
}
60+
61+
return { nr: note, xy };
62+
}
63+
64+
pulse(button: ButtonIn, color: number): void {
65+
this.logCall('pulse', button, color);
66+
}
67+
68+
setButtonColor(button: ButtonIn, color: RgbColor | PaletteColor): void {
69+
this.logCall('setButtonColor', button, color);
70+
}
71+
72+
setButtons(...buttons: ButtonStyle[]): void {
73+
this.logCall('setButtons', buttons);
74+
}
75+
76+
77+
private logCall(method: string, ...args: any[]): void {
78+
console.log(`[Dummy Launchpad] ${method}:`, ...args);
79+
}
80+
}

0 commit comments

Comments
 (0)