summaryrefslogtreecommitdiffhomepage
path: root/InternalClick.cpp
blob: e0c757e66fe14ff26ab1b110bb7ae169f100256b (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
#include "InternalClick.h"

#include "log.h"
#include "debug.h"

#include <fmt/format.h>

InternalClick::InternalClick(Config& config):
  m_config{config},
  m_timestamp{clock_type::now()}
{
}

void InternalClick::run_cyclic_50ms()
{
  std::chrono::time_point<clock_type> now = clock_type::now();

  std::chrono::duration<double> duration{60.0 / static_cast<double>(m_config.get_bpm())};
  if (now - m_timestamp > duration) {
    std::chrono::duration<double> offset = now - m_timestamp - duration;
    m_timestamp = now - std::chrono::duration_cast<clock_type::duration>(offset);
    signal_click(offset);
    debug_cout << fmt::format("offset={}", offset.count()) << std::endl;
  }
}