Stop button API method for library extensions

Hi all. I am trying to use the api.js interface within my library (TuneScope) to trigger an event when the stop button is clicked. Is there some method I can reference within my library files that will stop a primitive method in my library when the stop button is clicked? The issue is that one of my methods enters a loop to play Tone.js notes in a sequence, but I'm having trouble finding a way to recognize when the stop button has been pressed so that I can exit this loop/kill the async thread. Thanks!

I implemented the solution in this thread https://forum.snap.berkeley.edu/t/binding-actions-once-to-the-stop-button/1791:

const ide = get_snap_ide();
const original_stopAllScripts = ide.stopAllScripts.bind(ide);
ide.stopAllScripts = function () {
       stop_all_scripts();
       original_stopAllScripts();
};

It works, but my worry is that it is not kosher for merging into the official github.

hHIf I may suggest, you could instead create the loop inside snap, and play the notes from there. I'm guessing you're talking about the play tracks block, which I did recreate inside snap as well, so here's my script. Note: I did add a new js function.


And here's the new function that I added

SnapExtensions.primitives.set(
    'ts_playnoteIns(note, duration, instrument)',
    function (note, noteLength, instrument) {
        TuneScope.playNote(note, noteLength, instrument.toLowerCase());
    }
);

You can test it out in my snap mod, just load the tunescope library.

That link doesn't work.

https://ego-lay-atman-bay.github.io/Snap/

there was a typo in the link

It should work now