MuseScore  3.4
Music composition and notation
musicxmlsupport.h
Go to the documentation of this file.
1 //=============================================================================
2 // MusE Score
3 // Linux Music Score Editor
4 //
5 // Copyright (C) 2012 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 __MUSICXMLSUPPORT_H__
21 #define __MUSICXMLSUPPORT_H__
22 
23 #include "libmscore/fraction.h"
24 #include "libmscore/mscore.h"
25 #include "libmscore/note.h"
26 
27 namespace Ms {
28 
29 //---------------------------------------------------------
30 // NoteList
31 //---------------------------------------------------------
32 
37 typedef QPair<int, int> StartStop;
38 typedef QList<StartStop> StartStopList;
39 
40 //---------------------------------------------------------
41 // NoteList
42 //---------------------------------------------------------
43 
48 class NoteList {
49 public:
50  NoteList();
51  void addNote(const int startTick, const int endTick, const int staff);
52  void dump(const QString& voice) const;
53  bool stavesOverlap(const int staff1, const int staff2) const;
54  bool anyStaffOverlaps() const;
55 private:
56  QList<StartStopList> _staffNoteLists;
57  };
58 
59 //---------------------------------------------------------
60 // VoiceDesc
61 //---------------------------------------------------------
62 
67 class VoiceDesc {
68 public:
69  VoiceDesc();
70  void incrChordRests(int s);
71  int numberChordRests() const;
72  int numberChordRests(int s) const { return (s >= 0 && s < MAX_STAVES) ? _chordRests[s] : 0; }
73  int preferredStaff() const;
74  void setStaff(int s) { if (s >= 0) _staff = s; }
75  int staff() const { return _staff; }
76  void setVoice(int v) { if (v >= 0) _voice = v; }
77  int voice() const { return _voice; }
78  void setVoice(int s, int v) { if (s >= 0 && s < MAX_STAVES) _voices[s] = v; }
79  int voice(int s) const { return (s >= 0 && s < MAX_STAVES) ? _voices[s] : -1; }
80  void setOverlap(bool b) { _overlaps = b; }
81  bool overlaps() const { return _overlaps; }
82  void setStaffAlloc(int s, int i) { if (s >= 0 && s < MAX_STAVES) _staffAlloc[s] = i; }
83  int staffAlloc(int s) const { return (s >= 0 && s < MAX_STAVES) ? _staffAlloc[s] : -1; }
84  QString toString() const;
85 private:
86  int _chordRests[MAX_STAVES];
87  int _staff;
88  int _voice;
89  bool _overlaps;
90  int _staffAlloc[MAX_STAVES];
91  int _voices[MAX_STAVES];
92  };
93 
94 //---------------------------------------------------------
95 // VoiceOverlapDetector
96 //---------------------------------------------------------
97 
109 public:
111  void addNote(const int startTick, const int endTick, const QString& voice, const int staff);
112  void dump() const;
113  void newMeasure();
114  bool stavesOverlap(const QString& voice) const;
115 private:
116  QMap<QString, NoteList> _noteLists;
117  };
118 
119 //---------------------------------------------------------
120 // MusicXMLDrumInstrument
121 //---------------------------------------------------------
122 
129  int pitch; // pitch read from MusicXML
130  QString name; // name read from MusicXML
131  QString sound; // sound read from MusicXML
132  QString virtLib; // virtual library read from MusicXML
133  QString virtName; // virtualname read from MusicXML
134  int midiChannel; // channel read from MusicXML
135  int midiPort; // port read from MusicXML
136  int midiProgram; // program read from MusicXML
137  int midiVolume; // volume read from MusicXML
138  int midiPan; // pan value read from MusicXML
140  int line;
142 
143  QString toString() const;
144 
146  : pitch(-1), name(), midiChannel(-1), midiPort(-1), midiProgram(-1), midiVolume(100), midiPan(63),
147  notehead(NoteHead::Group::HEAD_INVALID), line(0), stemDirection(Direction::AUTO) {}
149  : pitch(-1), name(s), midiChannel(-1), midiPort(-1), midiProgram(-1), midiVolume(100), midiPan(63),
150  notehead(NoteHead::Group::HEAD_INVALID), line(0), stemDirection(Direction::AUTO) {}
151  MusicXMLDrumInstrument(int p, QString s, NoteHead::Group nh, int l, Direction d)
152  : pitch(p), name(s), midiChannel(-1), midiPort(-1), midiProgram(-1), midiVolume(100), midiPan(63),
153  notehead(nh), line(l), stemDirection(d) {}
154  };
155 
160 typedef QMap<QString, MusicXMLDrumInstrument> MusicXMLDrumset;
161 typedef QMapIterator<QString, MusicXMLDrumInstrument> MusicXMLDrumsetIterator;
162 
163 
164 //---------------------------------------------------------
165 // MxmlSupport -- MusicXML import support functions
166 //---------------------------------------------------------
167 
168 class MxmlSupport {
169 public:
170  static int stringToInt(const QString& s, bool* ok);
171  static Fraction durationAsFraction(const int divisions, const QDomElement e);
172  static Fraction noteTypeToFraction(QString type);
173  static Fraction calculateFraction(QString type, int dots, int normalNotes, int actualNotes);
174  };
175 
176 //---------------------------------------------------------
177 // ValidatorMessageHandler
178 //---------------------------------------------------------
179 
184 class ValidatorMessageHandler : public QAbstractMessageHandler
185  {
186  Q_OBJECT
187 
188 public:
189  ValidatorMessageHandler() : QAbstractMessageHandler(0) {}
190  QString getErrors() const { return errors; }
191 protected:
192  virtual void handleMessage(QtMsgType type, const QString& description,
193  const QUrl& identifier, const QSourceLocation& sourceLocation);
194 private:
195  QString errors;
196  };
197 
198 extern void domError(const QDomElement&);
199 extern void domNotImplemented(const QDomElement&);
200 
201 
202 extern QString accSymId2MxmlString(const SymId id);
203 extern QString accidentalType2MxmlString(const AccidentalType type);
204 extern AccidentalType mxmlString2accidentalType(const QString mxmlName);
205 extern SymId mxmlString2accSymId(const QString mxmlName);
206 extern AccidentalType microtonalGuess(double val);
207 
208 } // namespace Ms
209 #endif
int staffAlloc(int s) const
Definition: musicxmlsupport.h:83
int _staff
The MuseScore staff allocated.
Definition: musicxmlsupport.h:87
QList< StartStopList > _staffNoteLists
The note start/stop times in all staves.
Definition: musicxmlsupport.h:56
List of note start/stop times in a voice in all staves.
Definition: musicxmlsupport.h:48
MusicXMLDrumInstrument(QString s)
Definition: musicxmlsupport.h:148
QList< StartStop > StartStopList
Definition: musicxmlsupport.h:38
int numberChordRests(int s) const
Definition: musicxmlsupport.h:72
AccidentalType microtonalGuess(double val)
Convert a MusicXML alter tag into a microtonal accidental in MuseScore enum AccidentalType.
Definition: musicxmlsupport.cpp:565
AccidentalType mxmlString2accidentalType(const QString mxmlName)
Convert a MusicXML accidental name to a MuseScore enum AccidentalType.
Definition: musicxmlsupport.cpp:500
NoteHead::Group notehead
notehead symbol set
Definition: musicxmlsupport.h:139
void setVoice(int s, int v)
Definition: musicxmlsupport.h:78
QString virtName
Definition: musicxmlsupport.h:133
Message handler for the MusicXML schema validator QXmlSchemaValidator.
Definition: musicxmlsupport.h:184
AccidentalType
Definition: types.h:152
SymId
Definition: sym.h:30
void setStaffAlloc(int s, int i)
Definition: musicxmlsupport.h:82
void domError(const QDomElement &e)
Definition: musicxmlsupport.cpp:217
QString sound
Definition: musicxmlsupport.h:131
ValidatorMessageHandler()
Definition: musicxmlsupport.h:189
QString virtLib
Definition: musicxmlsupport.h:132
const char * toString(Direction val)
Definition: mscore.cpp:176
bool overlaps() const
Definition: musicxmlsupport.h:81
QString accidentalType2MxmlString(const AccidentalType type)
Definition: musicxmlsupport.cpp:460
Definition: model.h:100
NoteList()
Definition: musicxmlsupport.cpp:31
QMapIterator< QString, MusicXMLDrumInstrument > MusicXMLDrumsetIterator
Definition: musicxmlsupport.h:161
int _voice
The MuseScore voice allocated.
Definition: musicxmlsupport.h:88
int midiChannel
Definition: musicxmlsupport.h:134
int line
place notehead onto this line
Definition: musicxmlsupport.h:140
QString getErrors() const
Definition: musicxmlsupport.h:190
bool _overlaps
This voice contains active notes in multiple staves at the same time.
Definition: musicxmlsupport.h:89
QString errors
Definition: musicxmlsupport.h:195
int midiProgram
Definition: musicxmlsupport.h:136
int pitch
Definition: musicxmlsupport.h:129
SymId mxmlString2accSymId(const QString mxmlName)
Definition: musicxmlsupport.cpp:412
int staff() const
Definition: musicxmlsupport.h:75
void setVoice(int v)
Definition: musicxmlsupport.h:76
A single instrument in a MusicXML part.
Definition: musicxmlsupport.h:128
Definition: aeolus.cpp:26
QPair< int, int > StartStop
List of note start/stop times in a voice in a single staff.
Definition: musicxmlsupport.h:37
Definition: note.h:53
bool anyStaffOverlaps() const
Determine if any note in any staff overlaps.
Definition: musicxmlsupport.cpp:91
int midiPan
Definition: musicxmlsupport.h:138
QMap< QString, MusicXMLDrumInstrument > MusicXMLDrumset
A MusicXML drumset or set of instruments in a multi-instrument part.
Definition: musicxmlsupport.h:160
MusicXMLDrumInstrument(int p, QString s, NoteHead::Group nh, int l, Direction d)
Definition: musicxmlsupport.h:151
void setOverlap(bool b)
Definition: musicxmlsupport.h:80
Direction
Definition: types.h:282
int midiVolume
Definition: musicxmlsupport.h:137
void domNotImplemented(const QDomElement &e)
Definition: musicxmlsupport.cpp:239
Definition of classes Note and NoteHead.
QString accSymId2MxmlString(const SymId id)
Definition: musicxmlsupport.cpp:374
bool stavesOverlap(const int staff1, const int staff2) const
Determine if any note in staff1 and staff2 overlaps.
Definition: musicxmlsupport.cpp:76
int voice(int s) const
Definition: musicxmlsupport.h:79
Definition: musicxmlsupport.h:168
Group
Definition: note.h:56
void dump(const QString &voice) const
Definition: musicxmlsupport.cpp:43
QString name
Definition: musicxmlsupport.h:130
QMap< QString, NoteList > _noteLists
The notelists for all the voices.
Definition: musicxmlsupport.h:116
Definition: fraction.h:46
int midiPort
Definition: musicxmlsupport.h:135
Direction stemDirection
Definition: musicxmlsupport.h:141
Detect overlap in a voice, which is when a voice has two or more notes active at the same time...
Definition: musicxmlsupport.h:108
int voice() const
Definition: musicxmlsupport.h:77
void addNote(const int startTick, const int endTick, const int staff)
Definition: musicxmlsupport.cpp:37
MusicXMLDrumInstrument()
Definition: musicxmlsupport.h:145
The description of a single voice in a MusicXML part.
Definition: musicxmlsupport.h:67
void setStaff(int s)
Definition: musicxmlsupport.h:74