summaryrefslogtreecommitdiffhomepage
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..629b92c
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,78 @@
+#include "ClickStream.h"
+#include "MIDI.h"
+#include "PCM.h"
+#include "config.h"
+
+#include <cstdint>
+#include <cmath>
+#include <iostream>
+#include <limits>
+#include <exception>
+#include <stdexcept>
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
+
+#include <boost/signals2.hpp>
+
+using namespace std::string_literals;
+
+double diff_timespec(const struct timespec *time1, const struct timespec *time0) {
+ return (time1->tv_sec - time0->tv_sec)
+ + (time1->tv_nsec - time0->tv_nsec) / 1000000000.0;
+}
+
+int main(void)
+{
+ try {
+ MIDI midi;
+ ClickStream stream;
+ PCM pcm{stream};
+
+ pcm.write();
+
+ midi.signal_click.connect([&](){stream.click();});
+
+ while (true) {
+ //std::cout << "Main loop entered." << std::endl;
+ fd_set read_set;
+ FD_ZERO(&read_set);
+ FD_SET(midi.fd(), &read_set);
+
+ fd_set write_set;
+ FD_ZERO(&write_set);
+ FD_SET(pcm.fd(), &write_set);
+
+ struct timeval timeout;
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+
+ int result = select(FD_SETSIZE, &read_set, &write_set, NULL, &timeout);
+ if (result < 0) {
+ throw std::runtime_error("select() failed");
+ } else if (result == 0) {
+ throw std::runtime_error("select() timeout");
+ }
+
+ if (midi.event_ready())
+ {
+ //std::cout << "read..." << std::endl;
+ auto event = midi.read();
+ //std::cout << "process..." << std::endl;
+ midi.process(event);
+ }
+
+ if (pcm.write_available()) {
+ //std::cout << "DEBUG: WRITE" << std::endl;
+ pcm.write();
+ }
+ }
+ } catch (const std::exception& ex) {
+ std::cerr << "Error: " << ex.what() << std::endl;
+ }
+
+ return 0;
+}
+