blob: 2a374aa1b45e9c2e7953e8c0b4ce9ac7d93ed731 (
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
|
#include "engine/controls/clockcontrol.h"
#include "control/controlobject.h"
#include "control/controlproxy.h"
#include "engine/controls/enginecontrol.h"
#include "preferences/usersettings.h"
#include "track/track.h"
ClockControl::ClockControl(QString group, UserSettingsPointer pConfig)
: EngineControl(group, pConfig) {
m_pCOBeatActive = new ControlObject(ConfigKey(group, "beat_active"));
m_pCOBeatActive->set(0.0);
m_pCOSampleRate = new ControlProxy("[Master]","samplerate");
}
ClockControl::~ClockControl() {
delete m_pCOBeatActive;
delete m_pCOSampleRate;
}
// called from an engine worker thread
void ClockControl::trackLoaded(TrackPointer pNewTrack) {
mixxx::BeatsPointer pBeats;
if (pNewTrack) {
pBeats = pNewTrack->getBeats();
}
trackBeatsUpdated(pBeats);
}
void ClockControl::trackBeatsUpdated(mixxx::BeatsPointer pBeats) {
// Clear on-beat control
m_pCOBeatActive->set(0.0);
m_pBeats = pBeats;
}
void ClockControl::process(const double dRate,
const double currentSample,
const int iBuffersize) {
Q_UNUSED(iBuffersize);
double samplerate = m_pCOSampleRate->get();
// TODO(XXX) should this be customizable, or latency dependent?
const double blinkSeconds = 0.100;
// Multiply by two to get samples from frames. Interval is scaled linearly
// by the rate.
const double blinkIntervalSamples = 2.0 * samplerate * (1.0 * dRate) * blinkSeconds;
mixxx::BeatsPointer pBeats = m_pBeats;
if (pBeats) {
double closestBeat = pBeats->findClosestBeat(currentSample);
double distanceToClosestBeat = fabs(currentSample - closestBeat);
m_pCOBeatActive->set(distanceToClosestBeat < blinkIntervalSamples / 2.0);
}
}
|