Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expansion of chord symbol formatting #5246

Merged
merged 7 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fonts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ This directory contains the fonts used internally by MuseScore and the sources u
* **bravura** The [_Bravura_](http://www.smufl.org/fonts/) fonts and the documentation for them and for SMuFL. These fonts are **not** maintained by the MuseScore community, please **DO NOT EDIT** these fonts.
* **gootville** The [_Gonville_ font](http://www.chiark.greenend.org.uk/~sgtatham/gonville/) for score musical symbols. This font is modified and maintained by the MuseScore project.
* **mscore** The main font used in MuseScore scores for musical symbols (formerly known as [_Emmentaler_](http://lilypond.org/doc/v2.18/Documentation/notation/the-feta-font)), as well its counterpart used for texts.
* **musejazz** The _MuseJazz_ and _MuseJazzText_ fonts used for notation and text in a handwritten style. These are maintained by the MuseScore project.
* **campania** The [_Campania_](https://github.com/MarcSabatella/Campania) font for Roman numeral analysis. This font is not maintained by the MuseScore project, but it is open source and contributions from the MuseScore community are encouraged at the main site for the font.

Other files in the main **fonts** directories are for collateral fonts used by MuseScore for specific tasks. If an *.sfd* file is present, the font is maintained/customized by the MuseScore community.

Expand Down
Binary file added fonts/campania/Campania.otf
Binary file not shown.
93 changes: 93 additions & 0 deletions fonts/campania/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Copyright (c) 2019, Marc Sabatella, with Reserved Font Name Campania.

This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
115 changes: 109 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
anatoly-os marked this conversation as resolved.
Show resolved Hide resolved
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
anatoly-os marked this conversation as resolved.
Show resolved Hide resolved
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
// currently 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,22 @@ 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") {
QString nmag = e.attribute("mag");
_nmag = nmag.toDouble();
QString nadjust = e.attribute("adjust");
_nadjust = nadjust.toDouble();
_autoAdjust = e.readBool();
}
else if (tag == "token") {
ChordToken t;
t.read(e);
Expand Down Expand Up @@ -1645,6 +1741,8 @@ void ChordList::read(XmlReader& e)
}
else if (tag == "renderRoot")
readRenderList(e.readElementText(), renderListRoot);
else if (tag == "renderFunction")
readRenderList(e.readElementText(), renderListFunction);
else if (tag == "renderBase")
readRenderList(e.readElementText(), renderListBase);
else
Expand Down Expand Up @@ -1673,10 +1771,14 @@ void ChordList::write(XmlWriter& xml) const
xml.etag();
++fontIdx;
}
if (_autoAdjust)
xml.tagE(QString("autoAdjust mag=\"%1\" adjust=\"%2\"").arg(_nmag).arg(_nadjust));
foreach (ChordToken t, chordTokenList)
t.write(xml);
if (!renderListRoot.empty())
writeRenderList(xml, &renderListRoot, "renderRoot");
if (!renderListFunction.empty())
writeRenderList(xml, &renderListRoot, "renderFunction");
if (!renderListBase.empty())
writeRenderList(xml, &renderListBase, "renderBase");
for (const ChordDescription& cd : *this)
Expand Down Expand Up @@ -1795,6 +1897,7 @@ void ChordList::unload()
renderListRoot.clear();
renderListBase.clear();
chordTokenList.clear();
_autoAdjust = false;
}

//---------------------------------------------------------
Expand Down
12 changes: 12 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,14 +229,25 @@ struct ChordFont {

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

public:
QList<ChordFont> fonts;
QList<RenderAction> renderListRoot;
QList<RenderAction> renderListFunction;
QList<RenderAction> renderListBase;
QList<ChordToken> chordTokenList;
static int privateID;

bool autoAdjust() const { return _autoAdjust; }
qreal nominalMag() const { return _nmag; }
qreal nominalAdjust() const { return _nadjust; }
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
Loading