Files
projectm/src/libprojectM/TimeKeeper.cpp
milkdropper 758348f25a Beat sensitivity implemented (#348)
* Beat detect sensitivity fix.

* Default: 1.0

* ReadMe beat sensitivity min/max.

* Beat sensitivity from config or settings isn't initialized.

* Smarter position.

* Make PCMScale (vol_history) also impacted by beat_sensitivity.

* Enhance and clarify Hard Cuts and better separate beat sensitivity.

* Forgot one config.

* Consistency with defaults.

* Even more clear about the default for Beat Sensitivity.
2020-05-15 17:49:28 +03:00

118 lines
2.3 KiB
C++

#ifndef WIN32
#include <sys/time.h>
#else
#endif /** !WIN32 */
#include <stdlib.h>
#include "TimeKeeper.hpp"
#include "RandomNumberGenerators.hpp"
TimeKeeper::TimeKeeper(double presetDuration, double smoothDuration, double hardcutDuration, double easterEgg)
{
_smoothDuration = smoothDuration;
_presetDuration = presetDuration;
_hardcutDuration = hardcutDuration;
_easterEgg = easterEgg;
#ifndef WIN32
projectm_gettimeofday ( &this->startTime, NULL );
#else
startTime = GetTickCount();
#endif /** !WIN32 */
UpdateTimers();
}
void TimeKeeper::UpdateTimers()
{
#ifndef WIN32
_currentTime = getTicks ( &startTime ) * 0.001;
#else
_currentTime = getTicks ( startTime ) * 0.001;
#endif /** !WIN32 */
_presetFrameA++;
_presetFrameB++;
}
void TimeKeeper::StartPreset()
{
_isSmoothing = false;
_presetTimeA = _currentTime;
_presetFrameA = 1;
_presetDurationA = sampledPresetDuration();
}
void TimeKeeper::StartSmoothing()
{
_isSmoothing = true;
_presetTimeB = _currentTime;
_presetFrameB = 1;
_presetDurationB = sampledPresetDuration();
}
void TimeKeeper::EndSmoothing()
{
_isSmoothing = false;
_presetTimeA = _presetTimeB;
_presetFrameA = _presetFrameB;
_presetDurationA = _presetDurationB;
}
bool TimeKeeper::CanHardCut()
{
return ((_currentTime - _presetTimeA) > _hardcutDuration);
}
double TimeKeeper::SmoothRatio()
{
return (_currentTime - _presetTimeB) / _smoothDuration;
}
bool TimeKeeper::IsSmoothing()
{
return _isSmoothing;
}
double TimeKeeper::GetRunningTime()
{
return _currentTime;
}
double TimeKeeper::PresetProgressA()
{
if (_isSmoothing) return 1.0;
else return (_currentTime - _presetTimeA) / _presetDurationA;
}
double TimeKeeper::PresetProgressB()
{
return (_currentTime - _presetTimeB) / _presetDurationB;
}
int TimeKeeper::PresetFrameB()
{
return _presetFrameB;
}
int TimeKeeper::PresetFrameA()
{
return _presetFrameA;
}
int TimeKeeper::PresetTimeB()
{
return _presetTimeB;
}
int TimeKeeper::PresetTimeA()
{
return _presetTimeA;
}
double TimeKeeper::sampledPresetDuration() {
#ifdef WIN32
return _presetDuration;
#else
return fmax(1, fmin(60, RandomNumberGenerators::gaussian
(_presetDuration, _easterEgg)));
#endif
}