diff options
Diffstat (limited to 'UI.cpp')
-rw-r--r-- | UI.cpp | 67 |
1 files changed, 61 insertions, 6 deletions
@@ -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(); + } +} |