-
Notifications
You must be signed in to change notification settings - Fork 0
/
BeatAnalyzer.h
64 lines (47 loc) · 1.51 KB
/
BeatAnalyzer.h
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
56
57
58
59
60
61
62
63
64
#pragma once
#include "Beat.h"
#include "BeatBranch.h"
#include "Note.h"
#include <iostream>
#include <math.h>
namespace RhythmTranscriber
{
extern unsigned int iters;
class BeatAnalyzer
{
public:
BaseNote *notes = nullptr;
unsigned int notesLen = 0;
float bpm = 0.f;
unsigned int maxDepth = 3;
/// @todo Move to private, it's public right now for testing purposes.
BeatBranch branch;
BeatBranch bestBranch;
float bestBranchScore = 0.f;
void set_bpm(float bpm);
void set_depth(unsigned int depth);
void get_best_branch_at(unsigned int noteIndex);
float calc_branch_score();
private:
float expectedBeatDuration = 0.f;
float minBeatDuration = 0.f;
float maxBeatDuration = 0.f;
/// @brief After evaluating the best branch, this will be set to the branches first beat.
/// Further branch evaluations can use this as the preceding beat to the first beat of the
/// branch for scoring.
Beat recentBestBeat;
void create_beat_branch(BaseNote *startNote, bool startsOffbeat, unsigned int depth);
inline void eval_branch()
{
if (branch.create_beats())
{
float branchScore = calc_branch_score();
if (branchScore > bestBranchScore)
{
bestBranchScore = branchScore;
bestBranch = branch;
}
}
}
};
}