|
| 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