shimi
Version:
A JS framework for building complex MIDI applications
30 lines (29 loc) • 1.79 kB
TypeScript
import { FitPitchOptions, IPitchContainer } from './IPitchContainer';
/**
* This class is designed to allow optimized pitch fitting.
* Using the regular pitch fitting methods on scale and chord objects often results in different input pitches being mapped to the same output pitch.
* This takes a collection of pitches which are to be optimized for, as well as a pitch container to check against.
* It uses a modified version of the stable marriage algorithm to decide where pitches need to be mapped to.
*/
export default class PitchFitter {
private _map;
/**
* @param pitches The collection of pitches which we want to optimize mapping for
* @param pitchContainer The scale/chord that we want the pitches to be fitted to
* @param fitOptions Options to configure how the fitting works
*/
constructor(pitches: Array<number>, pitchContainer: IPitchContainer, fitOptions: Partial<FitPitchOptions>);
/**
* Calling this will invalidate the current fitting and recalculate.
* @param pitches The collection of pitches which we want to optimize mapping for
* @param pitchContainer The scale/chord that we want the pitches to be fitted to
* @param fitOptions Options to configure how the fitting works
*/
optimize(pitches: Array<number>, pitchContainer: IPitchContainer, fitOptions: Partial<FitPitchOptions>): void;
/**
* Returns a pitch near to the passed in pitch, but which should fit better with the notes within the container that was optimized against.
* @param pitch The pitch which we want to fit to the scale. Can also take pitch names, see the [pitch](../functions/pitch.html) method for more information.
* @returns Returns a new pitch number.
*/
fitPitch(pitch: number | string): number;
}