import EventEmitter from 'eventemitter3'; import { GridRendererEventMap } from './Types'; import { DEFAULT } from './Util'; export interface ITile { isEmpty(): boolean; getNote(i: number): number; getBitmask(): number; hasNote(i: number): boolean; addNote(i: number, noteId: number): void; removeNote(i: number): void; removeAllNotes(): void; } export interface IGrid { readonly data: readonly ITile[]; /** * The width of the grid in tiles */ readonly width: number; /** * The height of the grid in tiles */ readonly height: number; /** * Updates and draws the grid to the canvas * @param mouseX - The current x position of the mouse on the canvas element * @param mouseY - The current y position of the mouse on the canvas element */ update?(): void; /** * Update the size of the grid. * Note: If shrinking, tiles outside the space of * new grid may be lost * * @param newWidth - New width in tiles * @param newHeight - New height in tiles * @param newNoteLength - New note length. If not set, use previous value, * or recalculate the default if using the default value previously. * If using the DEFAULT symbol explicitly recalculate the default. */ setSize(newWidth?: number, newHeight?: number, newNoteLength?: number | typeof DEFAULT | null): void; /** * Get the x position on the grid where the playhead currently is * @returns The x position */ getPlayheadX(): number; /** * Gets whether a grid tile is currently lit up (armed) * @param x - The x position, measured in grid tiles * @param y - The y position, measured in grid tiles * @returns Whether the tile is lit up */ getTileValue(x: number, y: number, instrument?: number): boolean; /** * Sets whether a grid tile is currently lit up (armed) * @param x - The x position, measured in grid tiles * @param y - The y position, measured in grid tiles * @param bool - Whether the tile should be turned on (true) or off (false) */ setTileValue(x: number, y: number, bool: boolean, instrument?: number): void; /** * Turns off all tiles and removes all notes */ clearAllTiles(): void; /** * Sets whether the ToneMatrix grid is muted. * @param muted - True for muted, false for unmuted */ setMuted(muted: boolean): void; dispose?(): void; } export interface IGridRenderer extends EventEmitter { /** * Update, then draw the current state of the app to the canvas element. * @param grid - The grid to be rendered * @param mouseX - The x position of the mouse on the canvas * @param mouseY - The y position of the mouse on the canvas */ update(grid: IGrid): void; /** * Update the grid size width and height. */ setSize(newWidth: number, newHeight: number): void; /** * Converts coordinates in "pixel space" to coordinates in "tile space". * In essence, if you pass in an (x, y) position on the canvas, * this returns the corresponding (x, y) position on the grid. * @param x - The x position, in pixels, to get the corresponding grid position for * @param y - The y position, in pixels, to get the corresponding grid position for * @param gridWidth - The width of the grid, in grid tiles * @param gridHeight - The height of the grid, in grid tiles * @param canvasWidth - The width of the pixel space, * typically the width of the canvas * @param canvasHeight - The height of the pixel space, * typically the height of the canvas */ pixelCoordsToTileCoords(x: number, y: number, gridWidth: number, gridHeight: number): [x: number, y: number] | false; dispose?(): void; }