ez-web-audio
Version:
Making the Web Audio API super EZ since 2024.
119 lines • 4.43 kB
TypeScript
import { AcceptableNote, IMusicallyAware } from '../musical-identity';
import { SampledNote } from '../sampled-note';
type NotesTuple = [IMusicallyAware[], string[]];
/**
* Sort notes in piano order (by octave, then by letter with flats before naturals).
*
* @param notes - Array of notes to sort
* @returns Sorted array of notes
* @internal
*/
export declare function sortNotes<T extends IMusicallyAware>(notes: IMusicallyAware[]): T[];
/**
* 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[][];
/**
* Comparator function for sorting notes alphabetically with flats before naturals.
*
* @param a - First note to compare
* @param b - Second note to compare
* @returns -1 or 1 for sort order
* @internal
*/
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][]>;
/**
* Create SampledNote instances from decoded audio data.
*
* Takes an array of [noteName, audioBuffer] tuples and creates sorted
* SampledNote instances for use in a Font.
*
* @param ctx - AudioContext for creating nodes
* @param audioData - Array of [noteName, audioBuffer] tuples
* @returns Sorted array of SampledNote instances
* @internal
*/
export declare function createNoteObjectsForFont(ctx: AudioContext, audioData: [AcceptableNote, AudioBuffer][]): SampledNote[];
export {};
//# sourceMappingURL=note-methods.d.ts.map