-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidiMap.h
101 lines (85 loc) · 3.3 KB
/
midiMap.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
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
#ifndef MGNR_MIDI_MAP
#define MGNR_MIDI_MAP
#include "hbb.h"
#include "note.h"
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string.h>
namespace mgnr{
class midiMap{
public:
midiMap();
~midiMap();
note * addNote(double position,double tone,double duration,int v,const std::string & info,int ins_id=0);
void removeNote(note * p);
void resizeNote(note * p);
void clear();
int find(const HBB::vec & from,const HBB::vec & to,void(*callback)(note*,void*),void * arg);
int find(double step,void(*callback)(note*,void*),void * arg);
int find(const HBB::vec & p,void(*callback)(note*,void*),void * arg);
//获取范围内的音符
std::string infoFilter;
std::set<note*> notes;
std::map<noteIndex,note*> timeIndex;
std::map<int,double> timeMap;
std::multimap<int,std::tuple<std::string,int>> metaContent;
int TPQ;
double XShift;
int baseTone;
bool isMajor;
double sectionLen;//小节线
int section;
inline void setSection(int s){
section = s;
setSection();
}
inline void setSection(){
if(section<=0 || section>7)
section=4;
sectionLen=section*TPQ;
}
double getTempo(int tick);
bool addTempo(int tick,double tp);
std::tuple<bool,int,double> removeTempoBeforePos(int tick);
void getTempo(int begin,const std::function<bool(int,double)> & callback);//获取一段区域的速度
void removeControl(double begin,const std::string & info);
void addControl(double begin,const std::string & info);
int getAreaNote(double begin,double len,const std::string & info,double forceLen=0.6666,double minLen=0.25);//获取一个范围内的主要音符
int getSectionNote(double sec,const std::string & info,double forceLen=0.6666,double minLen=0.25);
int getBaseTone();//获取调性
inline void removeNoteById(int id){
auto p = seekNoteById(id);
if(p){
removeNote(p);
}
}
inline note * seekNoteById(int id){
auto it = noteIDs.find(id);
if(it!=noteIDs.end()){
return it->second;
}
return NULL;
}
std::unordered_map<std::string,std::vector<int> > chord_map;
std::unordered_map<std::string,int> note_number_map;
std::map<std::string,int> chord_map_note;
double noteTimeMax;
double noteToneMax;
double noteToneMin;
bool noteUpdated;
bool updateTimeMax();
private:
std::map<int,note*> noteIDs;
HBB indexer;
void * pool;
int id;
};
}
#endif