mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
5fbfecb1a9
* 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)
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
const test = require('tap').test;
|
|
const Music = require('../../src/extensions/scratch3_music/index.js');
|
|
const runtime = Object.create(null);
|
|
|
|
const blocks = new Music(runtime);
|
|
|
|
const util = {
|
|
stackFrame: Object.create(null),
|
|
target: {
|
|
audioPlayer: null
|
|
},
|
|
yield: () => null
|
|
};
|
|
|
|
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);
|
|
|
|
args = {DRUM: blocks.DRUM_INFO.length + 1};
|
|
blocks.playDrumForBeats(args, util);
|
|
t.strictEqual(playedDrum, 0);
|
|
|
|
t.end();
|
|
});
|
|
|
|
test('setInstrument uses 1-indexing and wrap clamps', t => {
|
|
// Stub getMusicState
|
|
const state = {currentInstrument: 0};
|
|
blocks._getMusicState = () => state;
|
|
|
|
let args = {INSTRUMENT: 1};
|
|
blocks.setInstrument(args, util);
|
|
t.strictEqual(state.currentInstrument, 0);
|
|
|
|
args = {INSTRUMENT: blocks.INSTRUMENT_INFO.length + 1};
|
|
blocks.setInstrument(args, util);
|
|
t.strictEqual(state.currentInstrument, 0);
|
|
|
|
t.end();
|
|
});
|