What is the proper way of cleaning up midi event handlers?
I’ve noticed that if I reload a script repeatedly in maiden, over time I get midi noise. The noise gets worse the more I reload. The noise resembles earlier midi messages sent from the midi controller, as though my event handler is getting ghost events from a few seconds ago. audio:restart() does not solve the issue. What does maybe seem to work is physically unplugging the controller, running midi.cleanup() at the console, and replugging in the controller.
I noticed a comment earlier in this thread:
iirc all midi tidying has been neatly inlined so it’s no longer needed in user code.
Since my issue gets worse with more reloads, it sure looks like something is not getting cleaned up for me.
I added this to my script to see if it would do anything, but it doesn’t seem to help.
function cleanup()
mid.event = nil -- I created the mid object with midi.connect()
midi.cleanup() -- found this method in the docs and figured I'd try it
end
I can use the same midi controller with other environments (e.g. supercollider hosted on my macbook) without the issue, so it seems specific to the norns environment. Matron does not show anything unusual in the console when cleaning up my script.
Possibly it’s because I’m often debugging errors in my script, and the midi handlers don’t cleaned up within some global error handler when the script hits an issue at runtime?
What’s the best strategy for me to debug further?
Also, apologies if this is the wrong place to ask, I’m new here.