Ward Does the PWR_BUT also call cleanup() in render.cpp?
Whether your running program calls it depends on how the program is stopped. When tapping on the Bela button, a flag (
gShouldStop) is set in the program so that the audio thread stops calling render () and exits
In turn, the main thread will call cleanup() and then exit. Any other threads should be exiting whenever
Bela_stopRequested() returns true. If these are AuxiliaryTask s, main waits on them before calling cleanup(). When the program finally exits, all global objects will be destroyed by calling their destructors before the program finally terminates.
When hold-pressing the Bela button, if you have a running program, it will be stopped as above and any new instance of the program which could attempt to start before the shutdown sequence is started and while the button is held down will fail to start (although I am not currently sure at what stage it will stop and whether it will call setup(), render() and/or cleanup ()).
If the program is stopped via
make stop, a SIGINT is sent to it. This signal is caught by the main thread, which sets gShouldStop and the program terminatea gracefully as above. Both SIGTERM and SIGINT are handled this way.
I am not sure how the shutdown procedure (which is probably called by both PWR button and Bela button) attempts to stop the running program (it probably offloads the task to systemd). As long as this sends a SIGTERM or SIGINT, cleanup() should be called and a graceful project exit takes place (there may be some timeouts after which the program is forcibly terminated).
In short: briefly tapping the Bela button or sending the program a SIGINT or SIGTERM immediately causes a graceful exit calling cleanup().