moved chordlist from style to score
This commit is contained in:
parent
6a5a25bf9d
commit
69a75efee6
16 changed files with 279 additions and 170 deletions
|
@ -89,6 +89,8 @@ set(MODULE_SRC
|
|||
${CMAKE_CURRENT_LIST_DIR}/compat/mscxcompat.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/compat/pageformat.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/compat/pageformat.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/compat/chordlist.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/compat/chordlist.h
|
||||
|
||||
${CMAKE_CURRENT_LIST_DIR}/style/styledef.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/style/styledef.h
|
||||
|
|
111
src/engraving/compat/chordlist.cpp
Normal file
111
src/engraving/compat/chordlist.cpp
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
* MuseScore-CLA-applies
|
||||
*
|
||||
* MuseScore
|
||||
* Music Composition & Notation
|
||||
*
|
||||
* Copyright (C) 2021 MuseScore BVBA 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 3 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "chordlist.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "style/style.h"
|
||||
#include "libmscore/score.h"
|
||||
#include "libmscore/xml.h"
|
||||
|
||||
using namespace mu::engraving::compat;
|
||||
using namespace Ms;
|
||||
|
||||
ReadChordListHook::ReadChordListHook(Ms::Score* score)
|
||||
: m_score(score)
|
||||
{
|
||||
if (m_score) {
|
||||
m_oldChordDescriptionFile = m_score->style().value(Sid::chordDescriptionFile).toString();
|
||||
}
|
||||
}
|
||||
|
||||
void ReadChordListHook::read(Ms::XmlReader& e)
|
||||
{
|
||||
if (!m_score) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_score->chordList()->clear();
|
||||
m_score->chordList()->read(e);
|
||||
m_score->chordList()->setCustomChordList(true);
|
||||
|
||||
m_chordListTag = true;
|
||||
}
|
||||
|
||||
void ReadChordListHook::validate()
|
||||
{
|
||||
if (!m_score) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if we just specified a new chord description file
|
||||
// and didn't encounter a ChordList tag
|
||||
// then load the chord description file
|
||||
|
||||
MStyle& style = m_score->style();
|
||||
ChordList* chordList = m_score->chordList();
|
||||
|
||||
QString newChordDescriptionFile = style.value(Sid::chordDescriptionFile).toString();
|
||||
if (newChordDescriptionFile != m_oldChordDescriptionFile && !m_chordListTag) {
|
||||
if (!newChordDescriptionFile.startsWith("chords_") && style.value(Sid::chordStyle).toString() == "std") {
|
||||
// should not normally happen,
|
||||
// but treat as "old" (114) score just in case
|
||||
style.set(Sid::chordStyle, QVariant(QString("custom")));
|
||||
style.set(Sid::chordsXmlFile, QVariant(true));
|
||||
qDebug("StyleData::load: custom chord description file %s with chordStyle == std", qPrintable(newChordDescriptionFile));
|
||||
}
|
||||
if (style.value(Sid::chordStyle).toString() == "custom") {
|
||||
chordList->setCustomChordList(true);
|
||||
} else {
|
||||
chordList->setCustomChordList(false);
|
||||
}
|
||||
chordList->unload();
|
||||
}
|
||||
|
||||
// make sure we have a chordlist
|
||||
if (!m_chordListTag) {
|
||||
chordList->checkChordList(style);
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================================
|
||||
// WriteChordListHook
|
||||
// ==========================================================
|
||||
|
||||
WriteChordListHook::WriteChordListHook(Ms::Score* score)
|
||||
: m_score(score)
|
||||
{
|
||||
}
|
||||
|
||||
void WriteChordListHook::write(Ms::XmlWriter& xml)
|
||||
{
|
||||
if (!m_score) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChordList* chordList = m_score->chordList();
|
||||
if (chordList->customChordList() && !chordList->empty()) {
|
||||
xml.stag("ChordList");
|
||||
chordList->write(xml);
|
||||
xml.etag();
|
||||
}
|
||||
}
|
59
src/engraving/compat/chordlist.h
Normal file
59
src/engraving/compat/chordlist.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
* MuseScore-CLA-applies
|
||||
*
|
||||
* MuseScore
|
||||
* Music Composition & Notation
|
||||
*
|
||||
* Copyright (C) 2021 MuseScore BVBA 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 3 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef MU_ENGRAVING_CHORDLIST_H
|
||||
#define MU_ENGRAVING_CHORDLIST_H
|
||||
|
||||
#include <functional>
|
||||
#include <QString>
|
||||
|
||||
namespace Ms {
|
||||
class XmlReader;
|
||||
class XmlWriter;
|
||||
class Score;
|
||||
}
|
||||
|
||||
namespace mu::engraving::compat {
|
||||
struct ReadChordListHook
|
||||
{
|
||||
ReadChordListHook(Ms::Score* score);
|
||||
|
||||
void read(Ms::XmlReader& e);
|
||||
void validate();
|
||||
|
||||
private:
|
||||
Ms::Score* m_score = nullptr;
|
||||
bool m_chordListTag = false;
|
||||
QString m_oldChordDescriptionFile;
|
||||
};
|
||||
|
||||
struct WriteChordListHook
|
||||
{
|
||||
WriteChordListHook(Ms::Score* score);
|
||||
|
||||
void write(Ms::XmlWriter& xml);
|
||||
|
||||
private:
|
||||
Ms::Score* m_score = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // MU_ENGRAVING_CHORDLIST_H
|
|
@ -2017,6 +2017,31 @@ void ChordList::unload()
|
|||
_autoAdjust = false;
|
||||
}
|
||||
|
||||
const ChordDescription* ChordList::description(int id) const
|
||||
{
|
||||
auto it = this->find(id);
|
||||
if (it == this->end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &it.value();
|
||||
}
|
||||
|
||||
void ChordList::checkChordList(const MStyle& style)
|
||||
{
|
||||
// make sure we have a chordlist
|
||||
if (!loaded()) {
|
||||
qreal emag = style.value(Sid::chordExtensionMag).toDouble();
|
||||
qreal eadjust = style.value(Sid::chordExtensionAdjust).toDouble();
|
||||
qreal mmag = style.value(Sid::chordModifierMag).toDouble();
|
||||
qreal madjust = style.value(Sid::chordModifierAdjust).toDouble();
|
||||
configureAutoAdjust(emag, eadjust, mmag, madjust);
|
||||
if (style.value(Sid::chordsXmlFile).toBool()) {
|
||||
read("chords.xml");
|
||||
}
|
||||
read(style.value(Sid::chordDescriptionFile).toString());
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// print
|
||||
// only for debugging
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#define __CHORDLIST_H__
|
||||
|
||||
#include <QMap>
|
||||
#include "style/style.h"
|
||||
|
||||
namespace Ms {
|
||||
class XmlWriter;
|
||||
|
@ -259,6 +260,8 @@ class ChordList : public QMap<int, ChordDescription>
|
|||
qreal _emag = 1.0, _eadjust = 0.0;
|
||||
qreal _mmag = 1.0, _madjust = 0.0;
|
||||
|
||||
bool _customChordList = false; // if true, chordlist will be saved as part of score
|
||||
|
||||
public:
|
||||
QList<ChordFont> fonts;
|
||||
QList<RenderAction> renderListRoot;
|
||||
|
@ -279,7 +282,14 @@ public:
|
|||
bool write(const QString&) const;
|
||||
bool loaded() const;
|
||||
void unload();
|
||||
|
||||
const ChordDescription* description(int id) const;
|
||||
ChordSymbol symbol(const QString& s) const { return symbols.value(s); }
|
||||
|
||||
void setCustomChordList(bool t) { _customChordList = t; }
|
||||
bool customChordList() const { return _customChordList; }
|
||||
|
||||
void checkChordList(const MStyle& style);
|
||||
};
|
||||
} // namespace Ms
|
||||
#endif
|
||||
|
|
|
@ -77,7 +77,7 @@ QString Harmony::harmonyName() const
|
|||
hc.add(_degreeList);
|
||||
// try to find the chord in chordList
|
||||
const ChordDescription* newExtension = 0;
|
||||
const ChordList* cl = score()->style().chordList();
|
||||
const ChordList* cl = score()->chordList();
|
||||
for (const ChordDescription& cd : *cl) {
|
||||
if (cd.chord == hc && !cd.names.empty()) {
|
||||
newExtension = &cd;
|
||||
|
@ -157,7 +157,7 @@ void Harmony::resolveDegreeList()
|
|||
// _descr->chord.print();
|
||||
|
||||
// try to find the chord in chordList
|
||||
const ChordList* cl = score()->style().chordList();
|
||||
const ChordList* cl = score()->chordList();
|
||||
for (const ChordDescription& cd : *cl) {
|
||||
if ((cd.chord == hc) && !cd.names.empty()) {
|
||||
qDebug("ResolveDegreeList: found in table as %s", qPrintable(cd.names.front()));
|
||||
|
@ -782,7 +782,7 @@ const ChordDescription* Harmony::parseHarmony(const QString& ss, int* root, int*
|
|||
}
|
||||
|
||||
_userName = s;
|
||||
const ChordList* cl = score()->style().chordList();
|
||||
const ChordList* cl = score()->chordList();
|
||||
const ChordDescription* cd = 0;
|
||||
if (useLiteral) {
|
||||
cd = descr(s);
|
||||
|
@ -1185,7 +1185,7 @@ const ChordDescription* Harmony::fromXml(const QString& kind, const QList<HDegre
|
|||
}
|
||||
|
||||
QString lowerCaseKind = kind.toLower();
|
||||
const ChordList* cl = score()->style().chordList();
|
||||
const ChordList* cl = score()->chordList();
|
||||
for (const ChordDescription& cd : *cl) {
|
||||
QString k = cd.xmlKind;
|
||||
QString lowerCaseK = k.toLower(); // required for xmlKind Tristan
|
||||
|
@ -1207,7 +1207,7 @@ const ChordDescription* Harmony::fromXml(const QString& kind, const QList<HDegre
|
|||
const ChordDescription* Harmony::fromXml(const QString& kind)
|
||||
{
|
||||
QString lowerCaseKind = kind.toLower();
|
||||
const ChordList* cl = score()->style().chordList();
|
||||
const ChordList* cl = score()->chordList();
|
||||
for (const ChordDescription& cd : *cl) {
|
||||
if (lowerCaseKind == cd.xmlKind) {
|
||||
return &cd;
|
||||
|
@ -1227,7 +1227,7 @@ const ChordDescription* Harmony::fromXml(const QString& kind, const QString& kin
|
|||
const QList<HDegree>& dl)
|
||||
{
|
||||
ParsedChord* pc = new ParsedChord;
|
||||
_textName = pc->fromXml(kind, kindText, symbols, parens, dl, score()->style().chordList());
|
||||
_textName = pc->fromXml(kind, kindText, symbols, parens, dl, score()->chordList());
|
||||
_parsedForm = pc;
|
||||
const ChordDescription* cd = getDescription(_textName, pc);
|
||||
return cd;
|
||||
|
@ -1241,7 +1241,7 @@ const ChordDescription* Harmony::fromXml(const QString& kind, const QString& kin
|
|||
|
||||
const ChordDescription* Harmony::descr() const
|
||||
{
|
||||
return score()->style().chordDescription(_id);
|
||||
return score()->chordList()->description(_id);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
@ -1253,7 +1253,7 @@ const ChordDescription* Harmony::descr() const
|
|||
|
||||
const ChordDescription* Harmony::descr(const QString& name, const ParsedChord* pc) const
|
||||
{
|
||||
const ChordList* cl = score()->style().chordList();
|
||||
const ChordList* cl = score()->chordList();
|
||||
const ChordDescription* match = 0;
|
||||
if (cl) {
|
||||
for (const ChordDescription& cd : *cl) {
|
||||
|
@ -1372,7 +1372,7 @@ RealizedHarmony& Harmony::realizedHarmony()
|
|||
|
||||
const ChordDescription* Harmony::generateDescription()
|
||||
{
|
||||
ChordList* cl = score()->style().chordList();
|
||||
ChordList* cl = score()->chordList();
|
||||
ChordDescription cd(_textName);
|
||||
cd.complete(_parsedForm, cl);
|
||||
// remove parsed chord from description
|
||||
|
@ -1681,7 +1681,7 @@ void Harmony::render(const QString& s, qreal& x, qreal& y)
|
|||
void Harmony::render(const QList<RenderAction>& renderList, qreal& x, qreal& y, int tpc, NoteSpellingType noteSpelling,
|
||||
NoteCaseType noteCase)
|
||||
{
|
||||
ChordList* chordList = score()->style().chordList();
|
||||
ChordList* chordList = score()->chordList();
|
||||
QStack<PointF> stack;
|
||||
int fontIdx = 0;
|
||||
qreal _spatium = spatium();
|
||||
|
@ -1785,7 +1785,7 @@ void Harmony::render()
|
|||
{
|
||||
int capo = score()->styleI(Sid::capoPosition);
|
||||
|
||||
ChordList* chordList = score()->style().chordList();
|
||||
ChordList* chordList = score()->chordList();
|
||||
|
||||
fontList.clear();
|
||||
for (const ChordFont& cf : qAsConst(chordList->fonts)) {
|
||||
|
@ -2015,7 +2015,7 @@ const QList<HDegree>& Harmony::degreeList() const
|
|||
const ParsedChord* Harmony::parsedForm()
|
||||
{
|
||||
if (!_parsedForm) {
|
||||
ChordList* cl = score()->style().chordList();
|
||||
ChordList* cl = score()->chordList();
|
||||
_parsedForm = new ParsedChord();
|
||||
_parsedForm->parse(_textName, cl, false);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "style/style.h"
|
||||
#include "style/defaultstyle.h"
|
||||
#include "compat/pageformat.h"
|
||||
#include "compat/chordlist.h"
|
||||
|
||||
#include "score.h"
|
||||
#include "slur.h"
|
||||
|
@ -2723,10 +2724,8 @@ static void readPageFormat(compat::PageFormat* pf, XmlReader& e)
|
|||
// readStyle
|
||||
//---------------------------------------------------------
|
||||
|
||||
static void readStyle(MStyle* style, XmlReader& e)
|
||||
static void readStyle(MStyle* style, XmlReader& e, compat::ReadChordListHook& readChordListHook)
|
||||
{
|
||||
QString oldChordDescriptionFile = style->value(Sid::chordDescriptionFile).toString();
|
||||
bool chordListTag = false;
|
||||
while (e.readNextStartElement()) {
|
||||
QString tag = e.name().toString();
|
||||
|
||||
|
@ -2750,16 +2749,7 @@ static void readStyle(MStyle* style, XmlReader& e)
|
|||
} else if (tag == "displayInConcertPitch") {
|
||||
style->set(Sid::concertPitch, QVariant(bool(e.readInt())));
|
||||
} else if (tag == "ChordList") {
|
||||
style->chordList()->clear();
|
||||
style->chordList()->read(e);
|
||||
//! TODO Look like a bug, changes just the local variable
|
||||
for (ChordFont f : style->chordList()->fonts) {
|
||||
if (f.family == "MuseJazz") {
|
||||
f.family = "MuseJazz Text";
|
||||
}
|
||||
}
|
||||
style->setCustomChordList(true);
|
||||
chordListTag = true;
|
||||
readChordListHook.read(e);
|
||||
} else if (tag == "pageFillLimit" || tag == "genTimesig" || tag == "FixMeasureNumbers" || tag == "FixMeasureWidth") { // obsolete
|
||||
e.skipCurrentElement();
|
||||
} else if (tag == "systemDistance") { // obsolete
|
||||
|
@ -2823,31 +2813,8 @@ static void readStyle(MStyle* style, XmlReader& e)
|
|||
style->set(Sid::harmonyPlay, false);
|
||||
}
|
||||
|
||||
// if we just specified a new chord description file
|
||||
// and didn't encounter a ChordList tag
|
||||
// then load the chord description file
|
||||
readChordListHook.validate();
|
||||
|
||||
QString newChordDescriptionFile = style->value(Sid::chordDescriptionFile).toString();
|
||||
if (newChordDescriptionFile != oldChordDescriptionFile && !chordListTag) {
|
||||
if (!newChordDescriptionFile.startsWith("chords_") && style->value(Sid::chordStyle).toString() == "std") {
|
||||
// should not normally happen,
|
||||
// but treat as "old" (114) score just in case
|
||||
style->set(Sid::chordStyle, QVariant(QString("custom")));
|
||||
style->set(Sid::chordsXmlFile, QVariant(true));
|
||||
qDebug("StyleData::load: custom chord description file %s with chordStyle == std", qPrintable(newChordDescriptionFile));
|
||||
}
|
||||
if (style->value(Sid::chordStyle).toString() == "custom") {
|
||||
style->setCustomChordList(true);
|
||||
} else {
|
||||
style->setCustomChordList(false);
|
||||
}
|
||||
style->chordList()->unload();
|
||||
}
|
||||
|
||||
// make sure we have a chordlist
|
||||
if (!chordListTag) {
|
||||
style->checkChordList();
|
||||
}
|
||||
#if 0 // TODO
|
||||
//
|
||||
// Compatibility with old scores/styles:
|
||||
|
@ -2936,7 +2903,8 @@ Score::FileError MasterScore::read114(XmlReader& e)
|
|||
setShowPageborders(e.readInt());
|
||||
} else if (tag == "Style") {
|
||||
qreal sp = spatium();
|
||||
readStyle(&style(), e);
|
||||
compat::ReadChordListHook clhook(this);
|
||||
readStyle(&style(), e, clhook);
|
||||
//style()->load(e);
|
||||
// adjust this now so chords render properly on read
|
||||
// other style adjustments can wait until reading is finished
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "style/style.h"
|
||||
#include "style/defaultstyle.h"
|
||||
#include "compat/pageformat.h"
|
||||
#include "compat/chordlist.h"
|
||||
|
||||
#include "xml.h"
|
||||
#include "score.h"
|
||||
|
@ -3316,10 +3317,8 @@ static void readStaffContent(Score* score, XmlReader& e)
|
|||
// readStyle
|
||||
//---------------------------------------------------------
|
||||
|
||||
static void readStyle(MStyle* style, XmlReader& e)
|
||||
static void readStyle(MStyle* style, XmlReader& e, compat::ReadChordListHook& readChordListHook)
|
||||
{
|
||||
QString oldChordDescriptionFile = style->value(Sid::chordDescriptionFile).toString();
|
||||
bool chordListTag = false;
|
||||
excessTextStyles206.clear();
|
||||
while (e.readNextStartElement()) {
|
||||
QString tag = e.name().toString();
|
||||
|
@ -3351,16 +3350,7 @@ static void readStyle(MStyle* style, XmlReader& e)
|
|||
d += style->value(Sid::endBarWidth).toDouble();
|
||||
style->set(Sid::endBarDistance, QVariant(d));
|
||||
} else if (tag == "ChordList") {
|
||||
style->chordList()->clear();
|
||||
style->chordList()->read(e);
|
||||
style->setCustomChordList(true);
|
||||
//! TODO Look like a bug, changes just the local variable
|
||||
for (ChordFont f : style->chordList()->fonts) {
|
||||
if (f.family == "MuseJazz") {
|
||||
f.family = "MuseJazz Text";
|
||||
}
|
||||
}
|
||||
chordListTag = true;
|
||||
readChordListHook.read(e);
|
||||
} else if (tag == "harmonyY") {
|
||||
qreal val = -e.readDouble();
|
||||
if (val > 0.0) {
|
||||
|
@ -3382,31 +3372,7 @@ static void readStyle(MStyle* style, XmlReader& e)
|
|||
style->set(Sid::harmonyPlay, false);
|
||||
}
|
||||
|
||||
// if we just specified a new chord description file
|
||||
// and didn't encounter a ChordList tag
|
||||
// then load the chord description file
|
||||
|
||||
QString newChordDescriptionFile = style->value(Sid::chordDescriptionFile).toString();
|
||||
if (newChordDescriptionFile != oldChordDescriptionFile && !chordListTag) {
|
||||
if (!newChordDescriptionFile.startsWith("chords_") && style->value(Sid::chordStyle).toString() == "std") {
|
||||
// should not normally happen,
|
||||
// but treat as "old" (114) score just in case
|
||||
style->set(Sid::chordStyle, QVariant(QString("custom")));
|
||||
style->set(Sid::chordsXmlFile, QVariant(true));
|
||||
qDebug("StyleData::load: custom chord description file %s with chordStyle == std", qPrintable(newChordDescriptionFile));
|
||||
}
|
||||
if (style->value(Sid::chordStyle).toString() == "custom") {
|
||||
style->setCustomChordList(true);
|
||||
} else {
|
||||
style->setCustomChordList(false);
|
||||
}
|
||||
style->chordList()->unload();
|
||||
}
|
||||
|
||||
// make sure we have a chordlist
|
||||
if (!chordListTag) {
|
||||
style->checkChordList();
|
||||
}
|
||||
readChordListHook.validate();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
@ -3463,7 +3429,8 @@ static bool readScore(Score* score, XmlReader& e)
|
|||
score->setShowPageborders(e.readInt());
|
||||
} else if (tag == "Style") {
|
||||
qreal sp = score->style().value(Sid::spatium).toDouble();
|
||||
readStyle(&score->style(), e);
|
||||
compat::ReadChordListHook clhook(score);
|
||||
readStyle(&score->style(), e, clhook);
|
||||
if (score->style().value(Sid::MusicalTextFont).toString() == "MuseJazz") {
|
||||
score->style().set(Sid::MusicalTextFont, "MuseJazz Text");
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "style/style.h"
|
||||
#include "style/defaultstyle.h"
|
||||
|
||||
#include "compat/chordlist.h"
|
||||
|
||||
#include "xml.h"
|
||||
#include "score.h"
|
||||
#include "staff.h"
|
||||
|
@ -109,7 +111,8 @@ bool Score::read(XmlReader& e)
|
|||
_markIrregularMeasures = e.readInt();
|
||||
} else if (tag == "Style") {
|
||||
qreal sp = style().value(Sid::spatium).toDouble();
|
||||
style().load(e);
|
||||
compat::ReadChordListHook clhook(this);
|
||||
style().load(e, &clhook);
|
||||
// if (_layoutMode == LayoutMode::FLOAT || _layoutMode == LayoutMode::SYSTEM) {
|
||||
if (_layoutMode == LayoutMode::FLOAT) {
|
||||
// style should not change spatium in
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "spannermap.h"
|
||||
#include "layoutbreak.h"
|
||||
#include "property.h"
|
||||
#include "chordlist.h"
|
||||
|
||||
#include "io/msczwriter.h"
|
||||
#include "io/msczreader.h"
|
||||
|
@ -493,6 +494,7 @@ private:
|
|||
|
||||
InputState _is;
|
||||
MStyle _style;
|
||||
ChordList _chordList;
|
||||
|
||||
bool _created { false }; ///< file is never saved, has generated name
|
||||
bool _startedEmpty { false }; ///< The score was created from an empty template (typically ":/data/My_First_Score.mscx")
|
||||
|
@ -947,6 +949,10 @@ public:
|
|||
void spell(Note*);
|
||||
Fraction nextSeg(const Fraction& tick, int track);
|
||||
|
||||
ChordList* chordList() { return &_chordList; }
|
||||
const ChordList* chordList() const { return &_chordList; }
|
||||
void checkChordList() { _chordList.checkChordList(style()); }
|
||||
|
||||
virtual MStyle& style() { return _style; }
|
||||
virtual const MStyle& style() const { return _style; }
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "draw/qpainterprovider.h"
|
||||
#include "style/defaultstyle.h"
|
||||
|
||||
#include "compat/chordlist.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "score.h"
|
||||
#include "xml.h"
|
||||
|
@ -178,7 +180,8 @@ void Score::writeMovement(XmlWriter& xml, bool selectionOnly)
|
|||
xml.setCurTrack(-1);
|
||||
|
||||
if (isTopScore()) { // only top score
|
||||
style().save(xml, true); // save only differences to buildin style
|
||||
compat::WriteChordListHook clhook(this);
|
||||
style().save(xml, true, &clhook); // save only differences to buildin style
|
||||
}
|
||||
xml.tag("showInvisible", _showInvisible);
|
||||
xml.tag("showUnprintable", _showUnprintable);
|
||||
|
@ -529,7 +532,8 @@ bool Score::saveStyle(const QString& name)
|
|||
XmlWriter xml(this, &f);
|
||||
xml.header();
|
||||
xml.stag("museScore version=\"" MSC_VERSION "\"");
|
||||
style().save(xml, false); // save complete style
|
||||
compat::WriteChordListHook clhook(this);
|
||||
style().save(xml, false, &clhook); // save complete style
|
||||
xml.etag();
|
||||
if (f.error() != QFile::NoError) {
|
||||
MScore::lastError = QObject::tr("Write Style failed: %1").arg(f.errorString());
|
||||
|
|
|
@ -1809,17 +1809,17 @@ void ChangeStyleVal::flip(EditData*)
|
|||
case Sid::chordModifierMag:
|
||||
case Sid::chordModifierAdjust:
|
||||
case Sid::chordDescriptionFile: {
|
||||
score->style().chordList()->unload();
|
||||
score->chordList()->unload();
|
||||
qreal emag = score->styleD(Sid::chordExtensionMag);
|
||||
qreal eadjust = score->styleD(Sid::chordExtensionAdjust);
|
||||
qreal mmag = score->styleD(Sid::chordModifierMag);
|
||||
qreal madjust = score->styleD(Sid::chordModifierAdjust);
|
||||
score->style().chordList()->configureAutoAdjust(emag, eadjust, mmag, madjust);
|
||||
score->chordList()->configureAutoAdjust(emag, eadjust, mmag, madjust);
|
||||
if (score->styleB(Sid::chordsXmlFile)) {
|
||||
score->style().chordList()->read("chords.xml");
|
||||
score->chordList()->read("chords.xml");
|
||||
}
|
||||
score->style().chordList()->read(score->styleSt(Sid::chordDescriptionFile));
|
||||
score->style().setCustomChordList(score->styleSt(Sid::chordStyle) == "custom");
|
||||
score->chordList()->read(score->styleSt(Sid::chordDescriptionFile));
|
||||
score->chordList()->setCustomChordList(score->styleSt(Sid::chordStyle) == "custom");
|
||||
}
|
||||
break;
|
||||
case Sid::spatium:
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "style.h"
|
||||
|
||||
#include "compat/pageformat.h"
|
||||
#include "compat/chordlist.h"
|
||||
|
||||
#include "defaultstyle.h"
|
||||
|
||||
#include "libmscore/xml.h"
|
||||
|
@ -98,30 +100,6 @@ int MStyle::defaultStyleVersion() const
|
|||
return m_defaultStyleVersion;
|
||||
}
|
||||
|
||||
const ChordDescription* MStyle::chordDescription(int id) const
|
||||
{
|
||||
if (!m_chordList.contains(id)) {
|
||||
return 0;
|
||||
}
|
||||
return &*m_chordList.find(id);
|
||||
}
|
||||
|
||||
void MStyle::checkChordList()
|
||||
{
|
||||
// make sure we have a chordlist
|
||||
if (!m_chordList.loaded()) {
|
||||
qreal emag = value(Sid::chordExtensionMag).toDouble();
|
||||
qreal eadjust = value(Sid::chordExtensionAdjust).toDouble();
|
||||
qreal mmag = value(Sid::chordModifierMag).toDouble();
|
||||
qreal madjust = value(Sid::chordModifierAdjust).toDouble();
|
||||
m_chordList.configureAutoAdjust(emag, eadjust, mmag, madjust);
|
||||
if (value(Sid::chordsXmlFile).toBool()) {
|
||||
m_chordList.read("chords.xml");
|
||||
}
|
||||
m_chordList.read(value(Sid::chordDescriptionFile).toString());
|
||||
}
|
||||
}
|
||||
|
||||
bool MStyle::readProperties(XmlReader& e)
|
||||
{
|
||||
const QStringRef& tag(e.name());
|
||||
|
@ -296,7 +274,7 @@ bool MStyle::load(QFile* qf, bool ign)
|
|||
}
|
||||
while (e.readNextStartElement()) {
|
||||
if (e.name() == "Style") {
|
||||
load(e);
|
||||
load(e, nullptr);
|
||||
} else {
|
||||
e.unknown();
|
||||
}
|
||||
|
@ -306,11 +284,10 @@ bool MStyle::load(QFile* qf, bool ign)
|
|||
return true;
|
||||
}
|
||||
|
||||
void MStyle::load(XmlReader& e)
|
||||
void MStyle::load(XmlReader& e, compat::ReadChordListHook* readChordListHook)
|
||||
{
|
||||
TRACEFUNC;
|
||||
QString oldChordDescriptionFile = value(Sid::chordDescriptionFile).toString();
|
||||
bool chordListTag = false;
|
||||
|
||||
while (e.readNextStartElement()) {
|
||||
const QStringRef& tag(e.name());
|
||||
|
||||
|
@ -328,10 +305,9 @@ void MStyle::load(XmlReader& e)
|
|||
} else if (tag == "displayInConcertPitch") {
|
||||
set(Sid::concertPitch, QVariant(bool(e.readInt())));
|
||||
} else if (tag == "ChordList") {
|
||||
m_chordList.unload();
|
||||
m_chordList.read(e);
|
||||
m_customChordList = true;
|
||||
chordListTag = true;
|
||||
if (readChordListHook) {
|
||||
readChordListHook->read(e);
|
||||
}
|
||||
} else if (tag == "lyricsDashMaxLegth") { // pre-3.6 typo
|
||||
set(Sid::lyricsDashMaxLength, e.readDouble());
|
||||
} else if (tag == "dontHidStavesInFirstSystm") { // pre-3.6.3/4.0 typo
|
||||
|
@ -341,33 +317,12 @@ void MStyle::load(XmlReader& e)
|
|||
}
|
||||
}
|
||||
|
||||
// if we just specified a new chord description file
|
||||
// and didn't encounter a ChordList tag
|
||||
// then load the chord description file
|
||||
|
||||
QString newChordDescriptionFile = value(Sid::chordDescriptionFile).toString();
|
||||
if (newChordDescriptionFile != oldChordDescriptionFile && !chordListTag) {
|
||||
if (!newChordDescriptionFile.startsWith("chords_") && value(Sid::chordStyle).toString() == "std") {
|
||||
// should not normally happen,
|
||||
// but treat as "old" (114) score just in case
|
||||
set(Sid::chordStyle, QVariant(QString("custom")));
|
||||
set(Sid::chordsXmlFile, QVariant(true));
|
||||
qDebug("StyleData::load: custom chord description file %s with chordStyle == std", qPrintable(newChordDescriptionFile));
|
||||
}
|
||||
if (value(Sid::chordStyle).toString() == "custom") {
|
||||
m_customChordList = true;
|
||||
} else {
|
||||
m_customChordList = false;
|
||||
}
|
||||
m_chordList.unload();
|
||||
}
|
||||
|
||||
if (!chordListTag) {
|
||||
checkChordList();
|
||||
if (readChordListHook) {
|
||||
readChordListHook->validate();
|
||||
}
|
||||
}
|
||||
|
||||
void MStyle::save(XmlWriter& xml, bool optimize)
|
||||
void MStyle::save(XmlWriter& xml, bool optimize, compat::WriteChordListHook* writeChordListHook)
|
||||
{
|
||||
xml.stag("Style");
|
||||
|
||||
|
@ -411,11 +366,11 @@ void MStyle::save(XmlWriter& xml, bool optimize)
|
|||
xml.tag(st.name(), value(idx));
|
||||
}
|
||||
}
|
||||
if (m_customChordList && !m_chordList.empty()) {
|
||||
xml.stag("ChordList");
|
||||
m_chordList.write(xml);
|
||||
xml.etag();
|
||||
|
||||
if (writeChordListHook) {
|
||||
writeChordListHook->write(xml);
|
||||
}
|
||||
|
||||
xml.tag("Spatium", value(Sid::spatium).toDouble() / DPMM);
|
||||
xml.etag();
|
||||
}
|
||||
|
|
|
@ -23,11 +23,12 @@
|
|||
#ifndef MU_ENGRAVING_STYLE_H
|
||||
#define MU_ENGRAVING_STYLE_H
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <array>
|
||||
#include <QFile>
|
||||
#include <QSet>
|
||||
|
||||
#include "libmscore/chordlist.h"
|
||||
#include "libmscore/types.h"
|
||||
#include "libmscore/spatium.h"
|
||||
|
||||
|
@ -35,9 +36,14 @@
|
|||
|
||||
#include "styledef.h"
|
||||
|
||||
namespace mu::engraving::compat {
|
||||
struct ReadChordListHook;
|
||||
struct WriteChordListHook;
|
||||
}
|
||||
|
||||
namespace Ms {
|
||||
class XmlReader;
|
||||
class XmlWriter;
|
||||
struct ChordDescription;
|
||||
|
||||
class MStyle
|
||||
{
|
||||
|
@ -63,14 +69,9 @@ public:
|
|||
void setDefaultStyleVersion(const int defaultsVersion);
|
||||
int defaultStyleVersion() const;
|
||||
|
||||
const ChordDescription* chordDescription(int id) const;
|
||||
ChordList* chordList() { return &m_chordList; }
|
||||
void setCustomChordList(bool t) { m_customChordList = t; }
|
||||
void checkChordList();
|
||||
|
||||
bool load(QFile* qf, bool ign = false);
|
||||
void load(XmlReader& e);
|
||||
void save(XmlWriter& xml, bool optimize);
|
||||
void load(XmlReader& e, mu::engraving::compat::ReadChordListHook* readChordListHook);
|
||||
void save(XmlWriter& xml, bool optimize, mu::engraving::compat::WriteChordListHook* writeChordListHook);
|
||||
bool readProperties(XmlReader&);
|
||||
|
||||
void precomputeValues();
|
||||
|
@ -86,8 +87,6 @@ private:
|
|||
std::array<QVariant, int(Sid::STYLES)> m_values;
|
||||
std::array<qreal, int(Sid::STYLES)> m_precomputedValues;
|
||||
|
||||
ChordList m_chordList;
|
||||
bool m_customChordList = false; // if true, chordlist will be saved as part of score
|
||||
int m_defaultStyleVersion = -1;
|
||||
};
|
||||
} // namespace Ms
|
||||
|
|
|
@ -404,7 +404,7 @@ Score::FileError importBB(MasterScore* score, const QString& name)
|
|||
return Score::FileError::FILE_OPEN_ERROR;
|
||||
}
|
||||
score->style().set(Sid::chordsXmlFile, true);
|
||||
score->style().chordList()->read("chords.xml");
|
||||
score->chordList()->read("chords.xml");
|
||||
*(score->sigmap()) = bb.siglist();
|
||||
|
||||
QList<BBTrack*>* tracks = bb.tracks();
|
||||
|
|
|
@ -173,7 +173,7 @@ mu::Ret MasterNotation::setupNewScore(Ms::MasterScore* score, Ms::MasterScore* t
|
|||
|
||||
setScore(score);
|
||||
|
||||
score->style().checkChordList();
|
||||
score->checkChordList();
|
||||
|
||||
Ms::Fraction timesig(scoreOptions.timesigNumerator, scoreOptions.timesigDenominator);
|
||||
score->sigmap()->add(0, timesig);
|
||||
|
|
Loading…
Reference in a new issue