From 066e46f4c3addc43e6971dd276fa367a8914b22a Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Tue, 30 Apr 2024 09:44:57 -0400 Subject: [PATCH] Small doc updates and tweaks (#1239) --- Tone/core/context/ToneWithContext.ts | 59 +++++++++++++++++++++------- Tone/event/Part.ts | 4 +- Tone/event/Sequence.ts | 4 +- Tone/index.ts | 22 ++++++----- Tone/signal/SyncedSignal.ts | 1 + Tone/signal/WaveShaper.ts | 2 +- 6 files changed, 64 insertions(+), 28 deletions(-) diff --git a/Tone/core/context/ToneWithContext.ts b/Tone/core/context/ToneWithContext.ts index 6b513d963..84dfeb1e0 100644 --- a/Tone/core/context/ToneWithContext.ts +++ b/Tone/core/context/ToneWithContext.ts @@ -5,10 +5,21 @@ import { TimeClass } from "../type/Time"; import { TransportTimeClass } from "../type/TransportTime"; import { Frequency, Hertz, Seconds, Ticks, Time } from "../type/Units"; import { assertUsedScheduleTime } from "../util/Debug"; -import { getDefaultsFromInstance, optionsFromArguments } from "../util/Defaults"; +import { + getDefaultsFromInstance, + optionsFromArguments, +} from "../util/Defaults"; import { RecursivePartial } from "../util/Interface"; -import { isArray, isBoolean, isDefined, isNumber, isString, isUndef } from "../util/TypeCheck"; +import { + isArray, + isBoolean, + isDefined, + isNumber, + isString, + isUndef, +} from "../util/TypeCheck"; import { BaseContext } from "./BaseContext"; +import type { TransportClass } from "../clock/Transport"; /** * A unit which process audio @@ -20,8 +31,9 @@ export interface ToneWithContextOptions { /** * The Base class for all nodes that have an AudioContext. */ -export abstract class ToneWithContext extends Tone { - +export abstract class ToneWithContext< + Options extends ToneWithContextOptions +> extends Tone { /** * The context belonging to the node. */ @@ -37,11 +49,15 @@ export abstract class ToneWithContext ex /** * Pass in a constructor as the first argument */ - constructor(context?: BaseContext) + constructor(context?: BaseContext); constructor(options?: Partial); constructor() { super(); - const options = optionsFromArguments(ToneWithContext.getDefaults(), arguments, ["context"]); + const options = optionsFromArguments( + ToneWithContext.getDefaults(), + arguments, + ["context"] + ); if (this.defaultContext) { this.context = this.defaultContext; } else { @@ -94,7 +110,7 @@ export abstract class ToneWithContext ex } /** - * Convert the incoming time to seconds. + * Convert the incoming time to seconds. * This is calculated against the current {@link TransportClass} bpm * @example * const gain = new Tone.Gain(); @@ -137,7 +153,7 @@ export abstract class ToneWithContext ex protected _getPartialProperties(props: Options): Partial { const options = this.get(); // remove attributes from the prop that are not in the partial - Object.keys(options).forEach(name => { + Object.keys(options).forEach((name) => { if (isUndef(props[name])) { delete options[name]; } @@ -153,15 +169,26 @@ export abstract class ToneWithContext ex */ get(): Options { const defaults = getDefaultsFromInstance(this) as Options; - Object.keys(defaults).forEach(attribute => { + Object.keys(defaults).forEach((attribute) => { if (Reflect.has(this, attribute)) { const member = this[attribute]; - if (isDefined(member) && isDefined(member.value) && isDefined(member.setValueAtTime)) { + if ( + isDefined(member) && + isDefined(member.value) && + isDefined(member.setValueAtTime) + ) { defaults[attribute] = member.value; } else if (member instanceof ToneWithContext) { - defaults[attribute] = member._getPartialProperties(defaults[attribute]); + defaults[attribute] = member._getPartialProperties( + defaults[attribute] + ); // otherwise make sure it's a serializable type - } else if (isArray(member) || isNumber(member) || isString(member) || isBoolean(member)) { + } else if ( + isArray(member) || + isNumber(member) || + isString(member) || + isBoolean(member) + ) { defaults[attribute] = member; } else { // remove all undefined and unserializable attributes @@ -186,9 +213,13 @@ export abstract class ToneWithContext ex * player.autostart = true; */ set(props: RecursivePartial): this { - Object.keys(props).forEach(attribute => { + Object.keys(props).forEach((attribute) => { if (Reflect.has(this, attribute) && isDefined(this[attribute])) { - if (this[attribute] && isDefined(this[attribute].value) && isDefined(this[attribute].setValueAtTime)) { + if ( + this[attribute] && + isDefined(this[attribute].value) && + isDefined(this[attribute].setValueAtTime) + ) { // small optimization if (this[attribute].value !== props[attribute]) { this[attribute].value = props[attribute]; diff --git a/Tone/event/Part.ts b/Tone/event/Part.ts index 0033fe0eb..693a31c99 100644 --- a/Tone/event/Part.ts +++ b/Tone/event/Part.ts @@ -60,7 +60,7 @@ export class Part extends ToneEvent { /** * @param callback The callback to invoke on each event - * @param events the array of events + * @param value the array of events */ constructor(callback?: ToneEventCallback>, value?: ValueType[]); constructor(options?: Partial>); @@ -209,7 +209,7 @@ export class Part extends ToneEvent { * Add a an event to the part. * @param time The time the note should start. If an object is passed in, it should * have a 'time' attribute and the rest of the object will be used as the 'value'. - * @param value + * @param value Any value to add to the timeline * @example * const part = new Tone.Part(); * part.add("1m", "C#+11"); diff --git a/Tone/event/Sequence.ts b/Tone/event/Sequence.ts index 011244a93..1c6ded004 100644 --- a/Tone/event/Sequence.ts +++ b/Tone/event/Sequence.ts @@ -5,7 +5,7 @@ import { isArray, isString } from "../core/util/TypeCheck"; import { Part } from "./Part"; import { ToneEvent, ToneEventCallback, ToneEventOptions } from "./ToneEvent"; -type SequenceEventDescription = Array>>>>; +type SequenceEventDescription = Array>; interface SequenceOptions extends Omit, "value"> { loopStart: number; @@ -59,7 +59,7 @@ export class Sequence extends ToneEvent { /** * @param callback The callback to invoke with every note - * @param sequence The sequence + * @param events The sequence of events * @param subdivision The subdivision between which events are placed. */ constructor( diff --git a/Tone/index.ts b/Tone/index.ts index 319adf57d..d95430ded 100644 --- a/Tone/index.ts +++ b/Tone/index.ts @@ -7,9 +7,13 @@ import { ToneAudioBuffer } from "./core/context/ToneAudioBuffer"; export { start } from "./core/Global"; import { Seconds } from "./core/type/Units"; export { supported } from "./core/context/AudioContext"; +import type { TransportClass } from "./core/clock/Transport"; +import type { DestinationClass } from "./core/context/Destination"; +import type { DrawClass } from "./core/util/Draw"; +import type { ListenerClass } from "./core/context/Listener"; /** - * The current audio context time of the global {@link BaseContext}. + * The current audio context time of the global {@link BaseContext}. * @see {@link Context.now} * @category Core */ @@ -39,7 +43,7 @@ export const Transport = getContext().transport; * @see {@link TransportClass} * @category Core */ -export function getTransport(): import("./core/clock/Transport").TransportClass { +export function getTransport(): TransportClass { return getContext().transport; } @@ -61,7 +65,7 @@ export const Master = getContext().destination; * @see {@link DestinationClass} * @category Core */ -export function getDestination(): import("./core/context/Destination").DestinationClass { +export function getDestination(): DestinationClass { return getContext().destination; } @@ -76,12 +80,12 @@ export const Listener = getContext().listener; * The {@link ListenerClass} belonging to the global Tone.js Context. * @category Core */ -export function getListener(): import("./core/context/Listener").ListenerClass { +export function getListener(): ListenerClass { return getContext().listener; } /** - * Draw is used to synchronize the draw frame with the Transport's callbacks. + * Draw is used to synchronize the draw frame with the Transport's callbacks. * @see {@link DrawClass} * @category Core * @deprecated Use {@link getDraw} instead @@ -89,12 +93,12 @@ export function getListener(): import("./core/context/Listener").ListenerClass { export const Draw = getContext().draw; /** - * Get the singleton attached to the global context. - * Draw is used to synchronize the draw frame with the Transport's callbacks. + * Get the singleton attached to the global context. + * Draw is used to synchronize the draw frame with the Transport's callbacks. * @see {@link DrawClass} * @category Core */ -export function getDraw(): import("./core/util/Draw").DrawClass { +export function getDraw(): DrawClass { return getContext().draw; } @@ -106,7 +110,7 @@ export function getDraw(): import("./core/util/Draw").DrawClass { export const context = getContext(); /** - * Promise which resolves when all of the loading promises are resolved. + * Promise which resolves when all of the loading promises are resolved. * Alias for static {@link ToneAudioBuffer.loaded} method. * @category Core */ diff --git a/Tone/signal/SyncedSignal.ts b/Tone/signal/SyncedSignal.ts index 362cd060d..fbdd30295 100644 --- a/Tone/signal/SyncedSignal.ts +++ b/Tone/signal/SyncedSignal.ts @@ -4,6 +4,7 @@ import { optionsFromArguments } from "../core/util/Defaults"; import { TransportTimeClass } from "../core/type/TransportTime"; import { ToneConstantSource } from "./ToneConstantSource"; import { OutputNode } from "../core/context/ToneAudioNode"; +import type { TransportClass } from "../core/clock/Transport"; /** * Adds the ability to synchronize the signal to the {@link TransportClass} diff --git a/Tone/signal/WaveShaper.ts b/Tone/signal/WaveShaper.ts index 70f2dab31..b46463d6d 100644 --- a/Tone/signal/WaveShaper.ts +++ b/Tone/signal/WaveShaper.ts @@ -55,7 +55,7 @@ export class WaveShaper extends SignalOperator { * signal is an AudioRange [-1, 1] value and the output * signal can take on any numerical values. * - * @param bufferLen The length of the WaveShaperNode buffer. + * @param length The length of the WaveShaperNode buffer. */ constructor(mapping?: WaveShaperMapping, length?: number); constructor(options?: Partial);