Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
playNoteUp(
pitch: number, velocity: number,
output: any) { // tslint:disable-line:no-any
if (!this.sourceMap.has(pitch)) {
return;
}
const buffer = this.getBuffer(pitch, velocity);
// Fade to the note release.
const releaseSource = new Tone.BufferSource(buffer).connect(output);
releaseSource.start(
0, this.durationSeconds, undefined, 1, this.FADE_SECONDS);
this.sourceMap.get(pitch).stop(
(Tone.now() as number) + this.FADE_SECONDS, this.FADE_SECONDS);
this.sourceMap.delete(pitch);
}
//if it's a loop the default offset is the loopstart point
if (this._loop){
offset = Tone.defaultArg(offset, this._loopStart);
} else {
//otherwise the default offset is 0
offset = Tone.defaultArg(offset, 0);
}
//compute the values in seconds
offset = this.toSeconds(offset);
duration = Tone.defaultArg(duration, Math.max(this._buffer.duration - offset, 0));
duration = this.toSeconds(duration);
startTime = this.toSeconds(startTime);
// //make the source
this._source = new Tone.BufferSource({
"buffer" : this._buffer,
"loop" : this._loop,
"loopStart" : this._loopStart,
"loopEnd" : this._loopEnd,
"playbackRate" : this._playbackRate,
"fadeIn" : this.fadeIn,
"fadeOut" : this.fadeOut,
"curve": this.curve // ADDED for Storyboarder
}).connect(this.output);
//set the looping properties
if (!this._loop && !this._synced){
//if it's not looping, set the state change at the end of the sample
this._state.setStateAtTime(Tone.State.Stopped, startTime + duration);
playNote(
pitch: number, velocity: number, startTime: number, duration: number,
output: any) { // tslint:disable-line:no-any
const buffer = this.getBuffer(pitch, velocity);
if (duration > this.durationSeconds) {
logging.log(`Requested note duration longer than sample duration: ${
duration} > ${this.durationSeconds}`, 'SoundFont');
}
const source = new Tone
.BufferSource({
buffer,
fadeOut: this.FADE_SECONDS,
})
.connect(output);
source.start(startTime, 0, undefined, 1, 0);
if (!this.percussive && duration < this.durationSeconds) {
// Fade to the note release.
const releaseSource = new Tone.BufferSource(buffer).connect(output);
source.stop(startTime + duration + this.FADE_SECONDS);
releaseSource.start(
startTime + duration, this.durationSeconds, undefined, 1,
this.FADE_SECONDS);
}
}
private createSource(o?: { onended?: () => void }) {
// make the source
return new Tone.BufferSource({
buffer: this.buffer,
fadeOut: 0,
...o,
// playbackRate: this.playbackRate,
}).connect(this.output);
}
}
const play = () => {
buffer.reverse = Math.random() < 0.5;
const source = new Tone.BufferSource(buffer)
.set({
fadeIn: 3,
fadeOut: 3,
curve: 'linear',
playbackRate: 0.5,
onended: () => {
const index = disposableNodes.indexOf(source);
if (index >= 0) {
source.dispose();
disposableNodes.splice(index, 1);
}
},
})
.connect(reverb);
disposableNodes.push(source);
source.start('+1');
const drone = (
note,
droneDestination,
pitchShift = 0,
reverse = false
) => {
const closestSampledNote = findClosest(samplesByNote, note);
const difference = Distance.semitones(closestSampledNote, note);
const playbackRate = Tone.intervalToFrequencyRatio(
difference + pitchShift
);
const buffer = buffers.get(closestSampledNote);
const source = new Tone.BufferSource(buffer)
.set({
reverse,
playbackRate,
onended: () => {
const index = disposableNodes.indexOf(source);
if (index >= 0) {
source.dispose();
disposableNodes.splice(index, 1);
}
},
})
.connect(droneDestination);
source.start('+1');
};
const autoFilter = new Tone.AutoFilter(Math.random() / 10, 150, 4)
triggerAttack: (note, time = '+1') => {
const closestSample = findClosest(samplesByNote, note);
const difference = Distance.semitones(closestSample, note);
const buffer = buffers.get(closestSample);
const playbackRate = Tone.intervalToFrequencyRatio(
difference + semitoneChange
);
const source = new Tone.BufferSource(buffer)
.set({
playbackRate,
onended: () => {
const i = activeSources.indexOf(buffer);
if (i >= 0) {
activeSources.splice(i, 1);
}
},
})
.connect(destination);
source.start(time);
},
dispose: () => {
const playDigeridoo = () => {
const index = Math.floor(Math.random() * didgeridooSamples.length);
const buffer = didgeridoo.get(index);
let playbackRate = 1;
if (Math.random() < 0.1) {
playbackRate -= 0.2;
}
if (Math.random() < 0.1) {
playbackRate -= 0.2;
}
const source = new Tone.BufferSource({
buffer,
playbackRate,
}).connect(reverb);
source.onended = () => source.dispose();
source.start('+1');
Tone.Transport.scheduleOnce(() => {
playDigeridoo();
}, `+${Math.random() < 0.03 ? Math.random() * 10 + 10 : Math.random() * 5 + 5}`);
};
const drone = (
note,
droneDestination,
pitchShift = 0,
reverse = false
) => {
const closestSampledNote = findClosest(samplesByNote, note);
const difference = Distance.semitones(closestSampledNote, note);
const playbackRate = Tone.intervalToFrequencyRatio(
difference + pitchShift
);
const buffer = buffers.get(closestSampledNote);
if (!disposableNodes.includes(buffer)) {
disposableNodes.push(buffer);
}
const source = new Tone.BufferSource(buffer)
.set({
reverse,
playbackRate,
onended: () => {
const i = disposableNodes.indexOf(source);
if (i >= 0) {
source.dispose();
disposableNodes.splice(i, 1);
}
},
})
.connect(droneDestination);
source.start('+1');
};
const autoFilter = new Tone.AutoFilter(Math.random() / 10, 150, 4)
triggerAttack: (note, time) => {
const closestSample = findClosest(note);
const difference = Distance.semitones(note, closestSample);
const bufferSource = new Tone.BufferSource(
buffers.get(closestSample)
).connect(destination);
const playbackRate = Tone.intervalToFrequencyRatio(
-difference + changeInSemitones
);
bufferSource.set({
playbackRate,
onended: () => disposeNode(bufferSource),
fadeIn: 3,
fadeOut: 3,
});
disposableNodes.push(bufferSource);
bufferSource.start(time);
},
connect: node => {