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

**URL:** https://discourse.processing.org/t/a-proposed-fix-for-the-stop-method-in-p5-sound-part/14785
**Category:** Development
**Created:** [October 18, 2019, 10:08pm UTC](https://discourse.processing.org/t/a-proposed-fix-for-the-stop-method-in-p5-sound-part/14785 "2019-10-18T22:08:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![leobrooks](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/leobrooks/32/6686_2.png) [@leobrooks](https://discourse.processing.org/u/leobrooks)
#### Post date: [October 18, 2019, 10:08pm UTC](https://discourse.processing.org/t/a-proposed-fix-for-the-stop-method-in-p5-sound-part/14785/1 "2019-10-18T22:08:16Z")

</div>

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

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [October 19, 2019, 12:58am UTC](https://discourse.processing.org/t/a-proposed-fix-for-the-stop-method-in-p5-sound-part/14785/2 "2019-10-19T00:58:36Z")

</div>

hi LEO,  
thanks for the info.

* * *

can you please post code here with the

```auto
</> 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](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](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

> **[processing/p5.js-sound](https://github.com/processing/p5.js-sound/issues?utf8=%E2%9C%93&q=is%3Aissue%2Bis%3Aopen%2Bstop)**
>
> p5.sound brings the Processing approach to Web Audio and p5.js. Demos: - processing/p5.js-sound

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

---

<div class="post-metadata">

### Author: ![leobrooks](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/leobrooks/32/6686_2.png) [@leobrooks](https://discourse.processing.org/u/leobrooks)
#### Post date: [October 23, 2019, 8:04pm UTC](https://discourse.processing.org/t/a-proposed-fix-for-the-stop-method-in-p5-sound-part/14785/3 "2019-10-23T20:04:49Z")

</div>

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:

```auto
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:

```auto
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](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

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [October 23, 2019, 8:58pm UTC](https://discourse.processing.org/t/a-proposed-fix-for-the-stop-method-in-p5-sound-part/14785/4 "2019-10-23T20:58:30Z")

</div>

> [@leobrooks](#):
>
> I don’t know how or who could actually change this in the p5.Sound library file,

> **[GitHub - processing/p5.js-sound: p5.sound brings the Processing approach to...](https://github.com/processing/p5.js-sound)**
>
> p5.sound brings the Processing approach to Web Audio and p5.js. Demos: - GitHub - processing/p5.js-sound: p5.sound brings the Processing approach to Web Audio and p5.js. Demos:
