summaryrefslogtreecommitdiffhomepage
path: root/UI.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2025-01-04 13:48:34 +0100
committerRoland Reichwein <mail@reichwein.it>2025-01-04 13:48:34 +0100
commit39ec820c931b07bc0cec98add36f106a5965e137 (patch)
treed1f2f0feb07ff325f363e767181ffaeeab94e20b /UI.cpp
parentb2c35cdf69a9084806ac7930cf4475980d596cf6 (diff)
BPM detect
Diffstat (limited to 'UI.cpp')
-rw-r--r--UI.cpp88
1 files changed, 64 insertions, 24 deletions
diff --git a/UI.cpp b/UI.cpp
index 4e063d0..0adb48b 100644
--- a/UI.cpp
+++ b/UI.cpp
@@ -15,44 +15,66 @@ const int midi_monitor_max_size = 3;
using namespace std::chrono_literals;
-static std::vector<std::string> mode_names{{
+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{}
+static std::vector<std::string> output_names{
+ "Off", "On"
+};
+
+static std::vector<std::string> active_sensing_names{
+ "Not Detected", "Detected"
+};
+
+IntervalCounter::IntervalCounter()
{
}
-int UI::get_main_loops_per_second()
+int IntervalCounter::get_count_per_second()
{
// calculate result
std::chrono::time_point<clock_type> now = clock_type::now();
- uint64_t diff_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_main_loops_timestamp).count();
- uint64_t loops_per_second = (diff_ms == 0 || m_main_loops_checkpoint == 0) ? 0 : ((m_main_loops - m_main_loops_checkpoint) * 1000 / diff_ms);
+
+ uint64_t diff_ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_checkpoint_timestamp).count();
+ uint64_t count_per_second = (diff_ms == 0 || m_count_checkpoint == 0) ? 0 : ((m_count - m_count_checkpoint) * 1000 / diff_ms);
// update state
- m_main_loops_timestamp = now;
- m_main_loops_checkpoint = m_main_loops;
+ m_checkpoint_timestamp = now;
+ m_count_checkpoint = m_count;
- return loops_per_second;
+ return count_per_second;
+}
+
+void IntervalCounter::count()
+{
+ m_count++;
+}
+
+UI::UI(Config& config):
+ m_config(config),
+ m_main_loops{},
+ m_midi_events{},
+ m_active_sensing_timestamp{},
+ m_midi_timestamp{},
+ m_note_bpm{},
+ m_clock_bpm{}
+{
}
void UI::draw()
{
std::vector<int> cpuloads = get_cpu_loads();
- int main_loops_per_second = get_main_loops_per_second();
+ int main_loops_per_second = m_main_loops.get_count_per_second();
+ int midi_events_per_second = m_midi_events.get_count_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();
+ int output = m_config.get_output();
- bool active_sensing_detected = (clock_type::now() - m_active_sensing_timestamp) < 2s;
+ int active_sensing_detected = (clock_type::now() - m_active_sensing_timestamp) < 2s ? 1 : 0;
// clear screen
std::cout << "\x1B[2J\x1B[H";
@@ -70,6 +92,8 @@ void UI::draw()
std::cout << std::endl;
std::cout << fmt::format("MIDI Note: {}/{}", channel, note);
std::cout << std::endl;
+ std::cout << "Audio Output: " << fmt::format(fg(fmt::color::crimson) | fmt::emphasis::bold, "{}", output_names[output]);
+ std::cout << std::endl;
std::cout << std::endl;
std::cout << "Status:" << std::endl;
@@ -80,7 +104,7 @@ void UI::draw()
int max = *std::max_element(cpuloads.begin(), cpuloads.end());
std::cout << fmt::format(", max. {:2}%", max) << std::endl;
- std::cout << " MIDI Activity: ";
+ std::cout << " MIDI Notes: ";
if (m_midi_monitor.empty()) {
std::cout << "--";
} else {
@@ -99,10 +123,11 @@ void UI::draw()
}
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 << fmt::format(" Internal: {:3} BPM", bpm) << std::endl;
+ std::cout << " MIDI Active Sensing: " << fmt::format(fg(fmt::color::blue) | fmt::emphasis::bold, "{}", active_sensing_names[active_sensing_detected]) << std::endl;
+ std::cout << fmt::format(" MIDI Events/s: {}", midi_events_per_second) << std::endl;
+ std::cout << fmt::format(" MIDI Clock: {:3} BPM", m_clock_bpm) << std::endl;
+ std::cout << fmt::format(" MIDI Click: {:3} BPM", m_note_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;
@@ -112,8 +137,12 @@ void UI::draw()
void UI::count_main_loops()
{
- ++m_main_loops;
- debug_cout << "DEBUG:" << m_main_loops << std::endl;
+ m_main_loops.count();
+}
+
+void UI::count_midi_events()
+{
+ m_midi_events.count();
}
void UI::slot_active_sensing()
@@ -131,3 +160,14 @@ void UI::slot_midi_note(int channel, int note, uint64_t timestamp)
m_midi_monitor.pop_back();
}
}
+
+void UI::slot_note_bpm(int bpm)
+{
+ m_note_bpm = bpm;
+}
+
+void UI::slot_clock_bpm(int bpm)
+{
+ m_clock_bpm = bpm;
+}
+