summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--Timer.cpp1
-rw-r--r--Timer.h54
-rw-r--r--UI.cpp18
-rw-r--r--UI.h9
-rw-r--r--main.cpp19
6 files changed, 106 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 47f9a5f..8ef3555 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,14 @@ TARGET=click
default: $(TARGET)
-SRCS=main.cpp MIDI.cpp PCM.cpp ClickStream.cpp config.cpp
+SRCS= \
+ main.cpp \
+ MIDI.cpp \
+ PCM.cpp \
+ ClickStream.cpp \
+ config.cpp \
+ UI.cpp \
+ Timer.cpp
OBJS=$(SRCS:.cpp=.o)
diff --git a/Timer.cpp b/Timer.cpp
new file mode 100644
index 0000000..afe5d24
--- /dev/null
+++ b/Timer.cpp
@@ -0,0 +1 @@
+#include "Timer.h"
diff --git a/Timer.h b/Timer.h
new file mode 100644
index 0000000..81192d6
--- /dev/null
+++ b/Timer.h
@@ -0,0 +1,54 @@
+#pragma once
+
+#include <boost/signals2.hpp>
+
+#include <chrono>
+
+using namespace std::chrono_literals;
+
+using clock_type = std::chrono::high_resolution_clock;
+
+class Timer
+{
+public:
+ Timer(std::chrono::milliseconds interval, bool cyclic) : m_start_time(clock_type::now()), m_interval(interval), m_running(false), m_cyclic(cyclic)
+ {}
+
+ // connect to this signal
+ boost::signals2::signal<void()> elapsed;
+
+ void start()
+ {
+ m_running = true;
+ m_start_time = clock_type::now();
+ }
+
+ void stop()
+ {
+ m_running = false;
+ }
+
+ bool is_elapsed()
+ {
+ return m_start_time + m_interval < clock_type::now();
+ }
+
+ void update()
+ {
+ if (m_running && is_elapsed()) {
+ elapsed();
+ if (m_cyclic) {
+ start();
+ } else {
+ stop();
+ }
+ }
+ }
+
+private:
+ std::chrono::time_point<clock_type> m_start_time;
+ std::chrono::milliseconds m_interval;
+ bool m_running;
+ bool m_cyclic;
+};
+
diff --git a/UI.cpp b/UI.cpp
new file mode 100644
index 0000000..f0eb0c3
--- /dev/null
+++ b/UI.cpp
@@ -0,0 +1,18 @@
+#include "UI.h"
+
+#include <iostream>
+
+void UI::draw()
+{
+ std::cout << std::endl;
+ std::cout << "- -- BPM +" << std::endl;
+ std::cout << "Mode: Click __/__ (Clock Internal)" << std::endl;
+ std::cout << "Status:" << std::endl;
+ std::cout << " Alive/not alive" << std::endl;
+ std::cout << " CPU: --% --% ..." << std::endl;
+ std::cout << " Notes/Channels: -- -- -- ... (Choose)" << std::endl;
+ std::cout << " Timestamp: ------" << std::endl;
+ std::cout << " Active sensing: ---" << std::endl;
+ std::cout << " Clock: ____" << std::endl;
+ std::cout << " Click: ____" << std::endl;
+}
diff --git a/UI.h b/UI.h
new file mode 100644
index 0000000..60b168c
--- /dev/null
+++ b/UI.h
@@ -0,0 +1,9 @@
+#pragma once
+
+class UI
+{
+public:
+ UI(){}
+
+ void draw();
+};
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;