I don’t know the details of :panic(). I would only assume that it sends a note-off with all note values. It’s definitely not something I would use for terminating voices.
In OSC (like with MIDI), you terminate a voice by sending a note-off, very similar to how you send a note-on. Doing this properly implies that you remember what voices that are currently playing (already triggered with note-on). This, in turn, more or less implies that you structure your code with classes. (Otherwise, things will eventually become a bit ugly/messy, using some ad-hoc layout with ‘global’ tables and whatnot.)
My advise is to ‘encapsulate’ everything chord related to a chord class. Here is a simple explanation of the properties and methods that it could contain:
chord.button – contains/returns the viewbuilder button
chord.player – contains an “OscPlayer” class that takes care of playing/terminating voices, per below:
chord.player:play()
chord.player:stop()
chord.player.is_playing – can be used to avoid bugs in case a button is clicked consecutively.
other cool methods to implement:
chord:flash_button()
chord:stop_flash_button()
If you haven’t started to make classes, this might be the time
EDIT: I noticed now that we’ve already dealt with this topic here https://forum.renoise.com/t/solved-help-code-for-play-stop-specific-note-of-a-instrument-is-po/47116 so maybe I didn’t contribute anything now. Anyhow, I just want to point out that using :panic() doesn’t look very nice to me