Skip to content

Commit

Permalink
Fix musescore#15903: Added MusicXML support for some accidentals
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantAntony committed May 7, 2023
1 parent 07629d8 commit 2605b30
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 46 deletions.
15 changes: 12 additions & 3 deletions src/importexport/musicxml/internal/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,12 @@ void ExportMusicXml::keysig(const KeySig* ks, ClefType ct, staff_idx_t staff, bo
//LOGD(" keysym sym %d -> line %d step %d", ksym.sym, ksym.line, step);
_xml.tag("key-step", QString(QChar(table2[step])));
_xml.tag("key-alter", accSymId2alter(ksym.sym));
_xml.tag("key-accidental", accSymId2MxmlString(ksym.sym));
XmlWriter::Attributes accidentalAttrs;
QString s = accSymId2MxmlString(ksym.sym);
if (s == "other") {
accidentalAttrs = { { "smufl", accSymId2SmuflMxmlString(ksym.sym) } };
}
_xml.tag("key-accidental", accidentalAttrs, s);
}
} else {
// traditional key signature
Expand Down Expand Up @@ -2555,11 +2560,15 @@ static void writeAccidental(XmlWriter& xml, const QString& tagName, const Accide
if (acc) {
QString s = accidentalType2MxmlString(acc->accidentalType());
if (s != "") {
XmlWriter::Attributes attrs;
if (s == "other") {
attrs = { { "smufl", accidentalType2SmuflMxmlString(acc->accidentalType()) } };
}
QString tag = tagName;
if (acc->bracket() != AccidentalBracket::NONE) {
tag += " parentheses=\"yes\"";
attrs.emplace_back(std::make_pair("parentheses", "yes"));
}
xml.tagRaw(tag, s);
xml.tag(AsciiStringView(tag.toStdString()), attrs, s);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ static Accidental* accidental(QXmlStreamReader& e, Score* score)
bool cautionary = e.attributes().value("cautionary") == "yes";
bool editorial = e.attributes().value("editorial") == "yes";
bool parentheses = e.attributes().value("parentheses") == "yes";
QString smufl = e.attributes().value("smufl").toString();

const auto s = e.readElementText();
const auto type = mxmlString2accidentalType(s);
const auto type = mxmlString2accidentalType(s, smufl);

if (type != AccidentalType::NONE) {
auto a = Factory::createAccidental(score->dummy());
Expand Down
22 changes: 15 additions & 7 deletions src/importexport/musicxml/internal/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3658,18 +3658,24 @@ void MusicXMLParserPass2::doEnding(const QString& partId, Measure* measure, cons
Add a symbol defined as key-step \a step , -alter \a alter and -accidental \a accid to \a sig.
*/

static void addSymToSig(KeySigEvent& sig, const QString& step, const QString& alter, const QString& accid)
static void addSymToSig(KeySigEvent& sig, const QString& step, const QString& alter, const QString& accid,
const QString& smufl)
{
//LOGD("addSymToSig(step '%s' alt '%s' acc '%s')",
// qPrintable(step), qPrintable(alter), qPrintable(accid));

SymId id = mxmlString2accSymId(accid);
SymId id = mxmlString2accSymId(accid, smufl);

if (id == SymId::noSym) {
bool ok;
double d;
d = alter.toDouble(&ok);
AccidentalType accTpAlter = ok ? microtonalGuess(d) : AccidentalType::NONE;
id = mxmlString2accSymId(accidentalType2MxmlString(accTpAlter));
QString s = accidentalType2MxmlString(accTpAlter);
if (s == "other") {
s = accidentalType2SmuflMxmlString(accTpAlter);
}
id = mxmlString2accSymId(s);
}

if (step.size() == 1 && id != SymId::noSym) {
Expand Down Expand Up @@ -3719,7 +3725,7 @@ static void addKey(const KeySigEvent key, const bool printObj, Score* score, Mea
Clear key-step, -alter, -accidental.
*/

static void flushAlteredTone(KeySigEvent& kse, QString& step, QString& alt, QString& acc)
static void flushAlteredTone(KeySigEvent& kse, QString& step, QString& alt, QString& acc, QString& smufl)
{
//LOGD("flushAlteredTone(step '%s' alt '%s' acc '%s')",
// qPrintable(step), qPrintable(alt), qPrintable(acc));
Expand All @@ -3729,7 +3735,7 @@ static void flushAlteredTone(KeySigEvent& kse, QString& step, QString& alt, QStr
}
// step and alt are required, but also accept step and acc
if (step != "" && (alt != "" || acc != "")) {
addSymToSig(kse, step, alt, acc);
addSymToSig(kse, step, alt, acc, smufl);
} else {
LOGD("flushAlteredTone invalid combination of step '%s' alt '%s' acc '%s')",
qPrintable(step), qPrintable(alt), qPrintable(acc)); // TODO
Expand Down Expand Up @@ -3775,6 +3781,7 @@ void MusicXMLParserPass2::key(const QString& partId, Measure* measure, const Fra
QString keyStep;
QString keyAlter;
QString keyAccidental;
QString smufl;

while (_e.readNextStartElement()) {
if (_e.name() == "fifths") {
Expand Down Expand Up @@ -3808,17 +3815,18 @@ void MusicXMLParserPass2::key(const QString& partId, Measure* measure, const Fra
} else if (_e.name() == "cancel") {
skipLogCurrElem(); // TODO ??
} else if (_e.name() == "key-step") {
flushAlteredTone(key, keyStep, keyAlter, keyAccidental);
flushAlteredTone(key, keyStep, keyAlter, keyAccidental, smufl);
keyStep = _e.readElementText();
} else if (_e.name() == "key-alter") {
keyAlter = _e.readElementText();
} else if (_e.name() == "key-accidental") {
smufl = _e.attributes().value("smufl").toString();
keyAccidental = _e.readElementText();
} else {
skipLogCurrElem();
}
}
flushAlteredTone(key, keyStep, keyAlter, keyAccidental);
flushAlteredTone(key, keyStep, keyAlter, keyAccidental, smufl);

size_t nstaves = _pass1.getPart(partId)->nstaves();
staff_idx_t staffIdx = _pass1.trackForPart(partId) / VOICES;
Expand Down
Loading

0 comments on commit 2605b30

Please sign in to comment.