diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -19,6 +19,7 @@ #include <sys/types.h> #include <sys/time.h> #include <time.h> +#include <signal.h> #include <boost/signals2.hpp> @@ -30,8 +31,18 @@ double diff_timespec(const struct timespec *time1, const struct timespec *time0) + (time1->tv_nsec - time0->tv_nsec) / 1000000000.0; } +bool run_flag = true; + +void signal_handler(int) { + run_flag = false; + std::cout << "Signal received. Terminating." << std::endl; +} + int main(void) { + signal(SIGTERM, signal_handler); + signal(SIGINT, signal_handler); + try { //debug_cout.activate(); log_cout.activate(); @@ -55,21 +66,25 @@ int main(void) Timer timer_500ms(500ms, true); timer_500ms.start(); + Timer timer_10min(10min, true); + timer_10min.start(); + // Main signals boost::signals2::signal<void()> signal_count_loops; // // Signal-Slot Connections: // - midi.signal_note.connect([&](int channel, int note){note_click->receive_note(channel, note);}); + midi.signal_note.connect([&](int channel, int note, uint64_t timestamp){note_click->receive_note(channel, note, timestamp);}); note_click->signal_click.connect([&](){pcm.click();}); midi.signal_active_sensing.connect([&](){ui.slot_active_sensing();}); timer_500ms.elapsed.connect([&](){ui.draw();}); signal_count_loops.connect([&](){ui.count_main_loops();}); + timer_10min.elapsed.connect([&](){config.persist();}); midi.flush(); - while (true) { + while (run_flag) { debug_cout << "Main loop entered." << std::endl; signal_count_loops(); @@ -110,6 +125,7 @@ int main(void) // handle timers, TODO: make updates more efficient at scale timer_500ms.update(); + timer_10min.update(); } } catch (const std::exception& ex) { std::cerr << "Error: " << ex.what() << std::endl; |