Skip to content

Commit

Permalink
Add dummy launchpad
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Aug 23, 2024
1 parent ee3b5ea commit 028b794
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Some sample programs can be found in the [examples folder](./examples).
- Launchpad MK2
- Launchpad MK3 (only tested with Mini)

### Dummy launchpad

This library contains a `DummyLaunchpad` class. This can be used to test calls even if you don't have a launchpad attached/


### Why are only these launchpads supported?

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SegfaultHandler from 'segfault-handler';
export * from './launchpads/MK1/LaunchpadMK1.js';
export * from './launchpads/MK2/LaunchpadMK2.js';
export * from './launchpads/MK3/LaunchpadMK3.js';
export * from './launchpads/dummy/DummyLaunchpad.js';
export * from './launchpads/base/ILaunchpad.js';
export * from './launchpads/autoDetect.js';
export * from './launchpadHelpers.js';
Expand Down
80 changes: 80 additions & 0 deletions src/launchpads/dummy/DummyLaunchpad.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { CONTROL_NOTE, NORMAL_NOTE } from '../../internal/utils.js';
import { BaseLaunchpad } from '../base/BaseLaunchpad';
import { Button, ButtonIn, ButtonStyle, isButton, PaletteColor, RgbColor } from '../base/ILaunchpad';

/**
* A dummy launchpad that has the size of a mk2
*/
export class DummyLaunchpad extends BaseLaunchpad {
allOff(): void {
this.logCall('allOff');
}

flash(button: ButtonIn, color: number, color2?: number): void {
this.logCall('flash', button, color, color2);
}

protected makeSysEx(payload: number[]): number[] {
this.logCall('makeSysEx', payload);
return [];
}

mapButtonFromXy(xy: ButtonIn): number {
if (isButton(xy)) {
return xy.nr;
}

if (typeof xy === 'number') {
return xy;
}

const [x, y] = xy;

if (y === 0) {
return x + 104;
}

// eslint-disable-next-line no-extra-parens
return 91 - (10 * y) + x;
}

parseButtonToXy(state: number, note: number): Button {
// The top row is selected
let xy: [number, number] = [-1, -1];

if (state === CONTROL_NOTE && note >= 104) {
xy = [
note - 104, // x
0, // y
];
}

if (state === NORMAL_NOTE) {
xy = [
// % 10 is because we want to have one more than the buttons in one row
// that way we get a number from 1 - 9
(note - 1) % 10, // x
Math.floor((99 - note) / 10), // y
];
}

return { nr: note, xy };

Check failure on line 61 in src/launchpads/dummy/DummyLaunchpad.ts

View workflow job for this annotation

GitHub Actions / build

Object properties must go on a new line
}

pulse(button: ButtonIn, color: number): void {
this.logCall('pulse', button, color);
}

setButtonColor(button: ButtonIn, color: RgbColor | PaletteColor): void {
this.logCall('setButtonColor', button, color);
}

setButtons(...buttons: ButtonStyle[]): void {
this.logCall('setButtons', buttons);
}


private logCall(method: string, ...args: any[]): void {

Check warning on line 77 in src/launchpads/dummy/DummyLaunchpad.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
console.log(`[Dummy Launchpad] ${method}:`, ...args);
}
}

0 comments on commit 028b794

Please sign in to comment.