summaryrefslogtreecommitdiffhomepage
path: root/Click.h
blob: 6d3d871f335a1e17f7123708d658ac9ec4e4e7db (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
65
66
67
68
69
70
71
72
73
74
75
#pragma once

#include <boost/signals2.hpp>

#include "config.h"
#include "BPMDetect.h"

// Internally generated
// Configured via: BPM
class InternalClick
{
public:
  InternalClick(Config& config): m_config(config){}

private:
  Config& m_config;
};

// Generated from MIDI notes
// Configured via channel and note to listen to
class NoteClick
{
public:
  // signals
  boost::signals2::signal<void()> signal_click;
  boost::signals2::signal<void(int)> signal_bpm;

  NoteClick(Config& config):
    m_channel(config.get_midi_channel()),
    m_note(config.get_midi_note()),
    m_detect(1)
  {
    m_detect.signal_bpm.connect([&](int bpm){signal_bpm(bpm);});
  }

  // slots
  void receive_note(int channel, int note, uint64_t timestamp)
  {
    (void) timestamp;

    if (true || (channel == m_channel && note == m_note)) {
      signal_click();
      m_detect.receive_event();
    }
  }

private:
  int m_channel;
  int m_note;

  BPMDetect m_detect;
};

// Generated from MIDI Clock
class ClockClick
{
public:
  ClockClick(): m_detect(24)
  {
    m_detect.signal_bpm.connect([&](int bpm){signal_bpm(bpm);});
  }

  // signals
  boost::signals2::signal<void(int)> signal_bpm;

  // slots
  void receive_clock()
  {
    m_detect.receive_event();
  }

private:
  BPMDetect m_detect;
};