updating docs

This commit is contained in:
Yotam Mann 2019-08-27 08:47:52 -07:00
parent cc3f6c2910
commit d57dd7e07a
12 changed files with 61 additions and 55 deletions

View file

@ -19,7 +19,6 @@ interface NoiseOptions extends SourceOptions {
* Noise supports the noise types: "pink", "white", and "brown". Read more about
* colors of noise on [Wikipedia](https://en.wikipedia.org/wiki/Colors_of_noise).
*
* @param type the noise type (white|pink|brown)
* @example
* //initialize the noise and start
* var noise = new Noise("pink").start();
@ -66,6 +65,9 @@ export class Noise extends Source<NoiseOptions> {
*/
protected _fadeOut: Time;
/**
* @param type the noise type (white|pink|brown)
*/
constructor(type?: NoiseType);
// tslint:disable-next-line: unified-signatures
constructor(options?: Partial<NoiseOptions>);

View file

@ -15,6 +15,9 @@ export interface OneShotSourceOptions extends ToneAudioNodeOptions {
curve: OneShotSourceCurve;
}
/**
* Base class for fire-and-forget nodes
*/
export abstract class OneShotSource<Options extends ToneAudioNodeOptions> extends ToneAudioNode<Options> {
/**

View file

@ -17,13 +17,11 @@ export interface SourceOptions extends ToneAudioNodeOptions {
}
/**
* @class Base class for sources. Sources have start/stop methods
* and the ability to be synced to the
* start/stop of this.context.transport.
* Base class for sources. Sources have start/stop methods
* and the ability to be synced to the
* start/stop of this.context.transport.
*
* @constructor
* @extends {Tone.AudioNode}
* @example
* @example
* //Multiple state change events can be chained together,
* //but must be set in the correct order and with ascending times
*

View file

@ -23,8 +23,6 @@ interface ToneBufferSourceOptions extends OneShotSourceOptions {
/**
* Wrapper around the native BufferSourceNode.
* @param buffer The buffer to play
* @param onended The callback to invoke when the buffer is done playing.
*/
export class ToneBufferSource extends OneShotSource<ToneBufferSourceOptions> {
@ -52,6 +50,10 @@ export class ToneBufferSource extends OneShotSource<ToneBufferSourceOptions> {
private _sourceStarted: boolean = false;
private _sourceStopped: boolean = false;
/**
* @param buffer The buffer to play
* @param onended The callback to invoke when the buffer is done playing.
*/
constructor(buffer?: ToneAudioBuffer | AudioBuffer | string, onload?: () => void);
constructor(options?: Partial<ToneBufferSourceOptions>);
constructor() {

View file

@ -21,10 +21,6 @@ interface PlayerOptions extends SourceOptions {
/**
* Player is an audio file player with start, loop, and stop functions.
*
* @param url Either the AudioBuffer or the url from which to load the AudioBuffer
* @param onload The function to invoke when the buffer is loaded.
* Recommended to use Tone.Buffer.on('load') instead.
* @example
* var player = new Player("./path/to/sample.mp3").toDestination();
* //play as soon as the buffer is loaded
@ -86,8 +82,12 @@ export class Player extends Source<PlayerOptions> {
*/
fadeOut: Time;
constructor(options?: Partial<PlayerOptions>);
/**
* @param url Either the AudioBuffer or the url from which to load the AudioBuffer
* @param onload The function to invoke when the buffer is loaded.
*/
constructor(url?: string | AudioBuffer | ToneAudioBuffer, onload?: () => void);
constructor(options?: Partial<PlayerOptions>);
constructor() {
super(optionsFromArguments(Player.getDefaults(), arguments, ["url", "onload"]));

View file

@ -25,9 +25,6 @@ import { AMConstructorOptions, AMOscillatorOptions,
* +---------------+
* ```
*
* @param frequency The starting frequency of the oscillator.
* @param type The type of the carrier oscillator.
* @param modulationType The type of the modulator oscillator.
* @example
* //a sine oscillator frequency-modulated by a square wave
* var fmOsc = new AMOscillator("Ab3", "sine", "square").toDestination().start();
@ -78,8 +75,13 @@ export class AMOscillator extends Source<AMOscillatorOptions> implements ToneOsc
context: this.context,
});
constructor(options?: Partial<AMConstructorOptions>);
/**
* @param frequency The starting frequency of the oscillator.
* @param type The type of the carrier oscillator.
* @param modulationType The type of the modulator oscillator.
*/
constructor(frequency?: Frequency, type?: ToneOscillatorType, modulationType?: ToneOscillatorType);
constructor(options?: Partial<AMConstructorOptions>);
constructor() {
super(optionsFromArguments(AMOscillator.getDefaults(), arguments, ["frequency", "type", "modulationType"]));

View file

@ -23,9 +23,6 @@ import { FMConstructorOptions, FMOscillatorOptions,
* +-----------------+
* ```
*
* @param frequency The starting frequency of the oscillator.
* @param type The type of the carrier oscillator.
* @param modulationType The type of the modulator oscillator.
* @example
* //a sine oscillator frequency-modulated by a square wave
* var fmOsc = new FMOscillator("Ab3", "sine", "square").toDestination().start();
@ -79,8 +76,13 @@ export class FMOscillator extends Source<FMOscillatorOptions> implements ToneOsc
gain: 0,
});
constructor(options?: Partial<FMConstructorOptions>);
/**
* @param frequency The starting frequency of the oscillator.
* @param type The type of the carrier oscillator.
* @param modulationType The type of the modulator oscillator.
*/
constructor(frequency?: Frequency, type?: ToneOscillatorType, modulationType?: ToneOscillatorType);
constructor(options?: Partial<FMConstructorOptions>);
constructor() {
super(optionsFromArguments(FMOscillator.getDefaults(), arguments, ["frequency", "type", "modulationType"]));

View file

@ -19,13 +19,6 @@ import { PWMOscillator } from "./PWMOscillator";
*/
type AnyOscillator = Oscillator | PWMOscillator | PulseOscillator | FatOscillator | AMOscillator | FMOscillator;
/**
* The constructor of each of the OmniOscillator types
*/
type TypeofAnyOscillator = typeof Oscillator | typeof PWMOscillator |
typeof PulseOscillator | typeof FatOscillator |
typeof AMOscillator | typeof FMOscillator;
/**
* All of the Oscillator constructor types mapped to their name.
*/
@ -73,9 +66,6 @@ const OmniOscillatorSourceMap: {
* will use the FMOscillator, AMOscillator or FatOscillator respectively.
* For example: `omniOsc.type = "fatsawtooth"` will create set the oscillator
* to a FatOscillator of type "sawtooth".
*
* @param frequency The initial frequency of the oscillator.
* @param type The type of the oscillator.
* @example
* var omniOsc = new OmniOscillator("C#4", "pwm");
*/
@ -105,8 +95,12 @@ implements Omit<ToneOscillatorInterface, "type"> {
*/
private _sourceType!: OmniOscSourceType;
constructor(options?: Partial<OmniOscillatorConstructorOptions>);
/**
* @param frequency The initial frequency of the oscillator.
* @param type The type of the oscillator.
*/
constructor(frequency?: Frequency, type?: OmniOscillatorType);
constructor(options?: Partial<OmniOscillatorConstructorOptions>);
constructor() {
super(optionsFromArguments(OmniOscillator.getDefaults(), arguments, ["frequency", "type"]));

View file

@ -13,8 +13,6 @@ import { ToneOscillatorNode } from "./OscillatorNode";
* phase rotation, multiple oscillator types (see Oscillator.type),
* and Transport syncing (see Oscillator.syncFrequency).
*
* @param frequency Starting frequency
* @param type The oscillator type. Read more about type below.
* @example
* //make and start a 440hz sine tone
* var osc = new Oscillator(440, "sine").toDestination().start();
@ -60,13 +58,15 @@ export class Oscillator extends Source<ToneOscillatorOptions> implements ToneOsc
/**
* the type of the oscillator
* @type {string}
* @private
*/
private _type;
private _type: ToneOscillatorType;
constructor(options?: Partial<ToneOscillatorConstructorOptions>)
/**
* @param frequency Starting frequency
* @param type The oscillator type. Read more about type below.
*/
constructor(frequency?: Frequency, type?: ToneOscillatorType);
constructor(options?: Partial<ToneOscillatorConstructorOptions>)
constructor() {
super(optionsFromArguments(Oscillator.getDefaults(), arguments, ["frequency", "type"]));
@ -91,7 +91,7 @@ export class Oscillator extends Source<ToneOscillatorOptions> implements ToneOsc
this._type = options.type;
if (options.partialCount && options.type !== "custom") {
this._type = this.baseType + options.partialCount.toString();
this._type = this.baseType + options.partialCount.toString() as ToneOscillatorType;
}
this.phase = options.phase;
}
@ -121,7 +121,7 @@ export class Oscillator extends Source<ToneOscillatorOptions> implements ToneOsc
if (this._wave) {
this._oscillator.setPeriodicWave(this._wave);
} else {
this._oscillator.type = this._type;
this._oscillator.type = this._type as OscillatorType;
}
// connect the control signal to the oscillator frequency & detune
this._oscillator.connect(this.output);
@ -291,7 +291,7 @@ export class Oscillator extends Source<ToneOscillatorOptions> implements ToneOsc
* osc.partialCount = 2
*/
get baseType(): OscillatorType {
return this._type.replace(this.partialCount, "");
return (this._type as string).replace(this.partialCount.toString(), "") as OscillatorType;
}
set baseType(baseType: OscillatorType) {
if (this.partialCount && this._type !== "custom" && baseType !== "custom") {
@ -319,7 +319,7 @@ export class Oscillator extends Source<ToneOscillatorOptions> implements ToneOsc
let type = this._type;
const partial = /^(sine|triangle|square|sawtooth)(\d+)$/.exec(this._type);
if (partial) {
type = partial[1];
type = partial[1] as OscillatorType;
}
if (this._type !== "custom") {
if (p === 0) {

View file

@ -13,11 +13,7 @@ interface ToneOscillatorNodeOptions extends OneShotSourceOptions {
/**
* Wrapper around the native fire-and-forget OscillatorNode.
* Adds the ability to reschedule the stop method.
* ***[Tone.Oscillator](Oscillator) is better for most use-cases***
* @extends {Tone.AudioNode}
* @param {AudioBuffer|Tone.Buffer} buffer The buffer to play
* @param {Function} onload The callback to invoke when the
* buffer is done playing.
* ***[[Oscillator]] is better for most use-cases***
*/
export class ToneOscillatorNode extends OneShotSource<ToneOscillatorNodeOptions> {
@ -40,6 +36,10 @@ export class ToneOscillatorNode extends OneShotSource<ToneOscillatorNodeOptions>
readonly detune: Param<Cents>;
constructor(options?: Partial<ToneOscillatorNodeOptions>);
/**
* @param frequency The frequency value
* @param type The basic oscillator type
*/
constructor(
frequency: Frequency,
type: OscillatorType,

View file

@ -13,9 +13,6 @@ import { PulseOscillator } from "./PulseOscillator";
* at the modulationFrequency. This has the effect of continuously
* changing the timbre of the oscillator by altering the harmonics
* generated.
*
* @param {Frequency} frequency The starting frequency of the oscillator.
* @param {Frequency} modulationFrequency The modulation frequency of the width of the pulse.
* @example
* var pwm = new PWMOscillator("Ab3", 0.3).toDestination().start();
*/
@ -58,8 +55,12 @@ export class PWMOscillator extends Source<PWMOscillatorOptions> implements ToneO
*/
readonly modulationFrequency: Signal<Frequency>;
constructor(options?: Partial<PWMOscillatorOptions>);
/**
* @param {Frequency} frequency The starting frequency of the oscillator.
* @param {Frequency} modulationFrequency The modulation frequency of the width of the pulse.
*/
constructor(frequency?: Frequency, modulationFrequency?: Frequency);
constructor(options?: Partial<PWMOscillatorOptions>);
constructor() {
super(optionsFromArguments(PWMOscillator.getDefaults(), arguments, ["frequency", "modulationFrequency"]));
const options = optionsFromArguments(PWMOscillator.getDefaults(), arguments, ["frequency", "modulationFrequency"]);

View file

@ -37,8 +37,6 @@ import { PulseOscillatorOptions, ToneOscillatorInterface } from "./OscillatorInt
* | | | |
* +-----+ +-------+ +-+
* ```
* @param frequency The frequency of the oscillator
* @param width The width of the pulse
* @example
* var pulse = new PulseOscillator("E5", 0.4).toDestination().start();
*/
@ -82,8 +80,12 @@ export class PulseOscillator extends Source<PulseOscillatorOptions> implements T
mapping: val => val <= 0 ? -1 : 1,
});
constructor(options?: Partial<PulseOscillatorOptions>);
/**
* @param frequency The frequency of the oscillator
* @param width The width of the pulse
*/
constructor(frequency?: Frequency, width?: AudioRange);
constructor(options?: Partial<PulseOscillatorOptions>);
constructor() {
super(optionsFromArguments(PulseOscillator.getDefaults(), arguments, ["frequency", "width"]));