/
importmxmlpass2.h
357 lines (312 loc) · 13.5 KB
/
importmxmlpass2.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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
//=============================================================================
// MuseScore
// Linux Music Score Editor
//
// Copyright (C) 2015 Werner Schweer and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#ifndef __IMPORTMXMLPASS2_H__
#define __IMPORTMXMLPASS2_H__
#include <array>
#include "libmscore/score.h"
#include "libmscore/tuplet.h"
#include "importxmlfirstpass.h"
#include "importmxmlpass1.h"
#include "musicxml.h" // a.o. for Slur
#include "musicxmlsupport.h"
namespace Ms {
//---------------------------------------------------------
// support enums / structs / classes
//---------------------------------------------------------
typedef QList<Chord*> GraceChordList;
typedef QVector<FiguredBass*> FiguredBassList;
//---------------------------------------------------------
// MxmlStartStop
//---------------------------------------------------------
enum class MxmlStartStop : char {
START, STOP, NONE
};
//---------------------------------------------------------
// MusicXmlTupletDesc
//---------------------------------------------------------
/**
Describe the information extracted from
a single note/notations/tuplet element.
*/
struct MusicXmlTupletDesc {
MusicXmlTupletDesc();
MxmlStartStop type;
Placement placement;
TupletBracketType bracket;
TupletNumberType shownumber;
};
//---------------------------------------------------------
// MusicXmlSpannerDesc
//---------------------------------------------------------
struct MusicXmlSpannerDesc {
SLine* sp;
ElementType tp;
int nr;
MusicXmlSpannerDesc(SLine* _sp, ElementType _tp, int _nr) : sp(_sp), tp(_tp), nr(_nr) {}
MusicXmlSpannerDesc(ElementType _tp, int _nr) : sp(0), tp(_tp), nr(_nr) {}
};
//---------------------------------------------------------
// MusicXmlLyricsExtend
//---------------------------------------------------------
class MusicXmlLyricsExtend {
public:
MusicXmlLyricsExtend() {}
void init();
void addLyric(Lyrics* const lyric);
void setExtend(const int no, const int track, const int tick);
private:
QSet<Lyrics*> _lyrics;
};
//---------------------------------------------------------
// MusicXMLParserLyric
//---------------------------------------------------------
class MusicXMLParserLyric {
public:
MusicXMLParserLyric(const LyricNumberHandler lyricNumberHandler,
QXmlStreamReader& e, Score* score, MxmlLogger* logger);
QSet<Lyrics*> extendedLyrics() const { return _extendedLyrics; }
QMap<int, Lyrics*> numberedLyrics() const { return _numberedLyrics; }
void parse();
private:
void skipLogCurrElem();
const LyricNumberHandler _lyricNumberHandler;
QXmlStreamReader& _e;
Score* const _score; // the score
MxmlLogger* _logger; ///< Error logger
QMap<int, Lyrics*> _numberedLyrics; // lyrics with valid number
QSet<Lyrics*> _extendedLyrics; // lyrics with the extend flag set
};
//---------------------------------------------------------
// Notation
//---------------------------------------------------------
class Notation {
public:
Notation(const QString& name) { _name = name; }
void addAttribute(const QStringRef name, const QStringRef value);
QString attribute(const QString& name) const;
QString name() const { return _name; }
QString print() const;
void setText(const QString& text) { _text = text; }
QString text() const { return _text; }
private:
QString _name;
QString _text;
std::map<QString, QString> _attributes;
};
//---------------------------------------------------------
// forward references and defines
//---------------------------------------------------------
class FretDiagram;
class FiguredBassItem;
class Glissando;
class Pedal;
class Trill;
class MxmlLogger;
using SlurStack = std::array<SlurDesc, MAX_NUMBER_LEVEL>;
using TrillStack = std::array<Trill*, MAX_NUMBER_LEVEL>;
using BracketsStack = std::array<SLine*, MAX_BRACKETS>;
using DashesStack = std::array<SLine*, MAX_DASHES>;
using OttavasStack = std::array<SLine*, MAX_NUMBER_LEVEL>;
using HairpinsStack = std::array<SLine*, MAX_NUMBER_LEVEL>;
//---------------------------------------------------------
// MusicXMLParserNotations
//---------------------------------------------------------
class MusicXMLParserNotations {
public:
MusicXMLParserNotations(QXmlStreamReader& e, Score* score, MxmlLogger* logger);
void parse();
void addToScore(ChordRest* const cr, Note* const note, const int tick, SlurStack& slurs,
Glissando* glissandi[MAX_NUMBER_LEVEL][2], MusicXmlSpannerMap& spanners, TrillStack& trills,
Tie*& tie);
MusicXmlTupletDesc tupletDesc() const { return _tupletDesc; }
QString tremoloType() const { return _tremoloType; }
int tremoloNr() const { return _tremoloNr; }
bool mustStopGraceAFter() const { return _slurStop || _wavyLineStop; }
private:
void addTechnical(Note* note);
void articulations();
void dynamics();
void fermata();
void glissandoSlide();
void mordentNormalOrInverted();
void ornaments();
void slur();
void skipLogCurrElem();
void technical();
void tied();
void tuplet();
QXmlStreamReader& _e;
Score* const _score; // the score
MxmlLogger* _logger; // the error logger
MusicXmlTupletDesc _tupletDesc;
QString _tiedType;
QString _tiedOrientation;
QString _tiedLineType;
QString _dynamicsPlacement;
QStringList _dynamicsList;
std::vector<SymId> _articulationSymbols;
SymId _breath { SymId::noSym };
std::vector<Notation> _notations;
QString _tremoloType;
int _tremoloNr { 0 };
QString _wavyLineType;
int _wavyLineNo { 0 };
QString _chordLineType;
QString _fermataType;
SymId _fermataSymbol { SymId::noSym };
QString _technicalFingering;
QString _technicalFret;
QString _technicalPluck;
QString _technicalString;
QString _strongAccentType;
QString _arpeggioType;
bool _slurStop { false };
bool _wavyLineStop { false };
};
//---------------------------------------------------------
// MusicXMLParserPass2
//---------------------------------------------------------
class MusicXMLParserPass2 {
public:
MusicXMLParserPass2(Score* score, MusicXMLParserPass1& pass1, MxmlLogger* logger);
Score::FileError parse(QIODevice* device);
// part specific data interface functions
void addSpanner(const MusicXmlSpannerDesc& desc);
SLine* getSpanner(const MusicXmlSpannerDesc& desc);
void clearSpanner(const MusicXmlSpannerDesc& desc);
private:
void initPartState(const QString& partId);
Score::FileError parse();
void scorePartwise();
void partList();
void scorePart();
void part();
void measChordNote( /*, const MxmlPhase2Note note, ChordRest& currChord */);
void measChordFlush( /*, ChordRest& currChord */);
void measure(const QString& partId, const Fraction time);
void attributes(const QString& partId, Measure* measure, const int tick);
void measureStyle(Measure* measure);
void print(Measure* measure);
void barline(const QString& partId, Measure* measure);
void key(const QString& partId, Measure* measure, const int tick);
void clef(const QString& partId, Measure* measure, const int tick);
void time(const QString& partId, Measure* measure, const int tick);
void divisions();
void transpose(const QString& partId);
Note* note(const QString& partId, Measure* measure, const Fraction sTime, const Fraction prevTime,
Fraction& dura, QString& currentVoice, GraceChordList& gcl, int& gac,
Beam*& beam, FiguredBassList& fbl, int& alt);
void notePrintSpacingNo(Fraction& dura);
FiguredBassItem* figure(const int idx, const bool paren);
FiguredBass* figuredBass();
FretDiagram* frame();
void harmony(const QString& partId, Measure* measure, const Fraction sTime);
Accidental* accidental();
void beam(Beam::Mode& beamMode);
void duration(Fraction& dura);
void forward(Fraction& dura);
void backup(Fraction& dura);
void timeModification(Fraction& timeMod, TDuration& normalType);
void stem(Direction& sd, bool& nost);
void doEnding(const QString& partId, Measure* measure, const QString& number, const QString& type, const QString& text);
void staffDetails(const QString& partId);
void staffTuning(StringData* t);
void skipLogCurrElem();
// multi-measure rest state handling
void setMultiMeasureRestCount(int count);
int getAndDecMultiMeasureRestCount();
// generic pass 2 data
QXmlStreamReader _e;
int _divs; // the current divisions value
Score* const _score; // the score
MusicXMLParserPass1& _pass1; // the pass1 results
MxmlLogger* _logger; ///< Error logger
// part specific data (TODO: move to part-specific class)
// Measure duration according to last timesig read
// TODO: store timesigs read in pass 1, use those instead
// or use score->sigmap() ?
Fraction _timeSigDura;
QVector<Tuplet*> _tuplets; ///< Current tuplet for each track in the current part
QVector<bool> _tuplImpls; ///< Current tuplet implicit flag for each track in the current part
SlurStack _slurs { {} };
TrillStack _trills { {} }; ///< Current trills
BracketsStack _brackets { {} };
DashesStack _dashes { {} };
OttavasStack _ottavas { {} }; ///< Current ottavas
HairpinsStack _hairpins { {} }; ///< Current hairpins
Glissando* _glissandi[MAX_NUMBER_LEVEL][2]; ///< Current slides ([0]) / glissandi ([1])
Tie* _tie;
Volta* _lastVolta;
bool _hasDrumset; ///< drumset defined TODO: move to pass 1
MusicXmlSpannerMap _spanners;
SLine* _pedal; ///< Current pedal
Pedal* _pedalContinue; ///< Current pedal type="change" requiring fixup
Harmony* _harmony; ///< Current harmony
Chord* _tremStart; ///< Starting chord for current tremolo
FiguredBass* _figBass; ///< Current figured bass element (to attach to next note)
int _multiMeasureRestCount;
MusicXmlLyricsExtend _extendedLyrics; ///< Lyrics with "extend" requiring fixup
};
//---------------------------------------------------------
// MusicXMLParserDirection
//---------------------------------------------------------
class MusicXMLParserDirection {
public:
MusicXMLParserDirection(QXmlStreamReader& e, Score* score, const MusicXMLParserPass1& pass1, MusicXMLParserPass2& pass2, MxmlLogger* logger);
void direction(const QString& partId, Measure* measure, const int tick, MusicXmlSpannerMap& spanners);
private:
QXmlStreamReader& _e;
Score* const _score; // the score
const MusicXMLParserPass1& _pass1; // the pass1 results
MusicXMLParserPass2& _pass2; // the pass2 results
MxmlLogger* _logger; ///< Error logger
QStringList _dynamicsList;
QString _enclosure;
QString _wordsText;
QString _metroText;
QString _rehearsalText;
QString _dynaVelocity;
QString _tempo;
QString _sndCapo;
QString _sndCoda;
QString _sndDacapo;
QString _sndDalsegno;
QString _sndSegno;
QString _sndFine;
bool _hasDefaultY;
qreal _defaultY;
bool _coda;
bool _segno;
double _tpoMetro; // tempo according to metronome
double _tpoSound; // tempo according to sound
QList<Element*> _elems;
void directionType(QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
void bracket(const QString& type, const int number, QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
void octaveShift(const QString& type, const int number, QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
void pedal(const QString& type, const int number, QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
void dashes(const QString& type, const int number, QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
void wedge(const QString& type, const int number, QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
QString metronome(double& r);
void sound();
void dynamics();
void handleRepeats(Measure* measure, const int track);
void skipLogCurrElem();
};
} // namespace Ms
#endif