-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.h
42 lines (36 loc) · 914 Bytes
/
search.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
#pragma once
#include <coroutine>
#include <iostream>
#include <tuple>
#include <unordered_map>
#include <vector>
#include "generator.h"
#include "relative.h"
namespace midiSearch {
using melody_t = std::vector<int>;
using chord_t = std::vector<std::vector<int> >;
struct music {
melody_t melody;
melody_t relativeMelody;
chord_t chord;
std::string name;
};
using musicMap = std::unordered_map<std::string, music>;
//构建音频字典
inline musicMap buildMusicMap(generator<std::tuple<music,char*> >& reader) { //输入:读取器(协程)
musicMap res;
for (auto mu : reader) {
res[buildRelativeString(std::get<0>(mu).relativeMelody)] = std::get<0>(mu);
}
return res;
}
//获取首调
inline int getFirstTone(const melody_t & melody){
for(auto it:melody){
if(it!=0){
return it;
}
}
return 0;
}
} // namespace midiSearch