Note player (#806)

* Move drums into their own folder

* Load instrument samples

* Play notes

* Concurrency limit is shared across drums and instruments

* Increase MIDI note range

* Set instrument directly on musicState object

* JSDoc

* Clean up the play note functions and add comments

* Cleanup

* Check for audioEngine in playDrumNum

* JSDoc and comments

* Round the instrument number

* Fix unit test for set instrument

* Comment fixes

* Nit (condense onto single line)
This commit is contained in:
Eric Rosenbaum 2017-11-21 10:36:28 -05:00 committed by GitHub
parent 58dd57fe48
commit 5fbfecb1a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
63 changed files with 210 additions and 63 deletions

View file

@ -1,17 +1,8 @@
const test = require('tap').test;
const Music = require('../../src/extensions/scratch3_music/index.js');
let playedDrum;
let playedInstrument;
const runtime = {
audioEngine: {
numInstruments: 3,
instrumentPlayer: {
loadInstrument: instrument => (playedInstrument = instrument)
}
}
};
const runtime = Object.create(null);
const blocks = new Music(runtime);
blocks._playDrumNum = (util, drum) => (playedDrum = drum);
const util = {
stackFrame: Object.create(null),
@ -22,6 +13,10 @@ const util = {
};
test('playDrum uses 1-indexing and wrap clamps', t => {
// Stub playDrumNum
let playedDrum;
blocks._playDrumNum = (_util, drum) => (playedDrum = drum);
let args = {DRUM: 1};
blocks.playDrumForBeats(args, util);
t.strictEqual(playedDrum, 0);
@ -35,15 +30,16 @@ test('playDrum uses 1-indexing and wrap clamps', t => {
test('setInstrument uses 1-indexing and wrap clamps', t => {
// Stub getMusicState
blocks._getMusicState = () => ({});
const state = {currentInstrument: 0};
blocks._getMusicState = () => state;
let args = {INSTRUMENT: 1};
blocks.setInstrument(args, util);
t.strictEqual(playedInstrument, 0);
t.strictEqual(state.currentInstrument, 0);
args = {INSTRUMENT: runtime.audioEngine.numInstruments + 1};
args = {INSTRUMENT: blocks.INSTRUMENT_INFO.length + 1};
blocks.setInstrument(args, util);
t.strictEqual(playedInstrument, 0);
t.strictEqual(state.currentInstrument, 0);
t.end();
});