P5.Score: Cannot read property 'start' of undefined

Hi, I’m new to this community and p5 so forgive me if I ask something silly, but here is my problem.

I have a part with a phrase and I’m now trying to add the part to a score because I want to be able to play more parts later on. When I play the part by itself it works, but playing the score with that part does not work and triggers

Uncaught TypeError: Cannot read property 'start' of undefined (sketch: line 34)

I’m not sure what I do wrong, I initiate a new score with my part “preroll”:

score = new p5.Score(preroll);

and start it with:

score.start();

My whole code can be viewed at: https://editor.p5js.org/m4rinos/sketches/HFYqbDM2b

any help would be greatly appreciated :slight_smile:

1 Like

Looking at browser’s own console (F12), the error doesn’t occur in your own code but inside the p5.sound library itself! :open_mouth:

More precisely inside p5.Score::start() method: :musical_score:

Seems like its parts[] array is completely empty! :astonished:

After perusing p5.Score’s constructor here: :face_with_monocle:

I highly doubt the expression if (arguments[i] && this.parts[i]) { could ever become true. :thinking:

B/c parts[] starts empty: this.parts = [];. :flushed:

And therefore, all its indices are still undefined; so the condition will always be false! :crazy_face:

2 Likes

Hey thanks for the investigative work!

So yes, if I understand correctly my part in score = new p5.Score(preroll); is not loaded at all. Looking at the main Score function p5.Score = function() { it does not seem to take any parameters to fill the this.parts = []; array, so we might just need to add a parameter for parts right? Something like:

p5.Score = function (parts) {
    // for all of the arguments
    this.parts = parts;
    this.currentPart = 0;
    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.looping = false;
  };

Do you know how to take this from here?

1 Like

You should open an issue on its repo: :octopus:

In the interim, you might try to replace the p5.Score’s current bugged constructor w/ a working 1. :bug:

1 Like

@m4rinos – Was this ever opened as an issue on the repo?