1 | import { ToneAudioBuffer } from "../core/context/ToneAudioBuffer.js";
|
2 | import { Frequency, MidiNote, NormalRange, Note, Time } from "../core/type/Units.js";
|
3 | import { Instrument, InstrumentOptions } from "../instrument/Instrument.js";
|
4 | import { ToneBufferSourceCurve } from "../source/buffer/ToneBufferSource.js";
|
5 | interface SamplesMap {
|
6 | [note: string]: ToneAudioBuffer | AudioBuffer | string;
|
7 | [midi: number]: ToneAudioBuffer | AudioBuffer | string;
|
8 | }
|
9 | export interface SamplerOptions extends InstrumentOptions {
|
10 | attack: Time;
|
11 | release: Time;
|
12 | onload: () => void;
|
13 | onerror: (error: Error) => void;
|
14 | baseUrl: string;
|
15 | curve: ToneBufferSourceCurve;
|
16 | urls: SamplesMap;
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export declare class Sampler extends Instrument<SamplerOptions> {
|
40 | readonly name: string;
|
41 | |
42 |
|
43 |
|
44 | private _buffers;
|
45 | |
46 |
|
47 |
|
48 | private _activeSources;
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 | attack: Time;
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 | release: Time;
|
61 | |
62 |
|
63 |
|
64 |
|
65 | curve: ToneBufferSourceCurve;
|
66 | |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | constructor(samples?: SamplesMap, onload?: () => void, baseUrl?: string);
|
73 | /**
|
74 | * @param samples An object of samples mapping either Midi Note Numbers or
|
75 | * Scientific Pitch Notation to the url of that sample.
|
76 | * @param options The remaining options associated with the sampler
|
77 | */
|
78 | constructor(samples?: SamplesMap, options?: Partial<Omit<SamplerOptions, "urls">>);
|
79 | constructor(options?: Partial<SamplerOptions>);
|
80 | static getDefaults(): SamplerOptions;
|
81 | /**
|
82 | * Returns the difference in steps between the given midi note at the closets sample.
|
83 | */
|
84 | private _findClosest;
|
85 | /**
|
86 | * @param notes The note to play, or an array of notes.
|
87 | * @param time When to play the note
|
88 | * @param velocity The velocity to play the sample back.
|
89 | */
|
90 | triggerAttack(notes: Frequency | Frequency[], time?: Time, velocity?: NormalRange): this;
|
91 | /**
|
92 | * @param notes The note to release, or an array of notes.
|
93 | * @param time When to release the note.
|
94 | */
|
95 | triggerRelease(notes: Frequency | Frequency[], time?: Time): this;
|
96 | /**
|
97 | * Release all currently active notes.
|
98 | * @param time When to release the notes.
|
99 | */
|
100 | releaseAll(time?: Time): this;
|
101 | sync(): this;
|
102 | /**
|
103 | * Invoke the attack phase, then after the duration, invoke the release.
|
104 | * @param notes The note to play and release, or an array of notes.
|
105 | * @param duration The time the note should be held
|
106 | * @param time When to start the attack
|
107 | * @param velocity The velocity of the attack
|
108 | */
|
109 | triggerAttackRelease(notes: Frequency[] | Frequency, duration: Time | Time[], time?: Time, velocity?: NormalRange): this;
|
110 | /**
|
111 | * Add a note to the sampler.
|
112 | * @param note The buffer's pitch.
|
113 | * @param url Either the url of the buffer, or a buffer which will be added with the given name.
|
114 | * @param callback The callback to invoke when the url is loaded.
|
115 | */
|
116 | add(note: Note | MidiNote, url: string | ToneAudioBuffer | AudioBuffer, callback?: () => void): this;
|
117 | /**
|
118 | * If the buffers are loaded or not
|
119 | */
|
120 | get loaded(): boolean;
|
121 | /**
|
122 | * Clean up
|
123 | */
|
124 | dispose(): this;
|
125 | }
|
126 | export {};
|