-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDummyAudioToScoreAligner.cpp
108 lines (81 loc) · 2.42 KB
/
DummyAudioToScoreAligner.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
Yucong Jiang, June 2021
*/
#include "DummyAudioToScoreAligner.h"
#include "Templates.h"
#include "Paths.h"
#include <filesystem>
using namespace std;
DummyAudioToScoreAligner::DummyAudioToScoreAligner(float inputSampleRate, int hopSize,
int startEvent, int endEvent, int startFrame, int endFrame) :
m_inputSampleRate{inputSampleRate} , m_hopSize{hopSize}, m_startEvent{startEvent},
m_endEvent{endEvent}, m_startFrame{startFrame}, m_endFrame{endFrame}
{
}
DummyAudioToScoreAligner::~DummyAudioToScoreAligner()
{
}
bool DummyAudioToScoreAligner::loadAScore(string scoreName, int blockSize)
{
cerr << "In loadAScore: scoreName is -> " << scoreName << '\n';
auto scores = Paths::getScores();
if (scores.find(scoreName) == scores.end()) {
cerr << "Score not found: " << scoreName << '\n';
return false;
}
filesystem::path targetPath = scores[scoreName];
// Paths::getScores() has already verified that these exist
string scorePath = targetPath.string() + "/" + scoreName + ".solo";
string scoreMeterPath = targetPath.string() + "/" + scoreName + ".meter";
bool success = m_score.initialize(scorePath);
if (success) success = m_score.readMeter(scoreMeterPath);
NoteTemplates t =
CreateNoteTemplates::getNoteTemplates(m_inputSampleRate, blockSize);
m_score.setEventTemplates(t);
return success;
}
DummyAudioToScoreAligner::AlignmentResults DummyAudioToScoreAligner::align()
{
AlignmentResults results;
// Do the alignment work here!
// This is fake alignment output, for testing this dummy aligner:
for (int i = m_startEvent; i <= m_endEvent; i++) {
results.push_back(1 + i * 10);
}
return results;
}
float DummyAudioToScoreAligner::getSampleRate() const
{
return m_inputSampleRate;
}
float DummyAudioToScoreAligner::getHopSize() const
{
return m_hopSize;
}
Score DummyAudioToScoreAligner::getScore() const
{
return m_score;
}
void DummyAudioToScoreAligner::setAlignmentConstraints(int se, int ee, int sf, int ef)
{
m_startEvent = se;
m_endEvent = ee;
m_startFrame = sf;
m_endFrame = ef;
}
int DummyAudioToScoreAligner::getStartEvent() const
{
return m_startEvent;
}
int DummyAudioToScoreAligner::getEndEvent() const
{
return m_endEvent;
}
int DummyAudioToScoreAligner::getStartFrame() const
{
return m_startFrame;
}
int DummyAudioToScoreAligner::getEndFrame() const
{
return m_endFrame;
}