Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/engine/clockcontrol.cpp

Go to the documentation of this file.
00001 #include "engine/clockcontrol.h"
00002 
00003 #include "controlobject.h"
00004 #include "configobject.h"
00005 #include "cachingreader.h"
00006 #include "engine/enginecontrol.h"
00007 
00008 ClockControl::ClockControl(const char* pGroup, ConfigObject<ConfigValue>* pConfig)
00009         : EngineControl(pGroup, pConfig) {
00010     m_pCOBeatActive = new ControlObject(ConfigKey(pGroup, "beat_active"));
00011     m_pCOBeatActive->set(0.0f);
00012     m_pCOSampleRate = ControlObject::getControl(ConfigKey("[Master]","samplerate"));
00013 }
00014 
00015 ClockControl::~ClockControl() {
00016     delete m_pCOBeatActive;
00017 }
00018 
00019 void ClockControl::trackLoaded(TrackPointer pTrack) {
00020     // Clear on-beat control
00021     m_pCOBeatActive->set(0.0f);
00022 
00023     // Disconnect any previously loaded track/beats
00024     if (m_pTrack) {
00025         disconnect(m_pTrack.data(), SIGNAL(beatsUpdated()),
00026                    this, SLOT(slotBeatsUpdated()));
00027     }
00028     m_pBeats.clear();
00029     m_pTrack.clear();
00030 
00031     if (pTrack) {
00032         m_pTrack = pTrack;
00033         m_pBeats = m_pTrack->getBeats();
00034         connect(m_pTrack.data(), SIGNAL(beatsUpdated()),
00035                 this, SLOT(slotBeatsUpdated()));
00036     }
00037 }
00038 
00039 void ClockControl::trackUnloaded(TrackPointer pTrack) {
00040     trackLoaded(TrackPointer());
00041 }
00042 
00043 void ClockControl::slotBeatsUpdated() {
00044     if(m_pTrack) {
00045         m_pBeats = m_pTrack->getBeats();
00046     }
00047 }
00048 
00049 double ClockControl::process(const double dRate,
00050                              const double currentSample,
00051                              const double totalSamples,
00052                              const int iBuffersize) {
00053     double samplerate = m_pCOSampleRate->get();
00054 
00055     // TODO(XXX) should this be customizable, or latency dependent?
00056     const double blinkSeconds = 0.100;
00057 
00058     // Multiply by two to get samples from frames. Interval is scaled linearly
00059     // by the rate.
00060     const double blinkIntervalSamples = 2.0 * samplerate * (1.0 * dRate) * blinkSeconds;
00061 
00062     if (m_pBeats) {
00063         double closestBeat = m_pBeats->findClosestBeat(currentSample);
00064         double distanceToClosestBeat = fabs(currentSample - closestBeat);
00065         m_pCOBeatActive->set(distanceToClosestBeat < blinkIntervalSamples / 2.0);
00066     }
00067 
00068     return kNoTrigger;
00069 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines