Skip to content

Commit

Permalink
style settings for chord symbol formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcSabatella committed Aug 27, 2019
1 parent 0b55077 commit 800c89a
Show file tree
Hide file tree
Showing 13 changed files with 990 additions and 35 deletions.
107 changes: 101 additions & 6 deletions libmscore/chordlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,16 +295,25 @@ static void readRenderList(QString val, QList<RenderAction>& renderList)
{
renderList.clear();
QStringList sl = val.split(" ", QString::SkipEmptyParts);
foreach(const QString& s, sl) {
for (const QString& s : sl) {
if (s.startsWith("m:")) {
QStringList ssl = s.split(":", QString::SkipEmptyParts);
if (ssl.size() == 3) {
// m:x:y
RenderAction a;
a.type = RenderAction::RenderActionType::MOVE;
a.movex = ssl[1].toDouble();
a.movey = ssl[2].toDouble();
renderList.append(a);
}
#if 0
else if (ssl.size() == 2) {
// m:keyword
RenderAction a;
a.type = RenderAction::RenderActionType::MOVE;
// TODO: derive offset from keyword
}
#endif
}
else if (s == ":push")
renderList.append(RenderAction(RenderAction::RenderActionType::PUSH));
Expand Down Expand Up @@ -607,9 +616,9 @@ bool ParsedChord::parse(const QString& s, const ChordList* cl, bool syntaxOnly,
addToken(QString(s[i++]),ChordTokenClass::EXTENSION);
#endif
lastLeadingToken = _tokenList.size();
// get extension - up to first non-digit
// get extension - up to first non-digit other than comma or slash
for (j = 0, tok1 = ""; i < len; ++i, ++j) {
if (!s[i].isDigit())
if (!s[i].isDigit() && s[i] != ',' && s[i] != '/')
break;
tok1[j] = s[i];
}
Expand Down Expand Up @@ -745,7 +754,7 @@ bool ParsedChord::parse(const QString& s, const ChordList* cl, bool syntaxOnly,
chord += 5;
chord += 9;
}
else if (tok1 == "69") {
else if (tok1 == "69" || tok1 == "6,9" || tok1 == "6/9") {
if (take6) {
_xmlKind += "-sixth";
extl << "9";
Expand Down Expand Up @@ -1370,6 +1379,32 @@ QString ParsedChord::fromXml(const QString& rawKind, const QString& rawKindText,
return _name;
}


//---------------------------------------------------------
// position
//---------------------------------------------------------

qreal ChordList::position(const QStringList& names, ChordTokenClass ctc) const
{
QString name = names.empty() ? "" : names.first();
switch (ctc) {
case ChordTokenClass::EXTENSION:
return _eadjust;
case ChordTokenClass::MODIFIER: {
QChar c = name.isEmpty() ? name.at(0) : '0';
if (c.isDigit() || c.isPunct())
return _madjust;
else
return 0.0;
}
default:
if (name == "o" || name == "0")
return _eadjust;
else
return 0.0;
}
}

//---------------------------------------------------------
// renderList
//---------------------------------------------------------
Expand All @@ -1380,7 +1415,8 @@ const QList<RenderAction>& ParsedChord::renderList(const ChordList* cl)
// in case chord list has changed since last time
if (!_renderList.empty())
_renderList.clear();
foreach (ChordToken tok, _tokenList) {
bool adjust = cl->autoAdjust();
for (ChordToken tok : _tokenList) {
QString n = tok.names.first();
QList<RenderAction> rl;
QList<ChordToken> definedTokens;
Expand All @@ -1395,9 +1431,11 @@ const QList<RenderAction>& ParsedChord::renderList(const ChordList* cl)
}
}
// find matching class, fallback on ChordTokenClass::ALL
ChordTokenClass ctc = ChordTokenClass::ALL;
for (ChordToken matchingTok : definedTokens) {
if (tok.tokenClass == matchingTok.tokenClass) {
rl = matchingTok.renderList;
ctc = tok.tokenClass;
found = true;
break;
}
Expand All @@ -1406,14 +1444,33 @@ const QList<RenderAction>& ParsedChord::renderList(const ChordList* cl)
found = true;
}
}
if (found)
// check for adjustments
// stop adjusting when first non-adjusted modifier found
qreal p = adjust ? cl->position(tok.names, ctc) : 0.0;
if (tok.tokenClass == ChordTokenClass::MODIFIER && p == 0.0)
adjust = false;
// build render list
if (p != 0.0) {
RenderAction m1 = RenderAction(RenderAction::RenderActionType::MOVE);
m1.movex = 0.0;
m1.movey = p;
_renderList.append(m1);
}
if (found) {
_renderList.append(rl);
}
else {
// no definition for token, so render as literal
RenderAction a(RenderAction::RenderActionType::SET);
a.text = tok.names.first();
_renderList.append(a);
}
if (p != 0.0) {
RenderAction m2 = RenderAction(RenderAction::RenderActionType::MOVE);
m2.movex = 0.0;
m2.movey = -p;
_renderList.append(m2);
}
}
return _renderList;
}
Expand Down Expand Up @@ -1559,13 +1616,38 @@ void ChordDescription::write(XmlWriter& xml) const

int ChordList::privateID = -1000;

//---------------------------------------------------------
// configureAutoAdjust
//---------------------------------------------------------

void ChordList::configureAutoAdjust(qreal emag, qreal eadjust, qreal mmag, qreal madjust)
{
_emag = emag;
_eadjust = eadjust;
_mmag = mmag;
_madjust = madjust;
#if 0
// TODO: regenerate all chord descriptions
// current we always reload the entire chordlist
if (_autoAdjust) {
for (ChordFont cf : fonts) {
if (cf.fontClass == "extension")
cf.mag = _emag;
else if (cf.fontClass == "modifier")
cf.mag = _mmag;
}
}
#endif
}

//---------------------------------------------------------
// read
//---------------------------------------------------------

void ChordList::read(XmlReader& e)
{
int fontIdx = 0;
_autoAdjust = false;
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "font") {
Expand All @@ -1574,6 +1656,7 @@ void ChordList::read(XmlReader& e)
if (f.family == "MuseJazz")
f.family = "MuseJazz Text";
f.mag = 1.0;
f.fontClass = e.attribute("class");
while (e.readNextStartElement()) {
if (e.name() == "sym") {
ChordSymbol cs;
Expand Down Expand Up @@ -1615,9 +1698,18 @@ void ChordList::read(XmlReader& e)
else
e.unknown();
}
if (_autoAdjust) {
if (f.fontClass == "extension")
f.mag *= _emag;
else if (f.fontClass == "modifier")
f.mag *= _mmag;
}
fonts.append(f);
++fontIdx;
}
else if (tag == "autoAdjust") {
_autoAdjust = e.readBool();
}
else if (tag == "token") {
ChordToken t;
t.read(e);
Expand Down Expand Up @@ -1673,6 +1765,8 @@ void ChordList::write(XmlWriter& xml) const
xml.etag();
++fontIdx;
}
if (_autoAdjust)
xml.tag("autoAdjust", true);
foreach (ChordToken t, chordTokenList)
t.write(xml);
if (!renderListRoot.empty())
Expand Down Expand Up @@ -1795,6 +1889,7 @@ void ChordList::unload()
renderListRoot.clear();
renderListBase.clear();
chordTokenList.clear();
_autoAdjust = false;
}

//---------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions libmscore/chordlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ struct ChordSymbol {

struct ChordFont {
QString family;
QString fontClass;
qreal mag;
};

Expand All @@ -228,6 +229,9 @@ struct ChordFont {

class ChordList : public QMap<int, ChordDescription> {
QMap<QString, ChordSymbol> symbols;
bool _autoAdjust = false;
qreal _emag, _eadjust;
qreal _mmag, _madjust;

public:
QList<ChordFont> fonts;
Expand All @@ -236,6 +240,10 @@ class ChordList : public QMap<int, ChordDescription> {
QList<ChordToken> chordTokenList;
static int privateID;

bool autoAdjust() const { return _autoAdjust; }
void configureAutoAdjust(qreal emag = 1.0, qreal eadjust = 0.0, qreal mmag = 1.0, qreal madjust = 0.0);
qreal position(const QStringList& names, ChordTokenClass ctc) const;

void write(XmlWriter& xml) const;
void read(XmlReader&);
bool read(const QString&);
Expand Down
9 changes: 9 additions & 0 deletions libmscore/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ static const StyleType styleTypes[] {
{ Sid::chordStyle, "chordStyle", QVariant(QString("std")) },
{ Sid::chordsXmlFile, "chordsXmlFile", QVariant(false) },
{ Sid::chordDescriptionFile, "chordDescriptionFile", QVariant(QString("chords_std.xml")) },
{ Sid::chordExtensionMag, "chordExtensionMag", QVariant(1.0) },
{ Sid::chordExtensionAdjust, "chordExtensionAdjust", QVariant(0.0) },
{ Sid::chordModifierMag, "chordModifierMag", QVariant(1.0) },
{ Sid::chordModifierAdjust, "chordModifierAdjust", QVariant(0.0) },
{ Sid::concertPitch, "concertPitch", QVariant(false) },

{ Sid::createMultiMeasureRests, "createMultiMeasureRests", QVariant(false) },
Expand Down Expand Up @@ -2227,6 +2231,11 @@ void MStyle::checkChordList()
{
// make sure we have a chordlist
if (!_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();
_chordList.configureAutoAdjust(emag, eadjust, mmag, madjust);
if (value(Sid::chordsXmlFile).toBool())
_chordList.read("chords.xml");
_chordList.read(value(Sid::chordDescriptionFile).toString());
Expand Down
4 changes: 4 additions & 0 deletions libmscore/style.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ enum class Sid {
chordStyle,
chordsXmlFile,
chordDescriptionFile,
chordExtensionMag,
chordExtensionAdjust,
chordModifierMag,
chordModifierAdjust,
concertPitch,
createMultiMeasureRests,
minEmptyMeasures,
Expand Down
24 changes: 19 additions & 5 deletions libmscore/undo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1507,11 +1507,25 @@ void ChangeStyleVal::flip(EditData*)
QVariant v = score->styleV(idx);
if (v != value) {
score->style().set(idx, value);
if (idx == Sid::chordDescriptionFile) {
score->style().chordList()->unload();
if (score->styleB(Sid::chordsXmlFile))
score->style().chordList()->read("chords.xml");
score->style().chordList()->read(value.toString());
switch (idx) {
case Sid::chordExtensionMag:
case Sid::chordExtensionAdjust:
case Sid::chordModifierMag:
case Sid::chordModifierAdjust:
case Sid::chordDescriptionFile: {
score->style().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);
if (score->styleB(Sid::chordsXmlFile))
score->style().chordList()->read("chords.xml");
score->style().chordList()->read(score->styleSt(Sid::chordDescriptionFile));
}
break;
default:
break;
}
score->styleChanged();
}
Expand Down
6 changes: 6 additions & 0 deletions mscore/editstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ EditStyle::EditStyle(Score* s, QWidget* parent)
{ Sid::repeatBarlineDotSeparation, false, repeatBarlineDotSeparation, resetRepeatBarlineDotSeparation },

{ Sid::barGraceDistance, false, barGraceDistance, resetBarGraceDistance },
{ Sid::chordExtensionMag, false, extensionMag, resetExtensionMag },
{ Sid::chordExtensionAdjust, false, extensionAdjust, resetExtensionAdjust },
{ Sid::chordModifierMag, false, modifierMag, resetModifierMag },
{ Sid::chordModifierAdjust, false, modifierAdjust, resetModifierAdjust },
{ Sid::useStandardNoteNames, false, useStandardNoteNames, 0 },
{ Sid::useGermanNoteNames, false, useGermanNoteNames, 0 },
{ Sid::useFullGermanNoteNames, false, useFullGermanNoteNames, 0 },
Expand Down Expand Up @@ -1076,6 +1080,7 @@ void EditStyle::setValues()
chordsCustom->setChecked(true);
chordDescriptionGroup->setEnabled(true);
}
//formattingGroup->setEnabled(lstyle.chordList()->autoAdjust());

dontHideStavesInFirstSystem->setEnabled(hideEmptyStaves->isChecked());

Expand Down Expand Up @@ -1200,6 +1205,7 @@ void EditStyle::setChordStyle(bool checked)
cs->undo(new ChangeStyleVal(cs, Sid::chordDescriptionFile, file));
cs->update();
}
//formattingGroup->setEnabled(cs->style().chordList()->autoAdjust());
}

//---------------------------------------------------------
Expand Down
Loading

0 comments on commit 800c89a

Please sign in to comment.