2012-05-26 14:26:10 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Music Composition & Notation
|
|
|
|
//
|
|
|
|
// Copyright (C) 2004-2011 Werner Schweer
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2
|
|
|
|
// as published by the Free Software Foundation and appearing in
|
|
|
|
// the file LICENCE.GPL
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#ifndef __XML_H__
|
|
|
|
#define __XML_H__
|
|
|
|
|
2014-05-07 09:28:19 +02:00
|
|
|
#include "thirdparty/xmlstream/xmlstream.h"
|
2014-04-30 10:08:38 +02:00
|
|
|
#include "stafftype.h"
|
2014-05-05 15:38:40 +02:00
|
|
|
#include "interval.h"
|
2014-07-23 16:08:46 +02:00
|
|
|
#include "element.h"
|
|
|
|
#include "select.h"
|
2012-05-26 14:26:10 +02:00
|
|
|
|
2013-05-13 18:49:17 +02:00
|
|
|
namespace Ms {
|
|
|
|
|
2014-06-24 14:45:50 +02:00
|
|
|
enum class PlaceText : char;
|
2014-07-25 17:13:27 +02:00
|
|
|
enum class ClefType : signed char;
|
2013-01-21 20:21:41 +01:00
|
|
|
class Spanner;
|
|
|
|
class Beam;
|
|
|
|
class Tuplet;
|
2014-02-26 19:06:42 +01:00
|
|
|
class Measure;
|
2013-01-21 20:21:41 +01:00
|
|
|
|
2013-10-13 13:06:32 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// SpannerValues
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
struct SpannerValues {
|
|
|
|
int spannerId;
|
|
|
|
int tick2;
|
|
|
|
int track2;
|
|
|
|
};
|
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// XmlReader
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2014-05-07 09:28:19 +02:00
|
|
|
class XmlReader : public XmlStreamReader {
|
2013-01-11 18:10:18 +01:00
|
|
|
QString docName; // used for error reporting
|
|
|
|
|
2013-01-21 20:21:41 +01:00
|
|
|
// Score read context (for read optimizations):
|
2014-07-30 12:34:56 +02:00
|
|
|
int _tick { 0 };
|
|
|
|
int _tickOffset { 0 };
|
|
|
|
int _track { 0 };
|
2014-11-06 10:44:57 +01:00
|
|
|
int _trackOffset { 0 };
|
2014-07-30 12:34:56 +02:00
|
|
|
bool _pasteMode { false }; // modifies read behaviour on paste operation
|
|
|
|
Measure* _lastMeasure { nullptr };
|
2013-01-21 20:21:41 +01:00
|
|
|
QList<Beam*> _beams;
|
|
|
|
QList<Tuplet*> _tuplets;
|
2013-10-13 13:06:32 +02:00
|
|
|
QList<SpannerValues> _spannerValues;
|
2014-07-21 13:24:21 +02:00
|
|
|
QList<std::pair<int,Spanner*>> _spanner;
|
2014-04-30 10:08:38 +02:00
|
|
|
QList<StaffType> _staffTypes;
|
2014-02-17 16:28:09 +01:00
|
|
|
void htmlToString(int level, QString*);
|
2014-05-05 15:38:40 +02:00
|
|
|
Interval _transpose;
|
2014-07-25 17:13:27 +02:00
|
|
|
QList<QList<std::pair<int, ClefType>>> _clefs; // for 1.3 scores
|
2013-01-21 20:21:41 +01:00
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
public:
|
2014-05-07 09:28:19 +02:00
|
|
|
XmlReader(QFile* f) : XmlStreamReader(f), docName(f->fileName()) {}
|
|
|
|
XmlReader(const QByteArray& d, const QString& s = QString()) : XmlStreamReader(d), docName(s) {}
|
|
|
|
XmlReader(QIODevice* d, const QString& s = QString()) : XmlStreamReader(d), docName(s) {}
|
|
|
|
XmlReader(const QString& d, const QString& s = QString()) : XmlStreamReader(d), docName(s) {}
|
2013-01-11 18:10:18 +01:00
|
|
|
|
|
|
|
void unknown() const;
|
|
|
|
|
|
|
|
// attribute helper routines:
|
|
|
|
QString attribute(const char* s) const { return attributes().value(s).toString(); }
|
|
|
|
QString attribute(const char* s, const QString&) const;
|
|
|
|
int intAttribute(const char* s) const;
|
|
|
|
int intAttribute(const char* s, int _default) const;
|
|
|
|
double doubleAttribute(const char* s) const;
|
|
|
|
double doubleAttribute(const char* s, double _default) const;
|
|
|
|
bool hasAttribute(const char* s) const;
|
|
|
|
|
|
|
|
// helper routines based on readElementText():
|
|
|
|
int readInt() { return readElementText().toInt(); }
|
|
|
|
int readInt(bool* ok) { return readElementText().toInt(ok); }
|
|
|
|
double readDouble() { return readElementText().toDouble(); }
|
2014-05-28 16:17:40 +02:00
|
|
|
bool readBool() { return readElementText().toInt() != 0; }
|
2013-01-11 18:10:18 +01:00
|
|
|
QPointF readPoint();
|
|
|
|
QSizeF readSize();
|
|
|
|
QRectF readRect();
|
|
|
|
QColor readColor();
|
|
|
|
Fraction readFraction();
|
2014-02-17 16:28:09 +01:00
|
|
|
QString readXml();
|
2013-01-11 18:10:18 +01:00
|
|
|
|
|
|
|
void setDocName(const QString& s) { docName = s; }
|
2014-02-17 16:28:09 +01:00
|
|
|
QString getDocName() const { return docName; }
|
2013-01-21 20:21:41 +01:00
|
|
|
|
2014-11-06 10:44:57 +01:00
|
|
|
int tick() const { return _tick + _tickOffset; }
|
|
|
|
void initTick(int val) { _tick = val; }
|
|
|
|
void incTick(int val) { _tick += val; }
|
|
|
|
void setTickOffset(int val) { _tickOffset = val; }
|
|
|
|
int track() const { return _track + _trackOffset; }
|
|
|
|
void setTrackOffset(int val) { _trackOffset = val; }
|
|
|
|
int trackOffset() const { return _trackOffset; }
|
|
|
|
void setTrack(int val) { _track = val; }
|
|
|
|
bool pasteMode() const { return _pasteMode; }
|
|
|
|
void setPasteMode(bool v) { _pasteMode = v; }
|
2014-07-30 12:34:56 +02:00
|
|
|
|
2013-01-24 09:31:41 +01:00
|
|
|
void addTuplet(Tuplet* s);
|
2014-11-06 10:44:57 +01:00
|
|
|
void addBeam(Beam* s) { _beams.append(s); }
|
2013-01-21 20:21:41 +01:00
|
|
|
|
2014-02-26 19:06:42 +01:00
|
|
|
void setLastMeasure(Measure* m) { _lastMeasure = m; }
|
|
|
|
Measure* lastMeasure() const { return _lastMeasure; }
|
|
|
|
|
2013-01-21 20:21:41 +01:00
|
|
|
Beam* findBeam(int) const;
|
|
|
|
Tuplet* findTuplet(int) const;
|
|
|
|
|
2013-10-13 13:06:32 +02:00
|
|
|
QList<Tuplet*>& tuplets() { return _tuplets; }
|
|
|
|
QList<Beam*>& beams() { return _beams; }
|
2014-06-24 14:45:50 +02:00
|
|
|
|
2014-07-21 13:24:21 +02:00
|
|
|
void removeSpanner(const Spanner*);
|
|
|
|
void addSpanner(int id, Spanner*);
|
2014-06-24 14:45:50 +02:00
|
|
|
Spanner* findSpanner(int id);
|
2014-07-21 13:24:21 +02:00
|
|
|
int spannerId(const Spanner*); // returns spanner id, allocates new one if none exists
|
2014-06-24 14:45:50 +02:00
|
|
|
|
2013-10-13 13:06:32 +02:00
|
|
|
void addSpannerValues(const SpannerValues& sv) { _spannerValues.append(sv); }
|
|
|
|
const SpannerValues* spannerValues(int id);
|
2014-04-30 10:08:38 +02:00
|
|
|
QList<StaffType>& staffType() { return _staffTypes; }
|
2014-05-05 15:38:40 +02:00
|
|
|
Interval transpose() const { return _transpose; }
|
|
|
|
void setTransposeChromatic(int v) { _transpose.chromatic = v; }
|
|
|
|
void setTransposeDiatonic(int v) { _transpose.diatonic = v; }
|
2014-07-25 17:13:27 +02:00
|
|
|
|
|
|
|
QList<std::pair<int, ClefType>>& clefs(int idx);
|
2013-01-11 18:10:18 +01:00
|
|
|
};
|
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// Xml
|
2014-07-21 13:24:21 +02:00
|
|
|
// xml writer
|
2012-05-26 14:26:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
class Xml : public QTextStream {
|
|
|
|
static const int BS = 2048;
|
|
|
|
|
|
|
|
QList<QString> stack;
|
|
|
|
void putLevel();
|
2014-07-21 13:24:21 +02:00
|
|
|
QList<std::pair<int,const Spanner*>> _spanner;
|
|
|
|
int _spannerId = 1;
|
2014-07-23 16:08:46 +02:00
|
|
|
SelectionFilter _filter;
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
public:
|
2014-03-14 11:30:19 +01:00
|
|
|
int curTick = 0; // used to optimize output
|
|
|
|
int curTrack = -1;
|
|
|
|
int tickDiff = 0;
|
|
|
|
int trackDiff = 0; // saved track is curTrack-trackDiff
|
|
|
|
|
|
|
|
bool clipboardmode = false; // used to modify write() behaviour
|
|
|
|
bool excerptmode = false; // true when writing a part
|
|
|
|
bool writeOmr = true; // false if writing into *.msc file
|
|
|
|
|
|
|
|
int tupletId = 1;
|
|
|
|
int beamId = 1;
|
2014-07-21 13:24:21 +02:00
|
|
|
|
|
|
|
int addSpanner(const Spanner*); // returns allocated id
|
|
|
|
const Spanner* findSpanner(int id);
|
|
|
|
int spannerId(const Spanner*); // returns spanner id, allocates new one if none exists
|
2012-05-26 14:26:10 +02:00
|
|
|
|
|
|
|
Xml(QIODevice* dev);
|
|
|
|
Xml();
|
|
|
|
|
|
|
|
void sTag(const char* name, Spatium sp) { Xml::tag(name, QVariant(sp.val())); }
|
2012-10-30 09:06:24 +01:00
|
|
|
void pTag(const char* name, PlaceText);
|
2012-05-26 14:26:10 +02:00
|
|
|
void fTag(const char* name, const Fraction&);
|
|
|
|
|
|
|
|
void header();
|
|
|
|
|
|
|
|
void stag(const QString&);
|
|
|
|
void etag();
|
|
|
|
|
|
|
|
void tagE(const QString&);
|
|
|
|
void tagE(const char* format, ...);
|
|
|
|
void ntag(const char* name);
|
|
|
|
void netag(const char* name);
|
|
|
|
|
|
|
|
void tag(P_ID id, void* data, void* defaultVal);
|
|
|
|
void tag(P_ID id, QVariant data, QVariant defaultData = QVariant());
|
|
|
|
void tag(const char* name, QVariant data, QVariant defaultData = QVariant());
|
|
|
|
void tag(const QString&, QVariant data);
|
|
|
|
void tag(const char* name, const char* s) { tag(name, QVariant(s)); }
|
|
|
|
void tag(const char* name, const QString& s) { tag(name, QVariant(s)); }
|
|
|
|
void tag(const char* name, const QWidget*);
|
|
|
|
|
2014-03-25 16:55:51 +01:00
|
|
|
void writeXml(const QString&, QString s);
|
2012-05-26 14:26:10 +02:00
|
|
|
void dump(int len, const unsigned char* p);
|
|
|
|
|
2014-07-23 16:08:46 +02:00
|
|
|
void setFilter(SelectionFilter f) { _filter = f; }
|
|
|
|
bool canWrite(const Element*) const;
|
2014-08-07 00:30:50 +02:00
|
|
|
bool canWriteVoice(int track) const;
|
2014-07-23 16:08:46 +02:00
|
|
|
|
2012-05-26 14:26:10 +02:00
|
|
|
static QString xmlString(const QString&);
|
|
|
|
};
|
|
|
|
|
2013-01-11 18:10:18 +01:00
|
|
|
extern PlaceText readPlacement(XmlReader&);
|
2012-05-26 14:26:10 +02:00
|
|
|
extern QString docName;
|
2013-05-13 18:49:17 +02:00
|
|
|
|
|
|
|
} // namespace Ms
|
2012-05-26 14:26:10 +02:00
|
|
|
#endif
|
|
|
|
|