summaryrefslogtreecommitdiffhomepage
path: root/UI.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-04 10:25:25 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-04 10:25:25 +0100
commitaaafcea7e26791acbf5b9612e3fb396edcdfcc8f (patch)
tree63131edf7b2eafe404a01e7ae01e2680d5f1b1e8 /UI.cpp
parent9351c6d9812523b0b8027f2b2e0de54c27004bc2 (diff)
Fill UI
Diffstat (limited to 'UI.cpp')
-rw-r--r--UI.cpp67
1 files changed, 61 insertions, 6 deletions
diff --git a/UI.cpp b/UI.cpp
index c699aba..4e063d0 100644
--- a/UI.cpp
+++ b/UI.cpp
@@ -8,11 +8,24 @@
#include <iostream>
#include <string>
+#include <fmt/color.h>
#include <fmt/format.h>
+const int midi_monitor_max_size = 3;
+
using namespace std::chrono_literals;
-UI::UI(): m_main_loops{}, m_main_loops_checkpoint{}, m_main_loops_timestamp{}, m_active_sensing_timestamp{}
+static std::vector<std::string> mode_names{{
+ "NoteClick", "Clock", "Internal"
+}};
+
+UI::UI(Config& config):
+ m_config(config),
+ m_main_loops{},
+ m_main_loops_checkpoint{},
+ m_main_loops_timestamp{},
+ m_active_sensing_timestamp{},
+ m_midi_timestamp{}
{
}
@@ -34,6 +47,10 @@ void UI::draw()
{
std::vector<int> cpuloads = get_cpu_loads();
int main_loops_per_second = get_main_loops_per_second();
+ int mode = m_config.get_mode();
+ int channel = m_config.get_midi_channel();
+ int note = m_config.get_midi_note();
+ int bpm = m_config.get_bpm();
bool active_sensing_detected = (clock_type::now() - m_active_sensing_timestamp) < 2s;
@@ -41,8 +58,18 @@ void UI::draw()
std::cout << "\x1B[2J\x1B[H";
//std::cout << std::endl;
- std::cout << "- -- BPM +" << std::endl;
- std::cout << "Mode: Click __/__ (Clock Internal)" << std::endl;
+ std::cout << fmt::format("- {:3} BPM +", bpm) << std::endl;
+ std::cout << "Mode: ";
+ for (int i = 0; i < mode_names.size(); ++i) {
+ if (i == mode) {
+ std::cout << fmt::format(fg(fmt::color::crimson) | fmt::emphasis::bold, " {}", mode_names[i]);
+ } else {
+ std::cout << fmt::format(" {}", mode_names[i]);
+ }
+ }
+ std::cout << std::endl;
+ std::cout << fmt::format("MIDI Note: {}/{}", channel, note);
+ std::cout << std::endl;
std::cout << std::endl;
std::cout << "Status:" << std::endl;
@@ -53,12 +80,29 @@ void UI::draw()
int max = *std::max_element(cpuloads.begin(), cpuloads.end());
std::cout << fmt::format(", max. {:2}%", max) << std::endl;
- std::cout << " Notes/Channels: -- -- -- ... (Choose)" << std::endl;
- std::cout << " MIDI Timestamp: ------" << std::endl;
+ std::cout << " MIDI Activity: ";
+ if (m_midi_monitor.empty()) {
+ std::cout << "--";
+ } else {
+ int count{};
+ for (const auto& i: m_midi_monitor) {
+ if (count == 0) {
+ std::cout << fmt::format(fg(fmt::color::crimson) | fmt::emphasis::bold, " {}/{}", i.first, i.second);
+ } else {
+ std::cout << fmt::format(" {}/{}", i.first, i.second);
+ }
+ ++count;
+ }
+ if (count >= midi_monitor_max_size) {
+ std::cout << " ...";
+ }
+ }
+ std::cout << std::endl;
+ std::cout << fmt::format(" MIDI Timestamp: {}", m_midi_timestamp) << std::endl;
std::cout << fmt::format(" Active sensing: {}", active_sensing_detected) << std::endl;
std::cout << " Clock: ____ BPM" << std::endl;
std::cout << " Click: ____ BPM" << std::endl;
- std::cout << " Internal: ____ BPM" << std::endl;
+ std::cout << fmt::format(" Internal: {:3} BPM", bpm) << std::endl;
std::cout << fmt::format(" Main loops/s: {}", main_loops_per_second) << std::endl;
@@ -76,3 +120,14 @@ void UI::slot_active_sensing()
{
m_active_sensing_timestamp = clock_type::now();
}
+
+void UI::slot_midi_note(int channel, int note, uint64_t timestamp)
+{
+ m_midi_timestamp = timestamp;
+
+ m_midi_monitor.emplace_front(channel, note);
+
+ while (m_midi_monitor.size() > midi_monitor_max_size) {
+ m_midi_monitor.pop_back();
+ }
+}