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:

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:

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?

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:

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

My apologies, I was on a trip.I now filed an issue at Github (issue 391 issue398).
In the mean time, you can change

if (arguments[i] && this.parts[i]) {

to

if (arguments[i]) {

to locally to fix the problem. this.parts is only filled after the condition, so it never gets there.

Hiya m4rinos!
I’m currently having similar issues with p5.score :frowning:
Did you ever find the solution to ur issue?

well, yes and no, I’ve created an issue at the repository, but in the mean time, I just hack the p5.sound.js file myself with the above change and that works. I did run into more issues later on when I tried to do more complicated stuff so I ended up organising my own parts, but this should get you going if all you need is a container for your parts. Of course be aware that updating your package will overwrite your changes so you might want to either not update or self host.

Hello,

is there any new (easy to follow) solution? or maybe an official update to come?

@m4rinos, can you share your “hacked” p5sound lib file, please?

thank you!