forked from NaiJi/project-kyoku
Implement slider tick animation on BPM calculator
parent
60d7b4e346
commit
46baf6fdfb
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "mathutils.h"
|
||||
|
||||
namespace beat_utils
|
||||
{
|
||||
struct BeatInfo
|
||||
{
|
||||
long double rate_per_microsecond = 0.;
|
||||
microsec average_interval = 0;
|
||||
};
|
||||
|
||||
BeatInfo calculateBeatRateInfo(const std::vector<microsec>& approximate_deltas);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
#include "tools/beatutils.h"
|
||||
#include <numeric>
|
||||
#include <iostream>
|
||||
|
||||
auto beat_utils::calculateBeatRateInfo(const std::vector<microsec>& approximate_deltas) -> BeatInfo
|
||||
{
|
||||
if (approximate_deltas.empty())
|
||||
return {};
|
||||
|
||||
const microsec sum = std::accumulate(approximate_deltas.begin(), approximate_deltas.end(), 0);
|
||||
const std::size_t amount = approximate_deltas.size();
|
||||
|
||||
long double average = static_cast<long double>(sum)
|
||||
/ static_cast<long double>(amount);
|
||||
|
||||
|
||||
|
||||
return BeatInfo
|
||||
{
|
||||
60000000. / average,
|
||||
static_cast<microsec>(average)
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue