Skip to content

Commit

Permalink
Remove note/drum concurrency limit when misc limits are removed
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Jan 14, 2024
1 parent c857903 commit 9511cc4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/extensions/scratch3_music/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
27 changes: 27 additions & 0 deletions test/unit/tw_extension_music.js
Original file line number Diff line number Diff line change
@@ -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();
});

0 comments on commit 9511cc4

Please sign in to comment.