-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine.hpp
79 lines (68 loc) · 1.8 KB
/
engine.hpp
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
76
77
78
79
#ifndef REABLINK_ENGINE_HPP
#define REABLINK_ENGINE_HPP
#include <ableton/Link.hpp>
#include <mutex>
namespace reablink
{
using namespace ableton;
class AudioEngine
{
public:
AudioEngine(Link& link);
static void TempoCallback(double bpm);
void setMaster(bool isMaster);
void setPuppet(bool isPuppet);
bool getMaster();
bool getPuppet();
void startPlaying();
void stopPlaying();
bool isPlaying() const;
double beatTime() const;
void setTempo(double tempo);
double quantum() const;
void setQuantum(double quantum);
bool isStartStopSyncEnabled() const;
void setStartStopSyncEnabled(bool enabled);
void audioCallback(std::chrono::microseconds hostTime,
std::size_t numSamples);
void audioCallback2(std::chrono::microseconds hostTime,
std::size_t numSamples);
private:
struct EngineData
{
double requestedTempo;
bool requestStart;
bool requestStop;
double quantum;
bool startStopSyncOn;
};
EngineData pullEngineData();
Link& mLink; // NOLINT
EngineData mSharedEngineData;
EngineData mLockfreeEngineData;
bool mIsPlaying; // NOLINT
std::mutex mEngineDataGuard;
std::atomic_bool isPuppet{false};
std::atomic_bool isMaster{false};
friend class AudioPlatform;
// int playbackFrameCount = 0;
double qnAbs = 0.;
double qnJumpOffset = 0.;
double qnLandOffset = 0.;
double diff = 0;
double qLen = 0;
static constexpr auto beatTolerance = 0.02;
// static constexpr auto playbackFrameSafe = 16;
int syncTolerance = 6;
static constexpr auto tempoTolerance = 0.001;
};
class AudioPlatform
{
public:
AudioPlatform(Link& link) : mEngine(link)
{
}
AudioEngine mEngine;
};
} // namespace reablink
#endif // REABLINK_ENGINE_HPP