mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Play drums!
This commit is contained in:
parent
73dbc82411
commit
b64152637e
1 changed files with 10 additions and 3 deletions
|
@ -428,15 +428,22 @@ class Scratch3MusicBlocks {
|
||||||
drum = MathUtil.wrapClamp(drum, 0, this.DRUM_INFO.length - 1);
|
drum = MathUtil.wrapClamp(drum, 0, this.DRUM_INFO.length - 1);
|
||||||
let beats = Cast.toNumber(args.BEATS);
|
let beats = Cast.toNumber(args.BEATS);
|
||||||
beats = this._clampBeats(beats);
|
beats = this._clampBeats(beats);
|
||||||
if (util.target.audioPlayer !== null) {
|
this._playDrumNum(util, drum);
|
||||||
util.target.audioPlayer.playDrumForBeats(drum, beats);
|
|
||||||
}
|
|
||||||
this._startStackTimer(util, this._beatsToSec(beats));
|
this._startStackTimer(util, this._beatsToSec(beats));
|
||||||
} else {
|
} else {
|
||||||
this._checkStackTimer(util);
|
this._checkStackTimer(util);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_playDrumNum (util, drumNum) {
|
||||||
|
if (util.target.audioPlayer === null) return;
|
||||||
|
const outputNode = util.target.audioPlayer.getInputNode();
|
||||||
|
const bufferSource = this.runtime.audioEngine.audioContext.createBufferSource();
|
||||||
|
bufferSource.buffer = this._drumBuffers[drumNum];
|
||||||
|
bufferSource.connect(outputNode);
|
||||||
|
bufferSource.start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rest for some number of beats.
|
* Rest for some number of beats.
|
||||||
* @param {object} args - the block arguments.
|
* @param {object} args - the block arguments.
|
||||||
|
|
Loading…
Reference in a new issue