Skip to content

Commit

Permalink
sampler loop Start/End
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasplan8 committed Sep 21, 2023
1 parent 061f82f commit 729c768
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Tone/instrument/Sampler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export interface SamplerOptions extends InstrumentOptions {
curve: ToneBufferSourceCurve;
urls: SamplesMap;
loop?: boolean;
loopStart?: Time;
loopEnd?: Time;
}

/**
Expand Down Expand Up @@ -86,6 +88,9 @@ export class Sampler extends Instrument<SamplerOptions> {

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.
Expand Down Expand Up @@ -130,6 +135,8 @@ export class Sampler extends Instrument<SamplerOptions> {
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) {
Expand All @@ -148,6 +155,8 @@ export class Sampler extends Instrument<SamplerOptions> {
release: 0.1,
urls: {},
loop: false,
loopStart: 0,
loopEnd: undefined,
});
}

Expand Down Expand Up @@ -201,6 +210,10 @@ export class Sampler extends Instrument<SamplerOptions> {

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
Expand Down
2 changes: 1 addition & 1 deletion build/Tone.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/Tone.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions build/esm/instrument/Sampler.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface SamplerOptions extends InstrumentOptions {
curve: ToneBufferSourceCurve;
urls: SamplesMap;
loop?: boolean;
loopStart?: Time;
loopEnd?: Time;
}
/**
* Pass in an object which maps the note's pitch or midi value to the url,
Expand Down Expand Up @@ -65,6 +67,8 @@ export declare 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.
Expand Down
8 changes: 8 additions & 0 deletions build/esm/instrument/Sampler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/esm/instrument/Sampler.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 729c768

Please sign in to comment.