-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditTable.h
executable file
·209 lines (186 loc) · 8.11 KB
/
editTable.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#ifndef MGNR_EDIT_TABLE
#define MGNR_EDIT_TABLE
#include "midiMap.h"
#include <sstream>
#include <list>
#include <stdio.h>
#include <memory>
namespace mgnr{
struct noteInfo{
//音符数据(如果是删除的话)
float position;
float tone;
float delay;
int volume;
int id;
std::string info;
noteInfo(note * p):info(p->info.value()){
position = p->begin;
tone = p->tone;
delay = p->delay;
volume = p->volume;
id = p->id;
}
};
struct history:public std::enable_shared_from_this<history>{
enum{
H_NOTE_ADD,
H_NOTE_DEL,
H_TEMPO_ADD,
H_TEMPO_DEL
}method;
std::list<int> noteIds;//音符,如果是添加的话,将会存在
int begin;//起始时间
double tempo;//添加删除速度时使用
std::list<std::unique_ptr<noteInfo> > notes;
};
class editTable:public midiMap{
public:
editTable();
~editTable();
void render();
void drawDisplay();
virtual void drawNote_begin()=0;
virtual void drawNote(int fx,int fy,int tx,int ty, int volume,const stringPool::stringPtr & info,bool selected,bool onlydisplay=false)=0;
virtual void drawNote_end()=0;
HBB::vec screenToAbs(int x,int y);//屏幕坐标转midi绝对坐标
note * clickToAdd(int x,int y);
void addDisplaied();
int clickToSelect(int x,int y);
void clickToSetTempo(int x,int y,double tp);
void clickToRemoveTempo(int x,int y);
void clickToAddDescription(int x,int y);
void clickToSetDescription(int x,int y);
void clickToLookAt(int x,int y);
int selectAll();
void clearSelected();
void removeSelected();
void selectedToRelative(std::string & out);
void clearNotes();
void renameSelected(const stringPool::stringPtr & n);
void resizeSelected(int delta);
void automatic(float & x,float & y);
void clickToDisplay(int x,int y);
void clickToDisplay_close();
int selectByArea(int x,int y,int len);
int selectByArea_unique(int x,int y,int len);
int selectByArea(int selectBoxX,int selectBoxXend,int selectBoxY,int selectBoxYend);
void drawNoteAbs(note*);//画音符绝对坐标
void drawNoteAbs(float begin,float tone,float delay,float volume,const stringPool::stringPtr & info,bool selected,bool onlydisplay=false);
void findNote();//根据参数找到搜索矩形,利用HBB找到音符
void drawTableRaws();
bool drawToneRaw(int t);
void drawTableColumns();
void drawSectionLine();
void drawTempoLine();
void drawDescriptionsLine();
void drawCaptions();
virtual void drawTableRaw(int from,int to,int left,int right,int t)=0;
virtual void drawTimeCol(float p)=0;
virtual void drawSectionCol(float p,int n)=0;
virtual void drawTempo(float p,double t)=0;
virtual void drawTempoPadd()=0;
virtual void drawDescriptions(float p,const stringPool::stringPtr & title,const std::string & content)=0;
virtual void drawDescriptionsPadd()=0;
virtual void drawScroll()=0;
virtual void drawCaption(float p,const std::string & str)=0;
virtual void callAddDescription(int tick)=0;
virtual void callEditDescription(int tick, const stringPool::stringPtr &title, const std::string &content)=0;
virtual void onScriptCmd(const char *);
void toString(std::string & str);
void loadString(const std::string & str);
void loadMidi(const std::string & str);
std::string loadMidi_preprocess(const std::string & str,const std::string & script,int tone);
std::string exportString();
void exportMidi(const std::string & str);
float lookAtX;//瞄准位置(左边缘中心点)
float lookAtY;
int rawLeft;
int rawRightMax = -1;
int rawRight;
int pitchNum = 128;
float noteHeight;//音符图片高度
float noteLength;//音符长度比例
int windowHeight;//窗口高度
int windowWidth;//窗口宽度
bool automaticX;//自动吸附模式(起始)
bool automaticY;//自动吸附模式(音高)
float maticBlock;//起始时间吸附到这个的整数倍
int baseTone;
bool isMajor;
int getBaseTone();//获取调性
float defaultDelay;//持续时间
int defaultVolume;//音量
stringPool::stringPtr defaultInfo;//信息
std::set<note*>::iterator scrollBuilder_it;
void scrollBuilder_process();
bool scrollBuilder_processing = false;
virtual void scrollBuilder_onGetNoteArea()=0;
virtual void scrollBuilder_onGetAllNotePos(note *)=0;
virtual void scrollBuilder_onSwap()=0;
std::map<int,std::string> captions;
void addChord(float position,
const std::string & root , const std::string & name , const char * format, float length , int root_base = 0,int v = 70,const std::string & info = "default",bool useTPQ = true);
void addChord(float position,const std::string & name, float length , int root_base = 0,int v = 70,const std::string & info = "default", const std::string & format="",bool useTPQ = true);
void addNoteWithId(float position,float tone,float dur,int v,int ins);
void parseChordNotes(std::vector<int> & notes,const std::string & name)const;
inline int getNoteId(const std::string & name)const{
auto it = note_number_map.find(name);
if(it==note_number_map.end()){
return 0;
} else {
return it->second;
}
}
inline int getChordMax(const std::string & name)const{
std::vector<int> notes;
parseChordNotes(notes,name);
int len = notes.size();
if(len<=0){
return 0;
} else {
return notes[len - 1];
}
}
int getInstrumentId(const stringPool::stringPtr & n);
void loadInstrument(int id);
inline void loadInstrument(const stringPool::stringPtr & n){
loadInstrument(getInstrumentId(n));
}
void markStrong();
private:
float noteAreaHeight;
float noteAreaWidth;
float realLookAtY;
std::unordered_map<std::string,int> instrument2Id;
void instrument2Id_init();
bool instrumentLoaded[128];
public:
struct displayBuffer_t{
float begin;
float tone;
float dur;
int volume;
stringPool::stringPtr info;
};
std::vector<displayBuffer_t> displayBuffer;
std::vector<displayBuffer_t> noteTemplate;
void undo();
void redo();
void copy();
bool pasteMode = false;
bool editStatus = false;
inline bool isEdited(){
return editStatus;
}
inline void pushHistory(std::shared_ptr<history> & ptr){
histories_undo.push_back(ptr);
histories_redo.clear();
editStatus = true;
}
private:
std::list<std::shared_ptr<history> > histories_undo;
std::list<std::shared_ptr<history> > histories_redo;
};
}
#endif