This repository has been archived by the owner on Mar 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.d.ts
5709 lines (4792 loc) · 145 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Tone is the base class of all other classes.
*/
declare class Tone {
constructor(opts?: object);
/**
* Generate a buffer by rendering all of the Tone.js code
* within the callback using the OfflineAudioContext.
* The OfflineAudioContext is capable of rendering much faster than
* real time in many cases. The callback function also passes in an
* offline instance of Tone.Transport which can be used to schedule
* events along the Transport.
* NOTE OfflineAudioContext has the same restrictions as the
* AudioContext in that on certain platforms (like iOS) it must be
* invoked by an explicit user action like a click or tap.
*/
static Offline(callback: Tone.Callback, duration: Tone.Encoding.Time): Promise<Tone.Buffer>;
/**
* Connect together all of the arguments in series
*/
static connectSeries(...nodes: Array<AudioParam | Tone | AudioNode>): Tone;
/**
* Convert decibels into gain
*/
static dbToGain(db: Tone.Encoding.Decibels): number;
/**
* If the given parameter is undefined, use the fallback.
* If both given and fallback are object literals, it will
* return a deep copy which includes all of the parameters
* from both objects. If a parameter is undefined in given,
* it will return the fallback property.
*
* WARNING: if object is self referential, it will go into
* an an infinite recursive loop.
*/
static defaultArg<G extends object, F extends object>(given: G, fallback: F): G & F;
static defaultArg<G>(given: NonNullable<G>, fallback?: undefined | null): G;
static defaultArg<F>(given: undefined | null, fallback: NonNullable<F>): F;
static defaultArg<G, F>(given: G, fallback?: F): G;
static defaults(values: any[], keys: string[], constr: (...args: any[]) => any | object): object;
/**
* Equal power gain scale. Good for cross-fading.
*/
static equalPowerScale(percent: Tone.Encoding.NormalRange): number;
/**
* Have a child inherit all of Tone’s (or a parent’s) prototype
* to inherit the parent’s properties, make sure to call
* Parent.call(this) in the child’s constructor based on closure
* library’s inherit function
*/
static extend<
T extends Tone.Ctor,
P extends Tone.Ctor = Tone.Ctor<any[], Tone>
>(child: T, parent?: P): ReturnType<T> & ReturnType<P>;
/**
* Convert gain to decibels.
*/
static gainToDb(gain: number): Tone.Encoding.Decibels;
/**
* Convert an interval (in semitones) to a frequency ratio
*/
static intervalToFrequencyRation(interval: Tone.Encoding.Interval): number;
/**
* Test if the argument is an Array
*/
static isArray(arg: ReadonlyArray<any>): true;
static isArray(arg: any): false;
/**
* Test if the argument is a boolean
*/
static isBoolean(arg: boolean): true;
static isBoolean(arg: any): false;
/**
* Test if the arg is not undefined
*/
static isDefined(arg?: undefined): false;
static isDefined(arg: any): true;
/**
* Test if the arg is a function
*/
static isFunction(arg: (...args: any[]) => void): true;
static isFunction(arg: any): false;
/**
* Test if the argument is a number
*/
static isNumber(arg: number): true;
static isNumber(arg: any): false;
/**
* Test if the given argument is an object literal (i.e. {})
*/
static isObject(arg: object): true;
static isObject(arg: any): false;
/**
* Test if the argument is a string.
*/
static isString(arg: string): true;
static isString(arg: any): false;
/**
* Test if the arg is undefined
*/
static isUndef(arg?: undefined): true;
static isUndef(arg: any): false;
/**
* Test if the argument is in the form of a note in
* scientific pitch notation. e.g. “C4”
*/
static isNote(arg: any): boolean;
/**
* Returns a Promise which resolves when all of the
* buffers have loaded
*/
static loaded(): Promise<void>;
/**
* Return the current time of the AudioContext clock
*/
static now(): number;
/** The AudioContext */
static readonly context: Tone.Context;
/**
* Recieve the input from the desired channelName to the input
*/
receive(channelName: string, channelNumber?: number): this;
/**
* Send this signal to the channel name.
*/
send(channelName: string, amount: Tone.Encoding.Decibels): GainNode;
/**
* Convert a frequency representation into a number.
*/
toFrequency(freq: Tone.Encoding.Frequency): Tone.Encoding.Hertz;
/**
* Convert Time into seconds. Unlike the method which it
* overrides, this takes into account transporttime and musical notation.
* Time : 1.40 Notation: 4n or 1m or 2t Now Relative: +3n Math: 3n+16n
* or even complicated expressions ((3n*2)/6 + 1)
*/
toSeconds(time: Tone.Encoding.Time): Tone.Encoding.Seconds;
/**
* Convert a time representation into ticks.
*/
toTicks(time: Tone.Encoding.Time): Tone.Encoding.Ticks;
}
declare namespace Tone {
export type Ctor<A extends Array<any> = any[], T = object> = (...args: A) => T;
export type Callback<A extends any[] = any[]> = (...args: A) => void;
export enum State {
Started = 'started',
Stopped = 'stopped',
Paused = 'paused'
}
export type PlayState = 'started' | 'stopped' | 'paused';
export type ProcessingNode = Tone
| AudioNode
| AudioParam
| AudioNode;
export type FadeCurve = 'linear' | 'exponential';
interface TimeObject {
[key: string]: number;
}
export namespace Encoding {
export type Default = number;
export type Time = number | string | TimeObject;
export type Frequency = number | string | TimeObject;
export type TransportTime = number | string | TimeObject;
export type Ticks = number;
export type NormalRange = number;
export type AudioRange = number;
export type Decibels = number;
export type Interval = number;
export type BPM = number;
export type Positive = number;
export type Gain = number;
export type Cents = number;
export type Degrees = number;
export type MIDI = string;
export type BarsBeatsSixteenths = string;
export type Samples = number;
export type Hertz = number;
export type Note = string;
export type Milliseconds = number;
export type Seconds = number;
export type Notation = string;
}
export type Unit = 'number'
| 'time'
| 'frequency'
| 'transportTime'
| 'ticks'
| 'normalRange'
| 'audioRange'
| 'db'
| 'interval'
| 'bpm'
| 'positive'
| 'gain'
| 'cents'
| 'degrees'
| 'midi'
| 'barsBeatsSixteenths'
| 'samples'
| 'hertz'
| 'note'
| 'milliseconds'
| 'seconds'
| 'notation'
type BasicOscillatorType = 'sine' | 'square' | 'sawtooth' | 'triangle';
type AMOscillatorType = 'amsine' | 'amsquare' | 'amsawtooth' | 'amtriangle';
type FatOscillatorType = 'fatsine' | 'fatsquare' | 'fatsawtooth' | 'fattriangle';
type FMOscillatorType = 'fmsine' | 'fmsquare' | 'fmsawtooth' | 'fmtriangle';
type OscillatorType = 'pwm' | 'pulse' | BasicOscillatorType | AMOscillatorType | FatOscillatorType | FMOscillatorType;
/**
* A single master output which is connected to
* the AudioDestinationNode (aka your speakers).
* It provides useful conveniences such as the ability to
* set the volume and mute the entire application.
* It also gives you the ability to apply master effects to
* your application.
*
* Like Tone.Transport, A single Tone.Master is created on
* initialization and you do not need to explicitly construct one.
*/
interface Master extends Tone {
/**
* Mute the output
*/
mute: boolean;
/**
* The volume of the master output
*/
volume: Volume['volume'];
/**
* Add a master effects chain.
* NOTE: this will disconnect any nodes which
* were previously chained in the master effects chain.
*/
chain(...nodes: ProcessingNode[]): this;
}
const Master: Master;
//------------------
// Types Interfaces
//------------------
interface PrimitiveTypeConstructor<E, T> {
(value: E, units?: Unit): number;
new(value: E, units?: Unit): T;
}
enum TypeUnits {
Default = 'number',
Time = 'time',
Frequency = 'frequency',
TransportTime = 'transportTime',
Ticks = 'ticks',
NormalRange = 'normalRange',
AudioRange = 'audioRange',
Decibels = 'db',
Interval = 'interval',
BPM = 'bpm',
Positive = 'positive',
Gain = 'gain',
Cents = 'cents',
Degrees = 'degrees',
MIDI = 'midi',
BarsBeatsSixteenths = 'barsBeatsSixteenths',
Samples = 'samples',
Hertz = 'hertz',
Note = 'note',
Milliseconds = 'milliseconds',
Seconds = 'seconds',
Notation = 'notation',
}
/**
* Tone.Frequency is a primitive type for encoding
* Frequency values. Eventually all time values are
* evaluated to hertz using the eval method
*/
interface Frequency extends TimeBase {
/**
* Takes an array of semitone intervals and returns an
* array of frequencies transposed by those intervals
*/
harmonize(intervals: ReadonlyArray<Encoding.Interval>): ReadonlyArray<number>;
/**
* Return the value as a midi note
*/
toMidi(): Encoding.MIDI;
/**
* Return the value of frequency in Scientific Pitch
* Notation
*/
toNote(): Encoding.Note;
/**
* Return the time in ticks
*/
toTicks(): Encoding.Ticks;
/**
* Transposes the frequency by the given number of semitones
*/
transpose(interval: Encoding.Interval): Frequency;
}
interface FrequencyConstructor extends PrimitiveTypeConstructor<Encoding.Frequency, Frequency> {
ftom(frequency: Encoding.Frequency): Encoding.MIDI;
mtof(midi: Encoding.MIDI): Encoding.Frequency;
}
const Frequency: FrequencyConstructor;
/**
* Tone.Midi is a primitive type for encoding Time values.
* Tone.Midi can be constructed with or without the new
* keyword. Tone.Midi can be passed into the parameter of
* any method which takes time as an argument
*/
interface Midi extends Frequency {
/**
* Return the value in hertz
*/
toFrequency(): number;
}
interface MidiConstructor extends PrimitiveTypeConstructor<Encoding.MIDI, Midi> {
ftom(frequency: Encoding.Frequency): Encoding.MIDI;
mtof(midi: Encoding.MIDI): Encoding.Frequency;
}
const Midi: MidiConstructor;
/**
* Tone.Ticks is a primitive type for encoding Time values.
* Tone.Ticks can be constructed with or without the new
* keyword. Tone.Ticks can be passed into the parameter of
* any method which takes time as an argument
*/
interface Ticks extends TransportTime {}
interface TicksConstructor extends PrimitiveTypeConstructor<Encoding.Ticks, Ticks> {}
const Ticks: Ticks;
/**
* Tone.TimeBase is a flexible encoding of time which can
* be evaluated to and from a string
*/
interface TimeBase extends Tone {
/**
* Return the value in hertz
*/
toFrequency(): number;
/**
* Returns this time in milliseconds
*/
toMilliseconds(): number;
/**
* Return the time in samples
*/
toSamples(): number;
/**
* Return the time in seconds
*/
toSeconds(): number;
/**
* Evaluate the time value.
* Returns the time in seconds.
*/
valueOf(): number;
}
interface TimeBaseConstructor extends PrimitiveTypeConstructor<Encoding.Time, TimeBase> {}
const TimeBase: TimeBaseConstructor;
/**
* Tone.Time is a primitive type for encoding Time values.
* Tone.Time can be constructed with or without the new
* keyword. Tone.Time can be passed into the parameter of
* any method which takes time as an argument
*/
interface Time extends TimeBase {
/**
* Quantize the time by the given subdivision. Optionally
* add a percentage which will move the time value towards
* the ideal quantized value by that percentage
*/
quantize(val: number | Encoding.Time, percent?: Encoding.NormalRange): number;
/**
* Return the time encoded as Bars:Beats:Sixteenths
*/
toBarsBeatsSixteenths(): Encoding.BarsBeatsSixteenths;
/**
* Return the value as a midi note
*/
toMidi(): Encoding.MIDI;
/**
* Convert a Time to Notation. The notation values will
* be the closest representation between 1m to 128th note
*/
toNotation(): Encoding.Notation;
/**
* Return the time in ticks
*/
toTicks(): Encoding.Ticks;
}
interface TimeConstructor extends PrimitiveTypeConstructor<Encoding.Time, Time> {}
const Time: TimeConstructor;
/**
* Tone.TransportTime is a the time along the Transport’s
* timeline. It is similar to Tone.Time, but instead of
* evaluating against the AudioContext’s clock, it is
* evaluated against the Transport’s position
*/
interface TransportTime extends Time {}
interface TransportTimeConstructor extends PrimitiveTypeConstructor<Encoding.TransportTime, TransportTime> {}
const TransportTime: TransportTimeConstructor;
//----------------
// Core Classes
//----------------
/**
* Tone.AudioNode is the base class for classes which process audio.
* AudioNodes have inputs and outputs.
*/
class AudioNode extends Tone {
/**
* The number of channels used when up-mixing and
* down-mixing connections to any inputs to the node.
* The default value is 2 except for specific nodes where its
* value is specially determined.
*/
readonly channelCount: number;
/**
* Determines how channels will be counted when
* up-mixing and down-mixing connections to any inputs to the node.
* The default value is “max”. This attribute has no effect for
* nodes with no inputs.
*/
readonly channelCountMode: string;
/**
* Determines how individual channels will be
* treated when up-mixing and down-mixing connections to any inputs
* to the node. The default value is “speakers”.
*/
readonly channelInterpretation: string;
/**
* Get the audio context belonging to this instance.
*/
readonly context: Context;
/**
* The number of inputs feeding into the AudioNode.
* For source nodes, this will be 0.
*/
readonly numberOfInputs: number;
/**
* The number of outputs coming out of the AudioNode.
*/
readonly numberOfOutputs: number;
/**
* Connect the output of this node to the rest of
* the nodes in series.
*/
chain(...nodes: Array<ProcessingNode>): this
/**
* connect the output of this node to the rest of
* the nodes in parallel
*/
fan(...nodes: Array<ProcessingNode>): this
/**
* Connect the output of a ToneNode to an AudioParam,
* AudioNode, or ToneNode
*/
connect(unit: ProcessingNode, outputNum?: number, inputNum?: number): this;
/**
* Disconnect the output
*/
disconnect(output: number | ProcessingNode): this;
/**
* Dispose and disconnect
*/
dispose(): this;
/**
* Connect ‘this’ to the master output. Shorthand for
* this.connect(Tone.Master)
*/
toMaster(): this;
/**
* Create input and outputs for this object.
*/
private createInsOuts(inputs: number, outputs: number): this
}
type BufferArray = Float32Array | ReadonlyArray<Float32Array>
/**
* Buffer loading and storage. Tone.Buffer is used internally by
* all classes that make requests for audio files such as Tone.Player,
* Tone.Sampler and Tone.Convolver. Aside from load callbacks from
* individual buffers, Tone.Buffer provides events which keep track
* of the loading progress of all of the buffers.
* These are Tone.Buffer.on(“load” / “progress” / “error”)
*/
class Buffer extends Tone {
constructor(url: AudioBuffer | string, onload?: Callback, onerror?: Callback);
/**
* Stop all of the downloads in progress
*/
static cancelDownload(): Buffer;
/**
* Create a Tone.Buffer from the array. To create a
* multichannel AudioBuffer, pass in a multidimensional
* array
*/
static fromArray(array: BufferArray): Buffer;
/**
* Creates a Tone.Buffer from a URL, returns a promise
* which resolves to a Tone.Buffer
*/
static fromUrl(url: string): Promise<Buffer>;
/**
* Loads a url using XMLHttpRequest
*/
static load(url: string, onload: Callback, onerror: Callback, onprogress: Callback): XMLHttpRequest;
/**
* Checks a url’s extension to see if the current browser can
* play that file type
*/
static supportsType(url: string): boolean;
/**
* The duration of the buffer
*/
readonly duration: number;
/**
* The length of the buffer in samples
*/
readonly length: number;
/**
* If the buffer is loaded or not
*/
readonly loaded: boolean;
/**
* The number of discrete audio channels.
* Returns 0 if no buffer is loaded
*/
readonly numberOfChannels: number;
/**
* Reverse the buffer
*/
reverse: boolean;
/**
* Clean up
*/
dispose(): this;
/**
* Set the audio buffer from the array.
* To create a multichannel AudioBuffer, pass in a
* multidimensional array
*/
fromArray(array: BufferArray): this;
get(): AudioBuffer;
/**
* Returns the Float32Array representing the PCM audio
* data for the specific channel
*/
getChannelData(channel: number): Float32Array;
/**
* Makes an xhr reqest for the selected url then decodes
* the file as an audio buffer. Invokes the callback once
* the audio buffer loads
*/
load(url: string): Promise<this>;
/**
* Pass in an AudioBuffer or Tone.Buffer to set the value of
* this buffer
*/
set(buffer: AudioBuffer | Buffer): this;
/**
* Cut a subsection of the array and return a buffer of
* the subsection. Does not modify the original buffer
*/
slice(start: Encoding.Time, end?: Encoding.Time): this;
/**
* Get the buffer as an array. Single channel buffers will
* return a 1-dimensional Float32Array, and multichannel buffers
* will return multidimensional arrays
*/
toArray(channel?: number): BufferArray;
/**
* Sums muliple channels into 1 channel
*/
toMono(channel?: number): BufferArray;
}
/**
* A data structure for holding multiple buffers
*/
class Buffers extends Tone {
constructor(urls: object | string[], callback?: Callback)
/**
* A path which is prefixed before every url
*/
baseUrl: string;
/**
* If the buffers are loaded or not
*/
readonly loaded: boolean;
/**
* Add a buffer by name and url to the Buffers
*/
add(name: string, url: string | Buffer | AudioBuffer, callback?: Callback): this;
/**
* Clean up
*/
dispose(): this;
/**
* Get a buffer by name. If an array was loaded, then use
* the array index
*/
get(name: string | number): Buffer;
/**
* True if the buffers object has a buffer by that name
*/
has(name: string | number): boolean;
}
/**
* Wrapper around the native AudioContext.
*/
class Context extends Emitter {
constructor(context?: AudioContext);
/**
* What the source of the clock is, either “worker”
* (Web Worker [default]), “timeout” (setTimeout),
* or “offline” (none).
*/
clockSource: string | Encoding.Seconds;
/**
* The type of playback, which affects tradeoffs between audio
* output latency and responsiveness. In addition to setting the
* value in seconds, the latencyHint also accepts the strings
* “interactive” (prioritizes low latency),
* “playback” (prioritizes sustained playback),
* “balanced” (balances latency and performance),
* and “fastest” (lowest latency, might glitch more often).
*/
latencyHint: string | Encoding.Seconds;
/**
* The amount of time events are scheduled into the future
*/
lookAhead: number;
/**
* How often the Web Worker callback is invoked. This number
* corresponds to how responsive the scheduling can be.
* Context.updateInterval + Context.lookAhead gives you the total
* latency between scheduling an event and hearing it.
*/
updateInterval: number;
/**
* Clears a previously scheduled timeout with Tone.context.setTimeout
*/
clearTimeout(id: number): this;
/**
* Promise which is invoked when the context is running.
* Tries to resume the context if it’s not started.
*/
close(): Promise<any>;
createAnalyser(): AnalyserNode;
createBiquadFilter(): BiquadFilterNode;
createConstantSource(): ConstantSourceNode;
createPanner(): PannerNode;
createStereoPanner(): StereoPannerNode;
/**
* Unlike other dispose methods, this returns a Promise which
* executes when the context is closed and disposed
*/
dispose(): this;
dispose(): Promise<this>;
/**
* Generate a looped buffer at some constant value.
*/
getConstant(val: number): AudioBufferSourceNode;
/**
* The current audio context time
*/
now(): number;
/**
* Promise which is invoked when the context is running.
* Tries to resume the context if it’s not started.
*/
ready(): Promise<any>;
/**
* A setTimeout which is gaurenteed by the clock source.
* Also runs in the offline context.
*/
setTimeout(fn: Callback, timeout: Encoding.Seconds): number;
}
/**
* Wrapper around the OfflineAudioContext
*/
class OfflineContext extends Context {
constructor(channels: number, duration: number, sampleRate: number)
/**
* Close the context
*/
close(): Promise<undefined>;
/**
* Override the now method to point to the internal clock time
*/
now(): number;
createBufferSource(): BufferSource;
/**
* Render the output of the OfflineContext
*/
render(): Promise<AudioBuffer>;
}
/**
* Wrapper around Web Audio’s native DelayNode.
*/
class Delay extends Tone {
constructor(delayTime?: Encoding.Time, maxDelay?: Encoding.Time)
/**
* The amount of time the incoming signal is delayed.
*/
delayTime: Param<Encoding.Time>;
/**
* The maximum delay time. This cannot be changed.
* The value is passed into the constructor.
*/
readonly maxDelay: Encoding.Time;
/** Clean up */
dispose(): this;
}
/**
* A sample accurate clock which provides a callback at the
* given rate. While the callback is not sample-accurate
* (it is still susceptible to loose JS timing), the time passed
* in as the argument to the callback is precise.
* For most applications, it is better to use Tone.Transport
* instead of the Clock by itself since you can synchronize
* multiple callbacks.
*/
class Clock extends Emitter {
constructor(callback: Callback, frequency: Encoding.Frequency)
/**
* The callback function to invoke at the scheduled tick
*/
callback: Callback;
/**
* The rate the callback function should be invoked
*/
frequency: TickSignal<Encoding.BPM>;
/**
* Returns the playback state of the source, either
* “started”, “stopped” or “paused”
*/
readonly state: State;
/**
* Clean up
*/
dispose(): this;
/**
* Return the elapsed seconds at the given time
*/
getSecondsAtTime(time: Encoding.Time): Encoding.Seconds;
/**
* Returns the scheduled state at the given time
*/
getStateAtTime(time: Encoding.Time): State;
/**
* Get the clock’s ticks at the given time
*/
getTicksAtTime(time: Encoding.Time): Encoding.Ticks;
/**
* Get the time of the next tick
*/
nextTickTime(ticks: Encoding.Ticks, before: Encoding.Time): this;
/**
* Pause the clock. Pausing does not reset the tick counter
*/
pause(time?: Encoding.Time): this;
/**
* Set the clock’s ticks at the given time
*/
setTicksAtTime(ticks: Encoding.Ticks, time: Encoding.Time): this;
/**
* Start the clock at the given time. Optionally pass
* in an offset of where to start the tick counter from
*/
start(time?: Encoding.Time, offset?: Encoding.Ticks): this;
/**
* Stop the clock. Stopping the clock resets the tick counter to 0
*/
stop(time?: Encoding.Time): this;
}
/**
* Tone.Emitter gives classes which extend it the ability
* to listen for and emit events.
*/
class Emitter extends Tone {
/**
* Add Emitter functions (on/off/emit) to the object
*/
static mixin(object: object): Emitter;
/** Clean up */
dispose(): this;
/**
* Invoke all of the callbacks bound to the event with any
* arguments passed in.
*/
emit(event: string, ...args: any[]): this;
/**
* Remove the event listener.
*/
off(event: string, callback: Callback): this;
/**
* Bind a callback to a specific event.
*/
on(event: string, callback: Callback): this;
/**
* Bind a callback which is only invoked once
*/
once(event: string, callback: Callback): this;
}
interface GainOptions {
gain: Encoding.Gain;
convert: boolean;
}
/**
* A thin wrapper around the Native Web Audio GainNode. The GainNode is
* a basic building block of the Web Audio API and is useful for
* routing audio and adjusting gains.
*/
class Gain extends Tone {
constructor(gain?: Encoding.Gain, units?: Unit)
/**
* The gain parameter of the gain node.
*/
readonly gain: Param<Encoding.Gain>;
}
/**
* Transport for timing musical events. Supports tempo curves and
* time changes. Unlike browser-based timing
* (setInterval, requestAnimationFrame) Tone.Transport timing events
* pass in the exact time of the scheduled event in the argument of the
* callback function. Pass that time value to the object you’re scheduling.
* A single transport is created for you when the library is initialized.
* The transport emits the events: “start”, “stop”, “pause”, and “loop”
* which are called with the time of that event as the argument.
*/
interface Transport extends Emitter {
/**
* Pulses Per Quarter note. This is the smallest resolution the
* Transport timing supports. This should be set once on initialization
* and not set again. Changing this value after other objects have been
* created can cause problems.
*/
PPQ: number;
/**
* The Beats Per Minute of the Transport.
*/