MuseScore  3.4
Music composition and notation
importmxmlpass1.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 __IMPORTMXMLPASS1_H__
21 #define __IMPORTMXMLPASS1_H__
22 
23 #include "libmscore/score.h"
24 #include "importxmlfirstpass.h"
25 #include "musicxml.h" // for the creditwords and MusicXmlPartGroupList definitions
26 #include "musicxmlsupport.h"
27 
28 namespace Ms {
29 
30 //---------------------------------------------------------
31 // PageFormat
32 //---------------------------------------------------------
33 
34 struct PageFormat {
35  QSizeF size;
36  qreal printableWidth; // _width - left margin - right margin
37  qreal evenLeftMargin; // values in inch
41  qreal oddTopMargin;
43  bool twosided;
44  };
45 
46 typedef QMap<QString, Part*> PartMap;
47 typedef std::map<int,MusicXmlPartGroup*> MusicXmlPartGroupMap;
48 
49 //---------------------------------------------------------
50 // MxmlOctaveShiftDesc
51 //---------------------------------------------------------
52 
54  enum class Type : char { UP, DOWN, STOP, NONE };
56  short size;
58  short num;
59  MxmlOctaveShiftDesc() : tp(Type::NONE), size(0), num(-1) {}
60  MxmlOctaveShiftDesc(Type _tp, short _size, Fraction _tm) : tp(_tp), size(_size), time(_tm), num(-1) {}
61  };
62 
63 //---------------------------------------------------------
64 // MxmlStartStop (also used in pass 2)
65 //---------------------------------------------------------
66 
67 enum class MxmlStartStop : char {
68  NONE, START, STOP
69  };
70 
71 enum class MxmlTupletFlag : char {
72  NONE = 0,
73  STOP_PREVIOUS = 1,
74  START_NEW = 2,
75  ADD_CHORD = 4,
76  STOP_CURRENT = 8
77  };
78 
79 typedef QFlags<MxmlTupletFlag> MxmlTupletFlags;
80 
82  void addDurationToTuplet(const Fraction duration, const Fraction timeMod);
83  MxmlTupletFlags determineTupletAction(const Fraction noteDuration,
84  const Fraction timeMod,
85  const MxmlStartStop tupletStartStop,
86  const TDuration normalType,
87  Fraction& missingPreviousDuration,
88  Fraction& missingCurrentDuration
89  );
90  bool m_inTuplet { false };
91  bool m_implicit { false };
92  int m_actualNotes { 1 };
93  int m_normalNotes { 1 };
94  Fraction m_duration { 0, 1 };
95  int m_tupletType { 0 }; // smallest note type in the tuplet // TODO_NOW rename ?
96  int m_tupletCount { 0 }; // number of smallest notes in the tuplet // TODO_NOW rename ?
97  };
98 
99 using MxmlTupletStates = std::map<QString, MxmlTupletState>;
100 
101 //---------------------------------------------------------
102 // declarations
103 //---------------------------------------------------------
104 
105 void determineTupletFractionAndFullDuration(const Fraction duration, Fraction& fraction, Fraction& fullDuration);
106 Fraction missingTupletDuration(const Fraction duration);
107 
108 
109 //---------------------------------------------------------
110 // MusicXMLParserPass1
111 //---------------------------------------------------------
112 
113 class MxmlLogger;
114 
116 public:
117  MusicXMLParserPass1(Score* score, MxmlLogger* logger);
118  void initPartState(const QString& partId);
119  Score::FileError parse(QIODevice* device);
120  Score::FileError parse();
121  void scorePartwise();
122  void identification();
123  void credit(CreditWordsList& credits);
124  void defaults(int& pageWidth, int& pageHeight);
125  void pageLayout(PageFormat& pf, const qreal conversion, int& pageWidth, int& pageHeight);
126  void partList(MusicXmlPartGroupList& partGroupList);
127  void partGroup(const int scoreParts, MusicXmlPartGroupList& partGroupList, MusicXmlPartGroupMap& partGroups);
128  void scorePart();
129  void scoreInstrument(const QString& partId);
130  void midiInstrument(const QString& partId);
131  void part();
132  void measure(const QString& partId, const Fraction cTime, Fraction& mdur, VoiceOverlapDetector& vod);
133  void attributes(const QString& partId, const Fraction cTime);
134  void clef(const QString& partId);
135  void time(const Fraction cTime);
136  void divisions();
137  void staves(const QString& partId);
138  void direction(const QString& partId, const Fraction cTime);
139  void directionType(const Fraction cTime, QList<MxmlOctaveShiftDesc>& starts, QList<MxmlOctaveShiftDesc>& stops);
140  void handleOctaveShift(const Fraction cTime, const QString& type, short size, MxmlOctaveShiftDesc& desc);
141  void notations(MxmlStartStop& tupletStartStop);
142  void note(const QString& partId, const Fraction cTime, Fraction& missingPrev, Fraction& dura, Fraction& missingCurr, VoiceOverlapDetector& vod, MxmlTupletStates& tupletStates);
143  void notePrintSpacingNo(Fraction& dura);
144  void duration(Fraction& dura);
145  void forward(Fraction& dura);
146  void backup(Fraction& dura);
147  void timeModification(Fraction& timeMod);
148  void pitch(int& step, float& alter, int& oct);
149  void rest();
150  void skipLogCurrElem();
151  bool determineMeasureLength(QVector<Fraction>& ml) const;
152  VoiceList getVoiceList(const QString id) const;
153  bool determineStaffMoveVoice(const QString& id, const int mxStaff, const QString& mxVoice,
154  int& msMove, int& msTrack, int& msVoice) const;
155  int trackForPart(const QString& id) const;
156  bool hasPart(const QString& id) const;
157  Part* getPart(const QString& id) const { return _partMap.value(id); }
158  MusicXmlPart getMusicXmlPart(const QString& id) const { return _parts.value(id); }
159  MusicXMLDrumset getDrumset(const QString& id) const { return _drumsets.value(id); }
160  void setDrumsetDefault(const QString& id, const QString& instrId, const NoteHead::Group hg, const int line, const Direction sd);
161  MusicXmlInstrList getInstrList(const QString id) const;
162  Fraction getMeasureStart(const int i) const;
163  int octaveShift(const QString& id, const int staff, const Fraction f) const;
164 
165 private:
166  // functions
167  void setFirstInstr(const QString& id, const Fraction stime);
168 
169  // generic pass 1 data
170  QXmlStreamReader _e;
171  int _divs;
172  QMap<QString, MusicXmlPart> _parts;
173  QVector<Fraction> _measureLength;
174  QVector<Fraction> _measureStart;
175  PartMap _partMap;
176  QMap<QString, MusicXMLDrumset> _drumsets;
179 
180  // part specific data (TODO: move to part-specific class)
182  QMap<int, MxmlOctaveShiftDesc> _octaveShifts;
184  QString _firstInstrId;
185  };
186 
187 } // namespace Ms
188 #endif
QString _firstInstrId
First instrument id.
Definition: importmxmlpass1.h:184
MxmlOctaveShiftDesc()
Definition: importmxmlpass1.h:59
Definition: durationtype.h:28
Definition of class MusicXML.
Fraction _firstInstrSTime
First instrument start time.
Definition: importmxmlpass1.h:183
qreal evenBottomMargin
Definition: importmxmlpass1.h:40
MxmlStartStop
Definition: importmxmlpass1.h:67
Definition of Score class.
QMap< QString, VoiceDesc > VoiceList
Definition: importxmlfirstpass.h:21
bool twosided
Definition: importmxmlpass1.h:43
QMap< QString, MusicXMLDrumset > _drumsets
Drumset for each part, mapped on part id.
Definition: importmxmlpass1.h:176
Definition: importmxmllogger.h:20
QList< CreditWords * > CreditWordsList
Definition: musicxml.h:75
QMap< QString, Part * > PartMap
Definition: importmxmlpass1.h:46
Definition: importxmlfirstpass.h:23
PartMap _partMap
TODO merge into MusicXmlPart ??
Definition: importmxmlpass1.h:175
Definition: score.h:391
Fraction _timeSigDura
Measure duration according to last timesig read.
Definition: importmxmlpass1.h:181
qreal oddTopMargin
Definition: importmxmlpass1.h:41
MusicXMLDrumset getDrumset(const QString &id) const
Definition: importmxmlpass1.h:159
qreal oddBottomMargin
Definition: importmxmlpass1.h:42
QFlags< MxmlTupletFlag > MxmlTupletFlags
Definition: importmxmlpass1.h:79
short num
Definition: importmxmlpass1.h:58
Type
Definition: importmxmlpass1.h:54
std::map< QString, MxmlTupletState > MxmlTupletStates
Definition: importmxmlpass1.h:99
Score * _score
MuseScore score.
Definition: importmxmlpass1.h:177
Definition: importmxmlpass1.h:81
QMap< int, MxmlOctaveShiftDesc > _octaveShifts
Pending octave-shifts.
Definition: importmxmlpass1.h:182
std::map< int, MusicXmlPartGroup * > MusicXmlPartGroupMap
Definition: importmxmlpass1.cpp:1498
MxmlOctaveShiftDesc(Type _tp, short _size, Fraction _tm)
Definition: importmxmlpass1.h:60
qreal evenTopMargin
Definition: importmxmlpass1.h:39
Definition: importmxmlpass1.h:115
Definition: importmxmlpass1.h:53
MxmlLogger * _logger
Error logger.
Definition: importmxmlpass1.h:178
FileError
Definition: score.h:395
Part * getPart(const QString &id) const
Definition: importmxmlpass1.h:157
QVector< Fraction > _measureStart
Start time of each measure.
Definition: importmxmlpass1.h:174
short size
Definition: importmxmlpass1.h:56
Definition: importxmlfirstpass.h:49
Definition: aeolus.cpp:26
QVector< Fraction > _measureLength
Length of each measure.
Definition: importmxmlpass1.h:173
QXmlStreamReader _e
Definition: importmxmlpass1.h:170
MxmlTupletFlag
Definition: importmxmlpass1.h:71
qreal oddLeftMargin
Definition: importmxmlpass1.h:38
const QSizeF & size() const
Definition: read206.h:38
QMap< QString, MusicXMLDrumInstrument > MusicXMLDrumset
A MusicXML drumset or set of instruments in a multi-instrument part.
Definition: musicxmlsupport.h:160
QSizeF _size
Definition: read206.h:25
Fraction missingTupletDuration(const Fraction duration)
Definition: importmxmlpass1.cpp:2753
Direction
Definition: types.h:282
QSizeF size
Definition: importmxmlpass1.h:35
qreal printableWidth
Definition: importmxmlpass1.h:36
Group
Definition: note.h:56
Definition: fraction.h:46
QMap< QString, MusicXmlPart > _parts
Parts data, mapped on part id.
Definition: importmxmlpass1.h:172
qreal evenLeftMargin
Definition: importmxmlpass1.h:37
void determineTupletFractionAndFullDuration(const Fraction duration, Fraction &fraction, Fraction &fullDuration)
Split duration into two factors where fullDuration is note sized (i.e.
Definition: importmxmlpass1.cpp:2632
Detect overlap in a voice, which is when a voice has two or more notes active at the same time...
Definition: musicxmlsupport.h:108
std::vector< MusicXmlPartGroup * > MusicXmlPartGroupList
Definition: musicxml.h:125
Definition: part.h:47
Fraction time
Definition: importmxmlpass1.h:57
int _divs
Current MusicXML divisions value.
Definition: importmxmlpass1.h:171
MusicXmlPart getMusicXmlPart(const QString &id) const
Definition: importmxmlpass1.h:158
Definition: read206.h:24
Type tp
Definition: importmxmlpass1.h:55