Merge pull request #826 from ericrosenbaum/bugfix/check-note-buffers

Check for instrument sample before playing
This commit is contained in:
Eric Rosenbaum 2017-11-28 13:39:49 -05:00 committed by GitHub
commit 63698dad8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -602,6 +602,10 @@ class Scratch3MusicBlocks {
const sampleArray = instrumentInfo.samples;
const sampleIndex = this._selectSampleIndexForNote(note, sampleArray);
// If the audio sample has not loaded yet, bail out
if (typeof this._instrumentBufferArrays[inst] === 'undefined') return;
if (typeof this._instrumentBufferArrays[inst][sampleIndex] === 'undefined') return;
// Create the audio buffer to play the note, and set its pitch
const context = util.runtime.audioEngine.audioContext;
const bufferSource = context.createBufferSource();