-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBeatButton.h
More file actions
38 lines (27 loc) · 891 Bytes
/
BeatButton.h
File metadata and controls
38 lines (27 loc) · 891 Bytes
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
#pragma once
#include "RotaryEncoder.h"
#define NUM_PRESSES 16
class BeatButton
{
public:
BeatButton(const RotaryEncoder& rotaryEncoder) :
rot(rotaryEncoder), hit(false), swState(true), lastTempoAdjust(0), idxLastPress(0),
microsPerBeat(500000), tAutoBeat(1) // default to 120 bpm at boot
{}
void update(long now, long tpf);
bool consumeHit() {
bool hasHit = hit;
hit = false;
return hasHit;
}
private:
const RotaryEncoder& rot;
bool hit;
bool swState;
int lastTempoAdjust;
long lastPresses[NUM_PRESSES];
int idxLastPress;
long microsPerBeat; // delay between hits in microseconds
long tAutoBeat; // time until next beat hit
void doPress(long now);
};