mirror of
https://github.com/Tonejs/Tone.js
synced 2025-01-26 02:25:06 +00:00
Update Sampler.ts
This commit is contained in:
parent
08df7ad68c
commit
28eb26c930
1 changed files with 24 additions and 1 deletions
|
@ -24,6 +24,9 @@ export interface SamplerOptions extends InstrumentOptions {
|
|||
baseUrl: string;
|
||||
curve: ToneBufferSourceCurve;
|
||||
urls: SamplesMap;
|
||||
loop?: boolean;
|
||||
loopStart?: Time;
|
||||
loopEnd?: Time;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,6 +86,11 @@ export class Sampler extends Instrument<SamplerOptions> {
|
|||
*/
|
||||
curve: ToneBufferSourceCurve;
|
||||
|
||||
loop: boolean;
|
||||
|
||||
loopStart: Time;
|
||||
loopEnd: Time | undefined;
|
||||
|
||||
/**
|
||||
* @param samples An object of samples mapping either Midi Note Numbers or
|
||||
* Scientific Pitch Notation to the url of that sample.
|
||||
|
@ -126,6 +134,9 @@ export class Sampler extends Instrument<SamplerOptions> {
|
|||
this.attack = options.attack;
|
||||
this.release = options.release;
|
||||
this.curve = options.curve;
|
||||
this.loop = options.loop || false;
|
||||
this.loopStart = options.loopStart || 0;
|
||||
this.loopEnd = options.loopEnd;
|
||||
|
||||
// invoke the callback if it's already loaded
|
||||
if (this._buffers.loaded) {
|
||||
|
@ -143,6 +154,9 @@ export class Sampler extends Instrument<SamplerOptions> {
|
|||
onerror: noOp,
|
||||
release: 0.1,
|
||||
urls: {},
|
||||
loop: false,
|
||||
loopStart: 0,
|
||||
loopEnd: undefined
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -193,7 +207,16 @@ export class Sampler extends Instrument<SamplerOptions> {
|
|||
fadeOut: this.release,
|
||||
playbackRate,
|
||||
}).connect(this.output);
|
||||
source.start(time, 0, buffer.duration / playbackRate, velocity);
|
||||
|
||||
if (this.loop) {
|
||||
source.loop = true;
|
||||
source.loopStart = this.loopStart;
|
||||
if (this.loopEnd !== undefined) {
|
||||
source.loopEnd = this.loopEnd;
|
||||
}
|
||||
}
|
||||
|
||||
source.start(time, 0, this.loop ? undefined : buffer.duration / playbackRate, velocity);
|
||||
// add it to the active sources
|
||||
if (!isArray(this._activeSources.get(midi))) {
|
||||
this._activeSources.set(midi, []);
|
||||
|
|
Loading…
Reference in a new issue