Code gets stuck on the last note of the melody after being played

There is nothing wrong with supply too few initial values.

Where it goes wrong is using whatever ends up in uninitialised locations.

Would the remaining spot(s) be 0 in this case?

a7