Skip to content

Commit

Permalink
fixed issue with p5.Score that prevented 'parts' from being passed as…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
aceslowman authored Apr 25, 2021
1 parent 22d3ea5 commit 282274a
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/looper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 282274a

Please sign in to comment.