1 #include "TempoTools.h"
3 using namespace std::chrono
;
5 TempoTools::TempoTools(RhythmIO
* rhythmio
)
16 TempoTools::~TempoTools()
20 void TempoTools::createTimeData(std::string levelPath
) {
22 timeKeys
= rio
->createBeatPatterns(levelPath
);
24 void TempoTools::clearTimeData() {
28 rio
->keyPositions
= 0;
30 void TempoTools::proccessDataSlow() {
31 rio
->bufferBeatData(timeKeys
, musicStart
, &hitData
, &cueData
);
33 void TempoTools::setMusicStart(long long mStart
) {
37 void TempoTools::countDown(float* time
, float duration
) {
38 milliseconds ms
= duration_cast
<milliseconds
>(
39 system_clock::now().time_since_epoch());
40 long long expiredTime
= ms
.count();
41 *time
= duration
- (expiredTime
- musicStart
) / 1000.0;
44 double TempoTools::clickTempo(int time
) {
46 clickTimes
.push_back(time
);
47 int size
= clickTimes
.size();
52 else if (size
> limit
) {
53 clickTimes
.erase(clickTimes
.begin());
57 for (int t
= 0; t
< size
- 1; t
++) {
58 combined
+= clickTimes
.at(t
+ 1) - clickTimes
.at(t
);
61 double combinedAv
= combined
/ (size
- 1);
63 double clickRate
= 60000 / combinedAv
;
64 double factor
= clickRate
/ tempo
;
74 short TempoTools::autoPlay(int type
){
75 milliseconds ms
= duration_cast
<milliseconds
>(
76 system_clock::now().time_since_epoch());
77 long long time
= ms
.count();
78 long long difference
= 0;
79 for (int i
= 1; i
< 10; i
++) {
81 difference
= cueFileTime
[i
] - time
;
82 if (difference
< 8 && difference
> -8 && !autoplayed
[i
]) {
86 else if (difference
< 8 && difference
> -8 && autoplayed
[i
]) {}
88 autoplayed
[i
] = false;
95 short TempoTools::clickAccuracy(int type
) {
96 milliseconds ms
= duration_cast
<milliseconds
>(
97 system_clock::now().time_since_epoch());
99 long long clickTime
= ms
.count();
103 for (int i
= 1; i
< 10; i
++) {
106 difference
= fileTime
[i
] - clickTime
;
108 oldDifference
= clickTime
- oldTime
[i
];
112 if (difference
< errorMarginPerf
|| oldDifference
< errorMarginPerf
) {
115 else if (difference
> oldDifference
) {
119 else if (difference
< oldDifference
) {
125 short TempoTools::clickAccuracyRange(int type
) {
126 milliseconds ms
= duration_cast
<milliseconds
>(
127 system_clock::now().time_since_epoch());
129 long long clickTime
= ms
.count();
133 for (int i
= 1; i
< 10; i
++) {
136 difference
= fileTime
[i
] - clickTime
;
138 oldDifference
= clickTime
- oldTime
[i
];
142 if (difference
< errorMarginPerf
|| oldDifference
< errorMarginPerf
) {
145 else if (difference
< errorMarginGood
|| oldDifference
< errorMarginGood
) {
149 else if (difference
< errorMarginOK
|| oldDifference
< errorMarginOK
) {
153 else if (difference
< errorMarginBad
|| oldDifference
< errorMarginBad
) {
160 //when a certain vector's time has expired, switch to the next one and keep the old one in an int.
161 void TempoTools::moveTicker() {
162 milliseconds ms
= duration_cast
<milliseconds
>(
163 system_clock::now().time_since_epoch());
164 long long ct
= ms
.count();
166 for (int i
= 1; i
< 10; i
++) {
167 if (hitData
.size() != 0) {
168 if (ct
> fileTime
[i
] && hitData
.at(0).at(1) == 1) {
169 oldTime
[i
] = fileTime
[i
];
170 fileTime
[i
] = (hitData
.at(0)).at(0);
171 hitData
.erase(hitData
.begin());
172 std::cout
<< "\tupdate Hit " << hitData
.size() << "\n";
176 for (int i
= 1; i
< 10; i
++) {
177 if (cueData
.size() != 0) {
178 if (ct
> cueFileTime
[i
] && cueData
.at(0).at(1) == i
* 10) {
179 cueFileTime
[i
] = cueData
.at(0).at(0);
180 cueData
.erase(cueData
.begin());
181 std::cout
<< "\tupdate Cue" << cueData
.size() << "\n";