import EventEmitter from 'eventemitter3'; import Grid from './Grid'; import { IGrid, IGridRenderer } from './Interfaces'; import { GridRendererEventMap, ParseEventMap, ToneMatrixEventMap, ToneTransportEventMap } from './Types'; import GridCanvasRenderer from './GridCanvasRenderer'; import { DEFAULT } from './Util'; export interface ToneMatrixOptions { /** * If this property is provided it will be used as the gridPlayer * instead of making a default {@link Grid} * @default new {@link Grid}({@link ToneMatrixOptions.width width} = 16, * {@link ToneMatrixOptions.width height} = 16, * {@link ToneMatrixOptions.noteLength noteLength}) */ grid?: GridType; /** * If this property is provided it will be used as the gridRenderer * instead of making a default {@link GridCanvasRenderer} * @default new {@link GridCanvasRenderer} * ({@link ToneMatrixOptions.canvasWrapperEl canvasWrapperEl}, * {@link IGrid.width}, * {@link IGrid.height}) */ gridRenderer?: GridRendererType; /** * The DOM element to append the default gridRenderer. * Required if {@link ToneMatrixOptions.gridRenderer gridRenderer} is not provided, * ignored otherwise */ canvasWrapperEl?: HTMLElement; /** * The width of the board to pass to the default Grid constructor. * Only used if {@link ToneMatrixOptions.grid grid} is provided. * @default 16 */ width?: number; /** * The height of the board to pass to the default Grid constructor. * Only used if {@link ToneMatrixOptions.grid grid} is provided. * @default 16 */ height?: number; /** * Note length, measured in fraction of a Tone measure. * @default 1 / {@link IGrid.width} */ noteLength?: number; /** * Whether to autoplay the Grid, either at first page interaction or * asap if possible. */ autoPlay?: boolean; } export declare type ListenerEventMaps = { [key in keyof ParseEventMap | keyof GridRendererEventMap | keyof ToneTransportEventMap]: (key extends keyof ParseEventMap ? ParseEventMap[key] : never) | (key extends keyof GridRendererEventMap ? GridRendererEventMap[key] : never) | (key extends keyof ToneTransportEventMap ? ToneTransportEventMap[key] : never); }; /** * Main class of ToneMatrix Redux, a pentatonic step sequencer */ export default class ToneMatrix extends EventEmitter { /** * The width of the grid, measured in grid tiles * @readonly */ get WIDTH(): number; /** * The height of the grid, measured in grid tiles * @readonly */ get HEIGHT(): number; /** * The grid connected to the ToneMatrix * @readonly */ readonly grid: GridType extends undefined ? Grid : GridType; /** * The gridrenderer connected to the ToneMatrix * @readonly */ readonly renderer: GridRendererType extends undefined ? GridCanvasRenderer : GridRendererType; /** * @internal */ private internalListeners; private destroyed; private autoPlay; readonly playing = false; /** * Creates a new ToneMatrix Redux instance, and attach it to existing DOM elements * @param options {object} * @param options.width test */ constructor(options: ToneMatrixOptions); /** * Updates the state of the app, and draws it to the canvas. * Called in requestAnimationFrame. */ private update; /** * Start the playback */ play(): void; /** * Pause the playback */ pause(): void; /** * Pause the playback */ stop(): void; /** * Clears all notes from the grid and resets the sharing URL. */ clear(): void; /** * Sets whether the ToneMatrix application is muted. * @param muted - True for muted, false for unmuted */ setMuted(muted: boolean): void; /** * Saves the grid's current state into a savestate string * @returns The base64-encoded savestate string, * ready for saving or outputting in a URL */ toBase64(bitsPerNote: number): string; /** * Loads a savestate from a string into the grid * @param base64 - The base64-encoded savestate string */ fromBase64(base64: string, bitsPerNote: number): boolean; /** * Cleans up all resources used by this ToneMatrix */ dispose(): void; /** * Set a new grid size * @param newWidth New width in tiles * @param newHeight New height in tiles * @param noteLength New noteLength. * if {@link DEFAULT | `DEFAULT`} it will be set to {@link IGrid.width | `1 / width`} * if unset will recalculate the default value if using a calcualted default value * or keep the currently set value if explicitly set. */ setSize(newWidth?: number, newHeight?: number, noteLength?: number | typeof DEFAULT): void; setWidth(newWidth: number, noteLength?: number | typeof DEFAULT): void; setHeight(newHeight: number, noteLength?: number | typeof DEFAULT): void; /** * Add an event listener to a listenable object and save everything needed * for removing it later. * @internal */ private listen; /** * Remove a listener from a listenable object. * @internal */ private unlisten; }