From 282274a508c4bc8f1511111305cad575630b2c4f Mon Sep 17 00:00:00 2001 From: Austin Lee Slominski Date: Sun, 25 Apr 2021 13:36:02 -0600 Subject: [PATCH] fixed issue with p5.Score that prevented 'parts' from being passed as argument (#543) This is related to an issue here: #529 It doesn't look like p5.Score is currently functional because it fails to fill the 'parts' array with the function arguments, due to a conditional that doesn't seem to be necessary. With this said, is there a way to provide a better error message to provide when p5.Score is missing phrases? Currently when p5.Score is provided no arguments, it returns Cannot read property 'start' of undefined. I imagine just checking if the function call has any arguments would be enough, but not sure if there is a case where that needs to be allowed. Also, I would be happy to work on converting this to es6 and writing out some tests, if that would be helpful for this class. --- src/looper.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/looper.js b/src/looper.js index 9110ca9c..2dfaf9e5 100644 --- a/src/looper.js +++ b/src/looper.js @@ -387,18 +387,16 @@ class Score { constructor() { // for all of the arguments this.parts = []; - this.currentPart = 0; + this.currentPart = new Array(arguments.length);; var thisScore = this; for (var i in arguments) { - if (arguments[i] && this.parts[i]) { - this.parts[i] = arguments[i]; - this.parts[i].nextPart = this.parts[i + 1]; - this.parts[i].onended = function () { - thisScore.resetPart(i); - playNextPart(thisScore); - }; - } + this.parts[i] = arguments[i]; + this.parts[i].nextPart = this.parts[i + 1]; + this.parts[i].onended = function () { + thisScore.resetPart(i); + playNextPart(thisScore); + }; } this.looping = false; }