A proposed fix for the stop() method in p5.Sound Part

Hello,

I am a relative newbie to coding but I have been working really hard on a project that uses the p5.Sound library in p5.js. The problem was that the stop() method was not working the way it said it should on the documentation. So I started analyzing the p5.Sound library and discovered a very simple, very tiny fix.

This is the way it is currently in the code:

p5.Part.prototype.stop = function (time) {
this.partStep = 0;
this.pause(time);
};

This is the fix:
p5.Part.prototype.stop = function (time) {
this.partStep = 0;
this.metro.metroTicks = 0;
this.pause(time);
};

I’ve tried it out with a few different projects on a local proxy server and it works a charm.

How does one go about making this change in the main library?

Leo

3 Likes

hi LEO,
thanks for the info.


can you please post code here with the

</> preformatted text

button from the forum editor menu
```
type or paste code here
```

( repair above 2 parts. )


also instead ( or additionally )
could you show it as a running test project as a MOD from
https://editor.p5js.org/p5/sketches/Sound:_Load_and_Play_Sound
and link here


add a link to the reference
https://p5js.org/reference/#/p5.Oscillator/stop
can help understand


if you want not only talk about it at the forum the good way would be to
check if there is a ISSUE already

if not you can open a new one describing your idea, link to forum / code …

Again, I’m really new to this and don’t know exactly what you are requesting, but I’ll try.

If you look in the p5.Sound library you will see this:

p5.Part.prototype.stop = function (time) {
this.partStep = 0;
this.pause(time);
};

If you amend it to the following, it seems to fix the issue:

p5.Part.prototype.stop = function (time) {
this.partStep = 0;
this.metro.metroTicks = 0;
this.pause(time);
};

Again, I am just resetting the partStep to 0. The issue was that if you used the stop() method before in a p5.Part instance it would reset the metroticks, essentially placing a new start/end point for your phrase, but it would not bring you back to the beginning of the phrase. This is not a fix for the oscillator feature in p5. Sound, but for Part. See reference below.

https://p5js.org/reference/#/p5.Part/stop

Even on the reference, it says that it will “Stop the part and cue it to step 0. Playback will resume from the begining of the Part when it is played again.”, but again, it won’t do this unless you include:
this.partStep = 0

I hope that makes things more clear. I don’t know how or who could actually change this in the p5.Sound library file, but it would make the program I am currently working on in the web editor much better. Thanks