summaryrefslogtreecommitdiffhomepage
path: root/UI.cpp
blob: f9b2512a5f1b7dc970b505fa1d8b53a35b648a53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "UI.h"

#include "cpuload.h"

#include <algorithm>
#include <iostream>
#include <string>

#include <fmt/format.h>

using namespace std::chrono_literals;

UI::UI(): m_main_loops{}, m_main_loops_checkpoint{}, m_main_loops_timestamp{}
{
}

int UI::get_main_loops_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);

  // update state
  m_main_loops_timestamp = now;
  m_main_loops_checkpoint = m_main_loops;

  return loops_per_second;
}

void UI::draw()
{
  std::vector<int> cpuloads = get_cpu_loads();
  int main_loops_per_second = get_main_loops_per_second();

  std::cout << std::endl;
  std::cout << "- -- BPM +" << std::endl;
  std::cout << "Mode: Click __/__ (Clock Internal)" << std::endl;
  std::cout << std::endl;
  std::cout << "Status:" << std::endl;
  std::cout << "  Alive/not alive" << 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 << "  Notes/Channels: -- -- -- ... (Choose)" << std::endl;
  std::cout << "  Timestamp: ------" << std::endl;
  std::cout << "  Active sensing: ---" << std::endl;
  std::cout << "  Clock: ____ BPM" << std::endl;
  std::cout << "  Click: ____ BPM" << std::endl;

  std::cout << fmt::format("  Main loops/s: {}", main_loops_per_second) << std::endl;
}

void UI::count_main_loops()
{
  ++m_main_loops;
  //std::cout << "DEBUG:" << m_main_loops << std::endl;
}