summaryrefslogtreecommitdiffhomepage
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp19
1 files changed, 16 insertions, 3 deletions
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 <cstdint>
+#include <chrono>
#include <cmath>
+#include <cstdint>
#include <iostream>
#include <limits>
#include <exception>
@@ -17,6 +20,7 @@
#include <boost/signals2.hpp>
+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;