From 9511cc4000e52d447f39fdc2ebd444372b6dd092 Mon Sep 17 00:00:00 2001 From: Muffin Date: Sat, 13 Jan 2024 21:58:18 -0600 Subject: [PATCH] Remove note/drum concurrency limit when misc limits are removed --- src/extensions/scratch3_music/index.js | 11 +++++++++-- test/unit/tw_extension_music.js | 27 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 test/unit/tw_extension_music.js diff --git a/src/extensions/scratch3_music/index.js b/src/extensions/scratch3_music/index.js index 982bd7a247a..7aea640d8b7 100644 --- a/src/extensions/scratch3_music/index.js +++ b/src/extensions/scratch3_music/index.js @@ -925,6 +925,13 @@ class Scratch3MusicBlocks { }; } + _isConcurrencyLimited () { + return ( + this.runtime.runtimeOptions.miscLimits && + this._concurrencyCounter > Scratch3MusicBlocks.CONCURRENCY_LIMIT + ); + } + /** * Play a drum sound for some number of beats. * @param {object} args - the block arguments. @@ -987,7 +994,7 @@ class Scratch3MusicBlocks { if (util.runtime.audioEngine === null) return; if (util.target.sprite.soundBank === null) return; // If we're playing too many sounds, do not play the drum sound. - if (this._concurrencyCounter > Scratch3MusicBlocks.CONCURRENCY_LIMIT) { + if (this._isConcurrencyLimited()) { return; } @@ -1088,7 +1095,7 @@ class Scratch3MusicBlocks { if (util.target.sprite.soundBank === null) return; // If we're playing too many sounds, do not play the note. - if (this._concurrencyCounter > Scratch3MusicBlocks.CONCURRENCY_LIMIT) { + if (this._isConcurrencyLimited()) { return; } diff --git a/test/unit/tw_extension_music.js b/test/unit/tw_extension_music.js new file mode 100644 index 00000000000..2d5e1fae8c8 --- /dev/null +++ b/test/unit/tw_extension_music.js @@ -0,0 +1,27 @@ +const test = require('tap').test; +const Music = require('../../src/extensions/scratch3_music/index.js'); +const Runtime = require('../../src/engine/runtime.js'); + +test('_isConcurrencyLimited', t => { + const rt = new Runtime(); + + // sanity check so that the setRuntimeOptions() call below actually does something + t.equal(rt.runtimeOptions.miscLimits, true, 'misc limits enabled by default'); + + const blocks = new Music(rt); + t.equal(blocks._isConcurrencyLimited(), false, 'not limited initially'); + + // logic here is slightly weird but this matches Scratch + blocks._concurrencyCounter = Music.CONCURRENCY_LIMIT; + t.equal(blocks._isConcurrencyLimited(), false, 'not limited at limit'); + + blocks._concurrencyCounter = Music.CONCURRENCY_LIMIT + 1; + t.equal(blocks._isConcurrencyLimited(), true, 'limited above limit'); + + rt.setRuntimeOptions({ + miscLimits: false + }); + t.equal(blocks._isConcurrencyLimited(), false, 'not limited when miscLimits: false'); + + t.end(); +});