forked from hselasky/midipp
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmidipp_element.h
262 lines (238 loc) · 5.73 KB
/
midipp_element.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*-
* Copyright (c) 2013-2019 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef _MIDIPP_ELEMENT_H_
#define _MIDIPP_ELEMENT_H_
#include "midipp.h"
class MppElement;
typedef struct
#define struct
TAILQ_ENTRY(MppElement) MppElementEntryT;
#undef struct
typedef struct
#define struct
TAILQ_HEAD(MppElementHead, MppElement) MppElementHeadT;
#undef struct
enum MppElementType {
MPP_T_CHANNEL,
MPP_T_COMMAND,
MPP_T_DURATION,
MPP_T_JUMP,
MPP_T_LABEL,
MPP_T_MACRO,
MPP_T_NEWLINE,
MPP_T_SCORE_SUBDIV,
MPP_T_SPACE,
MPP_T_STRING_CMD,
MPP_T_STRING_DESC,
MPP_T_STRING_DOT,
MPP_T_STRING_CHORD,
MPP_T_TRANSPOSE,
MPP_T_TIMER,
MPP_T_UNKNOWN,
MPP_T_MAX,
};
enum MppCommandType {
MPP_CMD_NOP,
MPP_CMD_LOCK,
MPP_CMD_UNLOCK,
MPP_CMD_BPM_REF,
MPP_CMD_AUTO_MELODY,
MPP_CMD_MICRO_TUNE,
MPP_CMD_KEY_MODE,
MPP_CMD_IMAGE_PROPS,
MPP_CMD_IMAGE_BG_COLOR,
MPP_CMD_IMAGE_FG_COLOR,
MPP_CMD_TEXT_PROPS,
MPP_CMD_TEXT_BG_COLOR,
MPP_CMD_TEXT_FG_COLOR,
MPP_CMD_MAX,
};
#define MPP_FLAG_JUMP_PAGE 1
#define MPP_FLAG_JUMP_REL 2
#define MPP_FLAG_JUMP_DIGIT 4
struct MppChordElement {
MppElement *chord;
MppElement *start;
MppElement *stop;
int stats[MPP_MAX_BANDS];
int key_max;
int key_base;
};
class MppColorProps {
public:
bool operator!= (const MppColorProps &other) const
{
return (other.fg_red != fg_red ||
other.fg_green != fg_green ||
other.fg_blue != fg_blue ||
other.bg_red != bg_red ||
other.bg_green != bg_green ||
other.bg_blue != bg_blue);
};
bool operator== (const MppColorProps &other) const
{
return ((*this != other) == 0);
};
void reset()
{
/* foreground */
fg_red = 255;
fg_green = 255;
fg_blue = 255;
/* background */
bg_red = 0;
bg_green = 0;
bg_blue = 0;
};
QColor fg()
{
return (QColor(fg_red, fg_green, fg_blue));
}
void setFg(const QColor color)
{
fg_red = color.red();
fg_green = color.green();
fg_blue = color.blue();
}
QColor bg()
{
return (QColor(bg_red, bg_green, bg_blue));
}
void setBg(const QColor color)
{
bg_red = color.red();
bg_green = color.green();
bg_blue = color.blue();
}
uint8_t fg_red;
uint8_t fg_green;
uint8_t fg_blue;
uint8_t bg_red;
uint8_t bg_green;
uint8_t bg_blue;
};
class MppObjectProps {
public:
bool operator!= (const MppObjectProps &other) const
{
return (other.align != align || other.space != space ||
other.shadow != shadow || other.color != color ||
other.num != num || other.how != how);
};
bool operator== (const MppObjectProps &other) const
{
return ((*this != other) == 0);
}
void reset()
{
align = 0;
space = 5;
shadow = 105;
color.reset();
};
uint16_t align;
uint16_t space;
uint16_t shadow;
uint16_t num;
uint16_t how;
MppColorProps color;
};
class MppElement {
public:
MppElement(MppElementType type, int, int = 0, int = 0, int = 0, int = 0);
~MppElement();
int compare(const MppElement *) const;
MppElement * next() const;
QChar getChar(int *) const;
int getIntValue(int *) const;
QString txt;
MppElementEntryT entry;
enum MppElementType type;
int value[4];
int line;
int sequence;
};
class MppHead {
public:
MppElementHeadT head;
QChar last;
struct {
int command;
int comment;
int did_jump;
int key_lock;
int level;
int line;
int offset;
int string;
MppObjectProps text_curr;
MppObjectProps image_curr;
MppElement *push_start;
MppElement *push_stop;
MppElement *curr_start;
MppElement *curr_stop;
MppElement *last_start;
MppElement *last_stop;
MppElement *elem;
MppElement *label_start[MPP_MAX_LABELS];
} state;
MppHead();
~MppHead();
void replace(MppHead *, MppElement *, MppElement *);
int getChord(int, MppChordElement *);
void reset();
void clear();
void sortScore();
void optimise();
void bassOffset(int);
void transposeScore(int, int = 0);
void limitScore(int);
void tuneScore();
void scaleTime(int);
void alignTime(int);
void dotReorder();
int getPlaytime();
void flush();
QString toPlain(int = -1);
QString toLyrics(int no_chords = 0);
int foreachLine(MppElement **, MppElement **);
int getMaxLines();
int isFirst();
void syncLast();
void pushLine();
void popLine();
void stepLine(MppElement **, MppElement **);
void currLine(MppElement **, MppElement **);
void jumpLabel(int);
void jumpPointer(MppElement *);
void sequence();
int getCurrLine();
void operator += (QChar);
void operator += (const QString &);
void operator += (MppElement *);
};
extern QString MppDeQuoteChord(QString &);
extern QString MppDeQuoteString(QString &);
#endif /* _MIDIPP_ELEMENT_H_ */