-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetronome.h
52 lines (40 loc) · 998 Bytes
/
metronome.h
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
#ifndef METRONOME_H
#define METRONOME_H
#include "portaudio.h"
#include <string>
#include <list>
#include <chrono>
const int SAMPLE_RATE = 44100;
struct Sample {
long long framesCount;
float *frames;
};
struct MetronomeState {
unsigned int tempo;
unsigned int beatsPerBar;
unsigned int barBeatNumber;
const Sample *sample;
const Sample *accentSample;
long long pos;
bool resetting;
};
const int MIN_TEMPO = 20;
const int MAX_TEMPO = 350;
class Metronome {
public:
Metronome(std::string samplePath, std::string accentSamplePath);
~Metronome();
unsigned int tempo();
void setTempo(unsigned int newTempo);
unsigned int beatsPerBar();
void setBeatsPerBar(unsigned int newBeatsPerBar);
void start();
void stop();
void tapTempo();
private:
PaStream *stream;
MetronomeState *state;
std::list<std::chrono::system_clock::time_point> m_tapTempoTimestamps;
const Sample * loadSample(std::string path);
};
#endif // METRONOME_H