-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} | ||
|
||
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 { | ||
console.log(`[Dummy Launchpad] ${method}:`, ...args); | ||
} | ||
} |