From 05895c86bddf50aacb3bb5e6a6bcc073965341ef Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 3 Jan 2025 12:27:14 +0100 Subject: Add first UI --- main.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 629b92c..53e2947 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,13 @@ #include "ClickStream.h" #include "MIDI.h" #include "PCM.h" +#include "Timer.h" +#include "UI.h" #include "config.h" -#include +#include #include +#include #include #include #include @@ -17,6 +20,7 @@ #include +using namespace std::chrono_literals; using namespace std::string_literals; double diff_timespec(const struct timespec *time1, const struct timespec *time0) { @@ -30,10 +34,16 @@ int main(void) MIDI midi; ClickStream stream; PCM pcm{stream}; + UI ui; pcm.write(); + Timer timer_300ms(300ms, true); + timer_300ms.start(); + + // Signal-Slot Connections: midi.signal_click.connect([&](){stream.click();}); + timer_300ms.elapsed.connect([&](){ui.draw();}); while (true) { //std::cout << "Main loop entered." << std::endl; @@ -46,8 +56,8 @@ int main(void) FD_SET(pcm.fd(), &write_set); struct timeval timeout; - timeout.tv_sec = 1; - timeout.tv_usec = 0; + timeout.tv_sec = 0; + timeout.tv_usec = 300000; int result = select(FD_SETSIZE, &read_set, &write_set, NULL, &timeout); if (result < 0) { @@ -68,6 +78,9 @@ int main(void) //std::cout << "DEBUG: WRITE" << std::endl; pcm.write(); } + + // handle timers, TODO: make updates more efficient at scale + timer_300ms.update(); } } catch (const std::exception& ex) { std::cerr << "Error: " << ex.what() << std::endl; -- cgit v1.2.3