diff options
author | Roland Reichwein <mail@reichwein.it> | 2025-01-12 13:05:43 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2025-01-12 13:05:43 +0100 |
commit | 33464a1eb6a95d5671ca0246169061868aef3bbe (patch) | |
tree | a3901867b6d908745ce6bdda58c83b99ef979a84 | |
parent | cdf85d6e04e664e4f56acd05affa287ac63ed125 (diff) |
Age out midi notes in UI
-rw-r--r-- | UI.cpp | 45 | ||||
-rw-r--r-- | UI.h | 8 |
2 files changed, 32 insertions, 21 deletions
@@ -68,6 +68,7 @@ UI::UI(Config& config): m_midi_notes{}, m_active_sensing_timestamp{}, m_midi_timestamp{}, + m_midi_monitor{30s}, m_note_bpm{2000ms}, m_clock_bpm{2000ms}, m_touchpad{} @@ -127,7 +128,7 @@ void UI::draw() std::cout << "\x1B[2J\x1B[H"; //std::cout << std::endl; - std::cout << fmt::format(editable_color, "{:3}", bpm) << " BPM " << fmt::format(input_color, "(+/-)") << std::endl; + std::cout << fmt::format(editable_color, "Speed: {:3}", bpm) << " BPM " << fmt::format(input_color, "(+/-)") << std::endl; std::cout << "Mode " << fmt::format(input_color, "(m)") << ": "; for (int i = 0; i < mode_names.size(); ++i) { if (i == mode) { @@ -144,19 +145,13 @@ void UI::draw() std::cout << std::endl; std::cout << "Status:" << std::endl; - std::cout << " CPU:"; - for (auto& i: cpuloads) { - std::cout << fmt::format(" {:2}%", i); - } - int max = *std::max_element(cpuloads.begin(), cpuloads.end()); - std::cout << fmt::format(", max. {:2}%", max) << std::endl; - std::cout << " MIDI Notes: "; - if (m_midi_monitor.empty()) { + if (m_midi_monitor.value().empty()) { std::cout << "--"; } else { int count{}; - for (const auto& i: m_midi_monitor) { + auto midi_monitor = m_midi_monitor.value(); + for (const auto& i: midi_monitor) { if (count == 0) { std::cout << fmt::format(editable_color, " {}/{}", i.first, i.second); } else { @@ -178,8 +173,15 @@ void UI::draw() std::cout << fmt::format(" MIDI Clock: {:3} BPM", m_clock_bpm.value()) << std::endl; std::cout << fmt::format(" Internal: {:3} BPM", internal_bpm) << std::endl; - std::cout << fmt::format(" Main loops/s: {:3}", main_loops_per_second) << std::endl; + std::cout << " CPU:"; + for (auto& i: cpuloads) { + std::cout << fmt::format(" {:2}%", i); + } + int max = *std::max_element(cpuloads.begin(), cpuloads.end()); + std::cout << fmt::format(", max. {:2}%", max) << std::endl; + std::cout << fmt::format(" Temperature: {:3} C", temperature) << std::endl; + std::cout << fmt::format(" Main loops/s: {:3}", main_loops_per_second) << std::endl; std::cout << std::endl; std::cout << "Log:" << std::endl; @@ -206,9 +208,10 @@ void UI::handle_input() } else if (c == 'm') { m_config.set_mode((m_config.get_mode() + 1) % 3); } else if (c == 'n') { - if (!m_midi_monitor.empty()) { - m_config.set_midi_channel(m_midi_monitor.front().first); - m_config.set_midi_note(m_midi_monitor.front().second); + auto midi_monitor = m_midi_monitor.value(); + if (!midi_monitor.empty()) { + m_config.set_midi_channel(midi_monitor.front().first); + m_config.set_midi_note(midi_monitor.front().second); } } else if (c == 'o') { m_config.set_output(1 - m_config.get_output()); @@ -224,9 +227,10 @@ void UI::handle_input() if (m_touchpad.event_is_button1(ev)) { m_config.set_mode((m_config.get_mode() + 1) % 3); } else if (m_touchpad.event_is_button2(ev)) { - if (!m_midi_monitor.empty()) { - m_config.set_midi_channel(m_midi_monitor.front().first); - m_config.set_midi_note(m_midi_monitor.front().second); + auto midi_monitor = m_midi_monitor.value(); + if (!midi_monitor.empty()) { + m_config.set_midi_channel(midi_monitor.front().first); + m_config.set_midi_note(midi_monitor.front().second); } } } @@ -257,10 +261,11 @@ void UI::slot_midi_note(int channel, int note, uint64_t timestamp) { m_midi_timestamp = timestamp; - m_midi_monitor.emplace_front(channel, note); + auto midi_monitor = m_midi_monitor.update(); + midi_monitor.emplace_front(channel, note); - while (m_midi_monitor.size() > midi_monitor_max_size) { - m_midi_monitor.pop_back(); + while (midi_monitor.size() > midi_monitor_max_size) { + midi_monitor.pop_back(); } count_midi_notes(); @@ -60,6 +60,12 @@ public: m_checkpoint_timestamp = clock_type::now(); } + T& update() + { + m_checkpoint_timestamp = clock_type::now(); + return m_value; + } + private: const std::chrono::milliseconds m_timeout; std::chrono::time_point<clock_type> m_checkpoint_timestamp{}; @@ -104,7 +110,7 @@ private: std::chrono::time_point<clock_type> m_active_sensing_timestamp; uint64_t m_midi_timestamp; - std::deque<std::pair<int,int>> m_midi_monitor; + AgeOutValue<std::deque<std::pair<int,int>>> m_midi_monitor; AgeOutValue<int> m_note_bpm; AgeOutValue<int> m_clock_bpm; |