UNPKG

ez-web-audio

Version:

Making the Web Audio API super EZ since 2024.

143 lines 5.24 kB
import { AcceptableNote, IMusicallyAware } from '../musical-identity'; import { SampledNote } from '../sampled-note'; type NotesTuple = [IMusicallyAware[], string[]]; /** * @public * @class utils */ /** * Sorts an array of {{#crossLink "Note"}}Notes{{/crossLink}} so that they are in the same order that they would * appear on a piano. * * @param {Array} notes An array of notes that should be musically-sorted. * * @public * @method sortNotes * * @return {Array} Array of musically-sorted notes. */ export declare function sortNotes(notes: IMusicallyAware[]): IMusicallyAware[]; /** * Takes an array of arrays of notes, determines the last note of * the first array, then splits the rest of the arrays in the array at the last * note of the first array, and moves the beginning of the array to the end * so that each array starts at the next note after the last note of the first * array, instead of at "A" (alphabetically). * * @example * This is hard to explain. Here's an example. * (Simplified, as the real notes are objects) * * Example input: [['A0', 'B0'], ['A1', 'B1', 'C1', 'D1']] * Example output: [['A0', 'B0'], ['C1', 'D1', 'A1', 'B1']] * * @private * @method octaveShift * * @param {Array} octaves An array of octaves, each octave is an array of Notes. * * @return {Array} Input array after having been shifted. */ export declare function octaveShift(octaves: IMusicallyAware[][]): IMusicallyAware[][]; /** * Maps through an array of arrays and sorts each array with * "noteSort" * * @private * @method octaveSort * * @param {Array} octaves array of arrays to be sorted * * @return {Array} array of sorted arrays */ export declare function octaveSort(octaves: IMusicallyAware[][]): IMusicallyAware[][]; /** * @method extractOctaves * * @description * Accepts an array of Note objects and passes back an array * like this: [original array, array of each octave in the orginal array] * * @param {Array} notes array of note objects. * @return {Array} array containing two inner arrays, [0] is the untouched input * array, [1] is an array of all the octaves in the original array. */ export declare function extractOctaves(notes: IMusicallyAware[]): NotesTuple; /** * @method stripDuplicateOctaves * * @description * Accepts an array of two arrays and returns the same * array, but with array at index [1] uniq'd and sorted alphabetically. * * @param input the output from extractOctaves. * @param input.0 the output from extractOctaves. * @param input.1 the output from extractOctaves. */ export declare function stripDuplicateOctaves([notes, octaves]: NotesTuple): NotesTuple; /** * @method createOctavesWithNotes * * @description * Accepts an array of two arrays, [0] being an array * of Note objects, [1] being all the available octaves. Returns a single array * made up of arrays of Note objects, organized by octave. Each inner array * represents all of the notes in an octave. * * @param data The output of stripDuplicateOctaves. * @param data.0 The output of stripDuplicateOctaves. * @param data.1 The output of stripDuplicateOctaves. */ export declare function createOctavesWithNotes([notes, octaves]: NotesTuple): IMusicallyAware[][]; /** * @method noteSort * * @description * Acts as a comparator function for the * {{#crossLink "Array/sort:method"}}Array.prototype.sort{{/crossLink}} method. * Sorts two {{#crossLink "Note"}}{{/crossLink}} instances alphabetically, flats * before naturals. * * * @param {Note} a The first Note instance to compare. * @param {Note} b The second Note instance to compare. * * @return {number} -1 or 1, depending on whether the current * {{#crossLink "Note"}}{{/crossLink}} instance should be sorted left, or right. */ export declare function noteSort(a: IMusicallyAware, b: IMusicallyAware): 1 | -1; /** * @method extractDecodedKeyValuePairs * * @description * Takes an array of base64 encoded strings (notes) and returns an array of * arrays like [[name, audio], [name, audio]] * * @param ctx AudioContext * @param notes Array of base64 encoded strings. * @return Returns an Array of tuples. Each tuple looks like * `[noteName, decodedAudio]` */ export declare function extractDecodedKeyValuePairs(ctx: AudioContext, notes: string[]): Promise<[AcceptableNote, AudioBuffer][]>; /** * @method createNoteObjectsForFont * * @description * Takes an array of arrays, each inner array acting as * a key-value pair in the form `[noteName, audioData]`. Each inner array is * transformed into a {{#crossLink "Note"}}{{/crossLink}} and the outer array * is returned. This method also sets each note on it's corresponding * instrument {{#crossLink "Map"}}{{/crossLink}} instance by name. Each note * is playable as seen in the example. * * @example * audioService.getFont('font-name').play('Ab5'); * * @param ctx AudioContext * @param audioData Array of tuples, each tuple like * `[noteName, audioData]`. * @return Returns an Array of {{#crossLink "Note"}}Notes{{/crossLink}} */ export declare function createNoteObjectsForFont(ctx: AudioContext, audioData: [AcceptableNote, AudioBuffer][]): SampledNote[]; export {}; //# sourceMappingURL=note-methods.d.ts.map