MuseScore  3.4
Music composition and notation
importmxmlpass2.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2015 Werner Schweer and others
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __IMPORTMXMLPASS2_H__
21 #define __IMPORTMXMLPASS2_H__
22 
23 #include <array>
24 
25 #include "libmscore/score.h"
26 #include "libmscore/tuplet.h"
27 #include "importxmlfirstpass.h"
28 #include "importmxmlpass1.h"
29 #include "musicxml.h" // a.o. for Slur
30 #include "musicxmlsupport.h"
31 
32 namespace Ms {
33 
34 //---------------------------------------------------------
35 // support enums / structs / classes
36 //---------------------------------------------------------
37 
38 using GraceChordList = QList<Chord*>;
39 using FiguredBassList = QVector<FiguredBass*>;
40 // typedef QList<Chord*> GraceChordList;
41 // typedef QVector<FiguredBass*> FiguredBassList;
42 using Tuplets = std::map<QString, Tuplet*>;
43 
44 //---------------------------------------------------------
45 // MxmlStartStop
46 //---------------------------------------------------------
47 /*
48 enum class MxmlStartStop : char {
49  START, STOP, NONE
50  };
51  */
52 
53 //---------------------------------------------------------
54 // MusicXmlTupletDesc
55 //---------------------------------------------------------
56 
68  };
69 
70 //---------------------------------------------------------
71 // MusicXmlSpannerDesc
72 //---------------------------------------------------------
73 
77  int _nr;
78  MusicXmlSpannerDesc(SLine* sp, ElementType tp, int nr) : _sp(sp), _tp(tp), _nr(nr) {}
79  MusicXmlSpannerDesc(ElementType tp, int nr) : _sp(0), _tp(tp), _nr(nr) {}
80  };
81 
82 //---------------------------------------------------------
83 // NewMusicXmlSpannerDesc
84 //---------------------------------------------------------
85 
87  SLine* _sp { nullptr };
88  Fraction _tick2 { 0, 0 };
89  int _track2 {};
90  bool _isStarted { false };
91  bool _isStopped { false };
93  QString toString() const;
94  };
95 
96 //---------------------------------------------------------
97 // MusicXmlLyricsExtend
98 //---------------------------------------------------------
99 
101 public:
103  void init();
104  void addLyric(Lyrics* const lyric);
105  void setExtend(const int no, const int track, const Fraction& tick);
106 
107 private:
108  QSet<Lyrics*> _lyrics;
109  };
110 
111 //---------------------------------------------------------
112 // MusicXMLParserLyric
113 //---------------------------------------------------------
114 
116 public:
117  MusicXMLParserLyric(const LyricNumberHandler lyricNumberHandler,
118  QXmlStreamReader& e, Score* score, MxmlLogger* logger);
119  QSet<Lyrics*> extendedLyrics() const { return _extendedLyrics; }
120  QMap<int, Lyrics*> numberedLyrics() const { return _numberedLyrics; }
121  void parse();
122 private:
123  void skipLogCurrElem();
125  QXmlStreamReader& _e;
126  Score* const _score; // the score
128  QMap<int, Lyrics*> _numberedLyrics; // lyrics with valid number
129  QSet<Lyrics*> _extendedLyrics; // lyrics with the extend flag set
130  };
131 
132 //---------------------------------------------------------
133 // Notation
134 //---------------------------------------------------------
135 
136 class Notation {
137 public:
138  Notation(const QString& name) { _name = name; }
139  void addAttribute(const QStringRef name, const QStringRef value);
140  QString attribute(const QString& name) const;
141  QString name() const { return _name; }
142  QString print() const;
143  void setText(const QString& text) { _text = text; }
144  QString text() const { return _text; }
145 private:
146  QString _name;
147  QString _text;
148  std::map<QString, QString> _attributes;
149  };
150 
151 //---------------------------------------------------------
152 // forward references and defines
153 //---------------------------------------------------------
154 
155 class FretDiagram;
156 class FiguredBassItem;
157 class Glissando;
158 class Pedal;
159 class Trill;
160 class MxmlLogger;
161 
162 using SlurStack = std::array<SlurDesc, MAX_NUMBER_LEVEL>;
163 using TrillStack = std::array<Trill*, MAX_NUMBER_LEVEL>;
164 using BracketsStack = std::array<MusicXmlExtendedSpannerDesc, MAX_NUMBER_LEVEL>;
165 using OttavasStack = std::array<MusicXmlExtendedSpannerDesc, MAX_NUMBER_LEVEL>;
166 using HairpinsStack = std::array<MusicXmlExtendedSpannerDesc, MAX_NUMBER_LEVEL>;
167 using SpannerStack = std::array<MusicXmlExtendedSpannerDesc, MAX_NUMBER_LEVEL>;
168 using SpannerSet = std::set<Spanner*>;
169 
170 //---------------------------------------------------------
171 // MusicXMLParserNotations
172 //---------------------------------------------------------
173 
175 public:
176  MusicXMLParserNotations(QXmlStreamReader& e, Score* score, MxmlLogger* logger);
177  void parse();
178  void addToScore(ChordRest* const cr, Note* const note, const int tick, SlurStack& slurs,
179  Glissando* glissandi[MAX_NUMBER_LEVEL][2], MusicXmlSpannerMap& spanners, TrillStack& trills,
180  Tie*& tie);
181  MusicXmlTupletDesc tupletDesc() const { return _tupletDesc; }
182  QString tremoloType() const { return _tremoloType; }
183  int tremoloNr() const { return _tremoloNr; }
184  bool mustStopGraceAFter() const { return _slurStop || _wavyLineStop; }
185 private:
186  void addTechnical(Note* note);
187  void articulations();
188  void dynamics();
189  void fermata();
190  void glissandoSlide();
191  void mordentNormalOrInverted();
192  void ornaments();
193  void slur();
194  void skipLogCurrElem();
195  void technical();
196  void tied();
197  void tuplet();
198  QXmlStreamReader& _e;
199  Score* const _score; // the score
200  MxmlLogger* _logger; // the error logger
202  QString _tiedType;
204  QString _tiedLineType;
206  QStringList _dynamicsList;
207  std::vector<SymId> _articulationSymbols;
208  SymId _breath { SymId::noSym };
209  std::vector<Notation> _notations;
210  QString _tremoloType;
211  int _tremoloNr { 0 };
212  QString _wavyLineType;
213  int _wavyLineNo { 0 };
214  QString _chordLineType;
215  QString _fermataType;
216  SymId _fermataSymbol { SymId::noSym };
218  QString _technicalFret;
222  QString _arpeggioType;
223  bool _slurStop { false };
224  bool _wavyLineStop { false };
225  };
226 
227 //---------------------------------------------------------
228 // MusicXMLParserPass2
229 //---------------------------------------------------------
230 
232 public:
233  MusicXMLParserPass2(Score* score, MusicXMLParserPass1& pass1, MxmlLogger* logger);
234  Score::FileError parse(QIODevice* device);
235 
236  // part specific data interface functions
237  void addSpanner(const MusicXmlSpannerDesc& desc);
238  MusicXmlExtendedSpannerDesc& getSpanner(const MusicXmlSpannerDesc& desc);
239  void clearSpanner(const MusicXmlSpannerDesc& desc);
240 
241 private:
242  void initPartState(const QString& partId);
243  SpannerSet findIncompleteSpannersAtPartEnd();
244  Score::FileError parse();
245  void scorePartwise();
246  void partList();
247  void scorePart();
248  void part();
249  void measChordNote( /*, const MxmlPhase2Note note, ChordRest& currChord */);
250  void measChordFlush( /*, ChordRest& currChord */);
251  void measure(const QString& partId, const Fraction time);
252  void attributes(const QString& partId, Measure* measure, const Fraction& tick);
253  void measureStyle(Measure* measure);
254  void print(Measure* measure);
255  void barline(const QString& partId, Measure* measure, const Fraction& tick);
256  void key(const QString& partId, Measure* measure, const Fraction& tick);
257  void clef(const QString& partId, Measure* measure, const Fraction& tick);
258  void time(const QString& partId, Measure* measure, const Fraction& tick);
259  void divisions();
260  void transpose(const QString& partId);
261  Note* note(const QString& partId, Measure* measure, const Fraction sTime, const Fraction prevTime,
262  Fraction& missingPrev, Fraction& dura, Fraction& missingCurr, QString& currentVoice, GraceChordList& gcl, int& gac,
263  Beam*& beam, FiguredBassList& fbl, int& alt, MxmlTupletStates& tupletStates, Tuplets& tuplets);
264  void notePrintSpacingNo(Fraction& dura);
265  FiguredBassItem* figure(const int idx, const bool paren);
266  FiguredBass* figuredBass();
267  FretDiagram* frame();
268  void harmony(const QString& partId, Measure* measure, const Fraction sTime);
269  Accidental* accidental();
270  void beam(Beam::Mode& beamMode);
271  void duration(Fraction& dura);
272  void forward(Fraction& dura);
273  void backup(Fraction& dura);
274  void timeModification(Fraction& timeMod, TDuration& normalType);
275  void stem(Direction& sd, bool& nost);
276  void doEnding(const QString& partId, Measure* measure, const QString& number, const QString& type, const QString& text);
277  void staffDetails(const QString& partId);
278  void staffTuning(StringData* t);
279  void skipLogCurrElem();
280 
281  // multi-measure rest state handling
282  void setMultiMeasureRestCount(int count);
283  int getAndDecMultiMeasureRestCount();
284 
285  // generic pass 2 data
286 
287  QXmlStreamReader _e;
288  int _divs; // the current divisions value
289  Score* const _score; // the score
290  MusicXMLParserPass1& _pass1; // the pass1 results
292 
293  // part specific data (TODO: move to part-specific class)
294 
295  // Measure duration according to last timesig read
296  // TODO: store timesigs read in pass 1, use those instead
297  // or use score->sigmap() ?
299 
300  SlurStack _slurs { {} };
301  TrillStack _trills { {} };
306 
307  Glissando* _glissandi[MAX_NUMBER_LEVEL][2];
308 
311  bool _hasDrumset;
312 
314 
322  };
323 
324 //---------------------------------------------------------
325 // MusicXMLParserDirection
326 //---------------------------------------------------------
327 
329 public:
330  MusicXMLParserDirection(QXmlStreamReader& e, Score* score, const MusicXMLParserPass1& pass1, MusicXMLParserPass2& pass2, MxmlLogger* logger);
331  void direction(const QString& partId, Measure* measure, const Fraction& tick, const int divisions, MusicXmlSpannerMap& spanners);
332 
333 private:
334  QXmlStreamReader& _e;
335  Score* const _score; // the score
336  const MusicXMLParserPass1& _pass1; // the pass1 results
337  MusicXMLParserPass2& _pass2; // the pass2 results
339 
340  QStringList _dynamicsList;
341  QString _enclosure;
342  QString _wordsText;
343  QString _metroText;
344  QString _rehearsalText;
345  QString _dynaVelocity;
346  QString _tempo;
347  QString _sndCapo;
348  QString _sndCoda;
349  QString _sndDacapo;
350  QString _sndDalsegno;
351  QString _sndSegno;
352  QString _sndFine;
354  qreal _defaultY;
355  bool _coda;
356  bool _segno;
357  double _tpoMetro; // tempo according to metronome
358  double _tpoSound; // tempo according to sound
359  QList<Element*> _elems;
361 
362  void directionType(QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
363  void bracket(const QString& type, const int number, QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
364  void octaveShift(const QString& type, const int number, QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
365  void pedal(const QString& type, const int number, QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
366  void dashes(const QString& type, const int number, QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
367  void wedge(const QString& type, const int number, QList<MusicXmlSpannerDesc>& starts, QList<MusicXmlSpannerDesc>& stops);
368  QString metronome(double& r);
369  void sound();
370  void dynamics();
371  void handleRepeats(Measure* measure, const int track);
372  void skipLogCurrElem();
373  };
374 
375 } // namespace Ms
376 #endif
QString _enclosure
Definition: importmxmlpass2.h:341
QString _sndFine
Definition: importmxmlpass2.h:352
Definition: durationtype.h:28
FiguredBass * _figBass
Current figured bass element (to attach to next note)
Definition: importmxmlpass2.h:319
MusicXmlTupletDesc _tupletDesc
Definition: importmxmlpass2.h:201
Definition: beam.h:37
Definition: importmxmlpass2.h:174
Definition of class MusicXML.
Describe the information extracted from a single note/notations/tuplet element.
Definition: importmxmlpass2.h:62
Tie * _tie
Definition: importmxmlpass2.h:309
QString _technicalFret
Definition: importmxmlpass2.h:218
Fretboard diagram.
Definition: fret.h:122
MusicXmlExtendedSpannerDesc _pedal
Current pedal.
Definition: importmxmlpass2.h:315
MusicXMLParserPass2 & _pass2
Definition: importmxmlpass2.h:337
std::set< Spanner * > SpannerSet
Definition: importmxmlpass2.h:168
QString _tiedLineType
Definition: importmxmlpass2.h:204
QSet< Lyrics * > _lyrics
Definition: importmxmlpass2.h:108
MxmlStartStop
Definition: importmxmlpass1.h:67
Definition: volta.h:48
Definition of Score class.
void setText(const QString &text)
Definition: importmxmlpass2.h:143
std::array< SlurDesc, MAX_NUMBER_LEVEL > SlurStack
Definition: importmxmlpass2.h:162
Definition: importmxmlpass2.h:115
one measure in a system
Definition: measure.h:65
QString _tempo
Definition: importmxmlpass2.h:346
QString _dynaVelocity
Definition: importmxmlpass2.h:345
TupletNumberType
Definition: types.h:500
QString _chordLineType
Definition: importmxmlpass2.h:214
QString _sndCoda
Definition: importmxmlpass2.h:348
Score *const _score
Definition: importmxmlpass2.h:199
SymId
Definition: sym.h:30
MxmlStartStop type
Definition: importmxmlpass2.h:64
std::array< MusicXmlExtendedSpannerDesc, MAX_NUMBER_LEVEL > BracketsStack
Definition: importmxmlpass2.h:164
Definition: importmxmllogger.h:20
std::map< QString, QString > _attributes
Definition: importmxmlpass2.h:148
bool mustStopGraceAFter() const
Definition: importmxmlpass2.h:184
QString _tremoloType
Definition: importmxmlpass2.h:210
Definition: importmxmlpass2.h:231
const LyricNumberHandler _lyricNumberHandler
Definition: importmxmlpass2.h:124
const MusicXMLParserPass1 & _pass1
Definition: importmxmlpass2.h:336
const int MAX_NUMBER_LEVEL
Definition: musicxml.h:50
A complete figured bass indication.
Definition: figuredbass.h:232
const char * toString(Direction val)
Definition: mscore.cpp:176
MusicXmlLyricsExtend()
Definition: importmxmlpass2.h:102
QMap< int, Lyrics * > _numberedLyrics
Definition: importmxmlpass2.h:128
QString _wavyLineType
Definition: importmxmlpass2.h:212
QStringList _dynamicsList
Definition: importmxmlpass2.h:206
Definition: accidental.h:65
bool _hasDefaultY
Definition: importmxmlpass2.h:353
TupletBracketType
Definition: types.h:501
Pedal * _pedalContinue
Current pedal type="change" requiring fixup.
Definition: importmxmlpass2.h:316
Definition: trill.h:62
Definition: score.h:391
Definition: stringdata.h:35
double _tpoSound
Definition: importmxmlpass2.h:358
int tremoloNr() const
Definition: importmxmlpass2.h:183
Definition: figuredbass.h:81
std::map< QString, MxmlTupletState > MxmlTupletStates
Definition: importmxmlpass1.h:99
std::array< Trill *, MAX_NUMBER_LEVEL > TrillStack
Definition: importmxmlpass2.h:163
QList< Chord * > GraceChordList
Definition: importmxmlpass2.h:38
Placement placement
Definition: importmxmlpass2.h:65
QString _sndDacapo
Definition: importmxmlpass2.h:349
Score *const _score
Definition: importmxmlpass2.h:289
MxmlLogger * _logger
Error logger.
Definition: importmxmlpass2.h:338
Placement
Definition: types.h:312
std::array< MusicXmlExtendedSpannerDesc, MAX_NUMBER_LEVEL > SpannerStack
Definition: importmxmlpass2.h:167
QString _rehearsalText
Definition: importmxmlpass2.h:344
SLine * _sp
Definition: importmxmlpass2.h:75
OttavasStack _ottavas
Current ottavas.
Definition: importmxmlpass2.h:303
std::vector< SymId > _articulationSymbols
Definition: importmxmlpass2.h:207
TupletBracketType bracket
Definition: importmxmlpass2.h:66
MxmlLogger * _logger
Error logger.
Definition: importmxmlpass2.h:291
MusicXmlLyricsExtend _extendedLyrics
Lyrics with "extend" requiring fixup.
Definition: importmxmlpass2.h:321
int _nr
Definition: importmxmlpass2.h:77
MusicXmlTupletDesc tupletDesc() const
Definition: importmxmlpass2.h:181
Definition: glissando.h:49
Fraction _offset
Definition: importmxmlpass2.h:360
virtual base class for Hairpin, Trill and TextLine
Definition: line.h:70
Definition: importmxmlpass1.h:115
QXmlStreamReader _e
Definition: importmxmlpass2.h:287
QString _name
Definition: importmxmlpass2.h:146
std::map< QString, Tuplet * > Tuplets
Definition: importmxmlpass2.h:42
MusicXmlExtendedSpannerDesc _dummyNewMusicXmlSpannerDesc
Definition: importmxmlpass2.h:305
QMap< SLine *, QPair< int, int > > MusicXmlSpannerMap
Definition: musicxml.h:126
QSet< Lyrics * > extendedLyrics() const
Definition: importmxmlpass2.h:119
QString _text
Definition: importmxmlpass2.h:147
Volta * _lastVolta
Definition: importmxmlpass2.h:310
Harmony * _harmony
Current harmony.
Definition: importmxmlpass2.h:317
FileError
Definition: score.h:395
Definition: importmxmlpass2.h:74
QString _sndSegno
Definition: importmxmlpass2.h:351
Mode
Definition: beam.h:73
QString _arpeggioType
Definition: importmxmlpass2.h:222
QVector< FiguredBass * > FiguredBassList
Definition: importmxmlpass2.h:39
MusicXmlSpannerMap _spanners
Definition: importmxmlpass2.h:313
Definition: aeolus.cpp:26
QString _sndCapo
Definition: importmxmlpass2.h:347
MxmlLogger * _logger
Definition: importmxmlpass2.h:200
MxmlLogger * _logger
Error logger.
Definition: importmxmlpass2.h:127
Definition: importmxmlpass2.h:100
double _tpoMetro
Definition: importmxmlpass2.h:357
QString _sndDalsegno
Definition: importmxmlpass2.h:350
QXmlStreamReader & _e
Definition: importmxmlpass2.h:334
QString _technicalFingering
Definition: importmxmlpass2.h:217
QList< Element * > _elems
Definition: importmxmlpass2.h:359
BracketsStack _brackets
Definition: importmxmlpass2.h:302
Fraction _timeSigDura
Definition: importmxmlpass2.h:298
Definition: importmxmlpass2.h:328
Definition: importmxmlpass2.h:86
TupletNumberType shownumber
Definition: importmxmlpass2.h:67
a Tie has a Note as startElement/endElement
Definition: tie.h:60
Graphic representation of a chord.
Definition: chord.h:55
QString name() const
Definition: importmxmlpass2.h:141
QString tremoloType() const
Definition: importmxmlpass2.h:182
QXmlStreamReader & _e
Definition: importmxmlpass2.h:198
Definition: harmony.h:72
Chord * _tremStart
Starting chord for current tremolo.
Definition: importmxmlpass2.h:318
std::vector< Notation > _notations
Definition: importmxmlpass2.h:209
Definition: chordrest.h:48
Direction
Definition: types.h:282
QStringList _dynamicsList
Definition: importmxmlpass2.h:340
MusicXmlSpannerDesc(SLine *sp, ElementType tp, int nr)
Definition: importmxmlpass2.h:78
Definition: pedal.h:44
QXmlStreamReader & _e
Definition: importmxmlpass2.h:125
ElementType _tp
Definition: importmxmlpass2.h:76
QString _metroText
Definition: importmxmlpass2.h:343
QString _dynamicsPlacement
Definition: importmxmlpass2.h:205
QString text() const
Definition: importmxmlpass2.h:144
qreal _defaultY
Definition: importmxmlpass2.h:354
Graphic representation of a note.
Definition: note.h:212
QString _tiedType
Definition: importmxmlpass2.h:202
QString _technicalString
Definition: importmxmlpass2.h:220
Definition: fraction.h:46
QString _technicalPluck
Definition: importmxmlpass2.h:219
Score *const _score
Definition: importmxmlpass2.h:335
ElementType
Definition: types.h:34
MusicXmlTupletDesc()
Definition: importmxmlpass2.cpp:93
Notation(const QString &name)
Definition: importmxmlpass2.h:138
MusicXmlExtendedSpannerDesc()
Definition: importmxmlpass2.h:92
QString _fermataType
Definition: importmxmlpass2.h:215
bool _coda
Definition: importmxmlpass2.h:355
std::array< MusicXmlExtendedSpannerDesc, MAX_NUMBER_LEVEL > OttavasStack
Definition: importmxmlpass2.h:165
QString _strongAccentType
Definition: importmxmlpass2.h:221
Score *const _score
Definition: importmxmlpass2.h:126
Definition: lyrics.h:27
MusicXmlSpannerDesc(ElementType tp, int nr)
Definition: importmxmlpass2.h:79
MusicXMLParserPass1 & _pass1
Definition: importmxmlpass2.h:290
HairpinsStack _hairpins
Current hairpins.
Definition: importmxmlpass2.h:304
bool _hasDrumset
drumset defined TODO: move to pass 1
Definition: importmxmlpass2.h:311
int _multiMeasureRestCount
Definition: importmxmlpass2.h:320
std::array< MusicXmlExtendedSpannerDesc, MAX_NUMBER_LEVEL > HairpinsStack
Definition: importmxmlpass2.h:166
Definition: importxmlfirstpass.h:38
bool _segno
Definition: importmxmlpass2.h:356
Definition: importmxmlpass2.h:136
int _divs
Definition: importmxmlpass2.h:288
QSet< Lyrics * > _extendedLyrics
Definition: importmxmlpass2.h:129
QMap< int, Lyrics * > numberedLyrics() const
Definition: importmxmlpass2.h:120
QString _tiedOrientation
Definition: importmxmlpass2.h:203
QString _wordsText
Definition: importmxmlpass2.h:342