Piano: Quit the audio thread by checking Core::EventLoop for exit

The infinite loop here doesn't really work at all for an application
process that expects to be able to exit. Check against
Core::EventLoop::current() to see if it's time to
exit, and return 0 from the thread function if so.

The thread will be joined in its destructor, which doesn't assert
anymore now that Thread is a jthread.
This commit is contained in:
Andrew Kaster 2020-12-31 02:14:12 -07:00 committed by Andreas Kling
parent 06865c78c7
commit 084c296362

View file

@ -82,7 +82,7 @@ int main(int argc, char** argv)
}
Array<Sample, sample_count> buffer;
for (;;) {
while (!Core::EventLoop::current().was_exit_requested()) {
track_manager.fill_buffer(buffer);
audio->write(reinterpret_cast<u8*>(buffer.data()), buffer_size);
Core::EventLoop::current().post_event(main_widget, make<Core::CustomEvent>(0));
@ -101,6 +101,7 @@ int main(int argc, char** argv)
wav_writer.finalize();
}
}
return 0;
});
audio_thread->start();