UNPKG

shimi

Version:

A JS framework for building complex MIDI applications

192 lines (191 loc) 8.4 kB
import { ClockChildFinishedEvent, IClockChild } from './Clock'; import { IMetronome } from './Metronome'; /** * @category Timing */ declare class RepeatBase<TArgs> implements IClockChild { /** Provides a way of identifying repeats so they can be easily retrieved later. */ get ref(): string; set ref(value: string); private _ref; /** Signifies whether the Repeat has stopped. */ get isFinished(): boolean; private _isFinished; /** This event fires when the Repeat finishes. */ get finished(): ClockChildFinishedEvent; private _finished; /** The action to perform for every update that the repeat is active. */ get action(): (args: TArgs) => void; private _action; /** * @param action The action to perform for every update that the repeat is active. */ constructor(action: (args: TArgs) => void); /** * This method is intended to be called by a clock to provide regular updates. It should be called by consumers of the library. * @param deltaMs How many milliseconds have passed since the last update cycle. */ update(deltaMs: number): void; /** Calling this tells the Repeat to stop whatever it's doing and that it will no longer be used. */ finish(): void; /** * Provides a way for setting the ref through a chained function call. For example: * * ``` * clock.addChild(Repeat.forMs(100, console.log('Hello!')).withRef('repeat')); * ``` * * @param ref The ref to set on the object. * @returns The calling object. */ withRef(ref: string): IClockChild; } /** * An instance of RepeatArgs is generated by a Repeat object to be passed into its action callback, providing the callback with information about how long the repeat has been running. * * @category Timing */ export declare class RepeatArgs { /** How many milliseconds the repeat has been running for. */ get ms(): number; private _ms; /** * @param ms How many milliseconds the repeat has been running for. */ constructor(ms: number); } /** * The ConditionalRepeat defines some action which should be performed on every update cycle until some condition has been met. * * @category Timing */ export declare class ConditionalRepeat extends RepeatBase<RepeatArgs> { /** Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable. */ get typeName(): string; /** The condition which must be satisfied for the repeat to automatically finish. */ get condition(): () => boolean; private _condition; private _countPassed; /** * @param condition The condition which must be satisfied for the repeat to automatically finish. * @param action The action to perform for every update that the repeat is active. */ constructor(condition: () => boolean, action: (args: RepeatArgs) => void); /** * This method is intended to be called by a clock to provide regular updates. It should be called by consumers of the library. * @param deltaMs How many milliseconds have passed since the last update cycle. */ update(deltaMs: number): void; } /** * An instance of FiniteRepeatArgs is generated by a Repeat object with finite running time, to be passed into its action callback. The FiniteRepeatArgs class provides information about how long a repeat has been running, as well as how far through repeat's lifetime we are. * * @category Timing */ export declare class FiniteRepeatArgs extends RepeatArgs { /** A number ranging from 0 to 1, signifying how far through a repeat's lifetime we are. */ get percent(): number; private _percent; /** * @param ms How many milliseconds the repeat has been running for. * @param percent A number ranging from 0 to 1, signifying how far through a repeat's lifetime we are. */ constructor(ms: number, percent: number); } /** * The MsRepeat defines some action which should be performed on every update cycle for some amount of time, measured in milliseconds. * * @category Timing */ export declare class MsRepeat extends RepeatBase<FiniteRepeatArgs> { /** Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable. */ get typeName(): string; /** How many milliseconds the repetition should run for. */ get msCount(): number; private _msCount; private _countPassed; /** * @param msCount How many milliseconds the repetition should run for. * @param action The action to perform for every update that the repeat is active. */ constructor(msCount: number, action: (args: FiniteRepeatArgs) => void); /** * This method is intended to be called by a clock to provide regular updates. It should be called by consumers of the library. * @param deltaMs How many milliseconds have passed since the last update cycle. */ update(deltaMs: number): void; } /** * An instance of BeatRepeatArgs is generated by a Repeat object with finite running time, to be passed into its action callback. The BeatRepeatArgs class provides information about how long a repeat has been running, how far through repeat's lifetime we are, and how many beats have passed since the repeat was started. * * @category Timing */ export declare class BeatRepeatArgs extends FiniteRepeatArgs { /** How many beats have passed since the repeat started. */ get beat(): number; private _beat; /** * @param ms How many milliseconds the repeat has been running for. * @param beat How many beats have passed since the repeat started. * @param percent A number ranging from 0 to 1, signifying how far through a repeat's lifetime we are. */ constructor(ms: number, beat: number, percent: number); } /** * The MsRepeat defines some action which should be performed on every update cycle for some amount of time, measured in beats. * * @category Timing */ export declare class BeatRepeat extends RepeatBase<BeatRepeatArgs> { /** Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable. */ get typeName(): string; /** The metronome used to count how many beats have passed. */ get metronome(): IMetronome; private _metronome; /** How many beats the repetition should run for. */ get beatCount(): number; private _beatCount; private _beatsPassed; private _msPassed; /** * @param metronome The metronome used to count how many beats have passed. * @param beatCount How many beats the repetition should run for. * @param action The action to perform for every update that the repeat is active. */ constructor(metronome: IMetronome, beatCount: number, action: (args: BeatRepeatArgs) => void); /** * This method is intended to be called by a clock to provide regular updates. It should be called by consumers of the library. * @param deltaMs How many milliseconds have passed since the last update cycle. */ update(deltaMs: number): void; } /** * The Repeat class contains static methods for slightly more nice and intuitive creation of repeats. * * @category Timing */ export default class Repeat { /** * Creates a new instance of ConditionalRepeat. * @param condition The condition which must be satisfied for the repeat to automatically finish. * @param action The action to perform for every update that the repeat is active. * @returns */ static until(condition: () => boolean, action: (args: RepeatArgs) => void): ConditionalRepeat; /** * Creates a new instance of MsRepeat. * @param msCount How many milliseconds the repetition should run for. * @param action The action to perform for every update that the repeat is active. * @returns */ static forMs(msCount: number, action: (args: FiniteRepeatArgs) => void): MsRepeat; /** * Creates a new instance of BeatRepeat. * @param metronome The metronome used to count how many beats have passed. * @param beatCount How many beats the repetition should run for. * @param action The action to perform for every update that the repeat is active. * @returns */ static forBeats(metronome: IMetronome, beatCount: number, action: (args: BeatRepeatArgs) => void): BeatRepeat; } export {};