-
Notifications
You must be signed in to change notification settings - Fork 2.9k
MusicXML: add support for numerals #24174
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
36b7b55
export and import numerals
rettinghaus 82529de
update and add test
rettinghaus 2176f2a
simplify
rettinghaus 8e00a57
switch to std::regex
rettinghaus 5273efb
remove wrong imports
rettinghaus cae6390
use string empty
rettinghaus c0205f5
fix strings
rettinghaus 398dc5a
fix rebase
rettinghaus 82a8474
improve support for roman numerals
rettinghaus bb62886
add test file
rettinghaus 12240a1
get number from roman numerals
rettinghaus 8167bd6
fix
rettinghaus 206e2ff
update test file
rettinghaus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5946,35 +5946,35 @@ static void directionJump(XmlWriter& xml, const Jump* const jp) | |
bool isDaCapo = false; | ||
bool isDalSegno = false; | ||
if (jtp == JumpType::DC) { | ||
if (jp->xmlText() == "") { | ||
if (jp->xmlText().empty()) { | ||
words = u"D.C."; | ||
} else { | ||
words = jp->xmlText(); | ||
} | ||
isDaCapo = true; | ||
} else if (jtp == JumpType::DC_AL_FINE) { | ||
if (jp->xmlText() == "") { | ||
if (jp->xmlText().empty()) { | ||
words = u"D.C. al Fine"; | ||
} else { | ||
words = jp->xmlText(); | ||
} | ||
isDaCapo = true; | ||
} else if (jtp == JumpType::DC_AL_CODA) { | ||
if (jp->xmlText() == "") { | ||
if (jp->xmlText().empty()) { | ||
words = u"D.C. al Coda"; | ||
} else { | ||
words = jp->xmlText(); | ||
} | ||
isDaCapo = true; | ||
} else if (jtp == JumpType::DS_AL_CODA) { | ||
if (jp->xmlText() == "") { | ||
if (jp->xmlText().empty()) { | ||
words = u"D.S. al Coda"; | ||
} else { | ||
words = jp->xmlText(); | ||
} | ||
isDalSegno = true; | ||
} else if (jtp == JumpType::DS_AL_FINE) { | ||
if (jp->xmlText() == "") { | ||
if (jp->xmlText().empty()) { | ||
words = u"D.S. al Fine"; | ||
} else { | ||
words = jp->xmlText(); | ||
|
@@ -5996,7 +5996,7 @@ static void directionJump(XmlWriter& xml, const Jump* const jp) | |
if (isDaCapo) { | ||
sound = u"dacapo=\"yes\""; | ||
} else if (isDalSegno) { | ||
if (jp->jumpTo() == "") { | ||
if (jp->xmlText().empty()) { | ||
sound = u"dalsegno=\"1\""; | ||
} else { | ||
sound = u"dalsegno=\"" + jp->jumpTo() + u"\""; | ||
|
@@ -8683,7 +8683,7 @@ void ExportMusicXml::harmony(Harmony const* const h, FretDiagram const* const fd | |
if (!h->xmlKind().isEmpty()) { | ||
String s = u"kind"; | ||
String kindText = h->musicXmlText(); | ||
if (h->musicXmlText() != u"") { | ||
if (!h->musicXmlText().empty()) { | ||
s += u" text=\"" + kindText + u"\""; | ||
} | ||
if (h->xmlSymbols() == u"yes") { | ||
|
@@ -8781,16 +8781,83 @@ void ExportMusicXml::harmony(Harmony const* const h, FretDiagram const* const fd | |
const String textName = h->hTextName(); | ||
switch (h->harmonyType()) { | ||
case HarmonyType::NASHVILLE: { | ||
m_xml.tag("function", h->hFunction()); | ||
m_xml.tag("kind", { { "text", textName } }, "none"); | ||
String alter; | ||
String functionText = h->hFunction(); | ||
if (functionText.empty()) { | ||
// we just dump the text as deprecated function | ||
m_xml.tag("function", textName); | ||
m_xml.tag("kind", "none"); | ||
break; | ||
} else if (!functionText.at(0).isDigit()) { | ||
alter = functionText.at(0); | ||
functionText = functionText.at(1); | ||
} | ||
m_xml.startElement("numeral"); | ||
m_xml.tag("numeral-root", functionText); | ||
if (alter == u"b") { | ||
m_xml.tag("numeral-alter", "-1"); | ||
} else if (alter == u"#") { | ||
m_xml.tag("numeral-alter", "1"); | ||
} | ||
m_xml.endElement(); | ||
if (!h->xmlKind().isEmpty()) { | ||
String s = u"kind"; | ||
String kindText = h->musicXmlText(); | ||
if (!h->musicXmlText().empty()) { | ||
s += u" text=\"" + kindText + u"\""; | ||
} | ||
if (h->xmlSymbols() == "yes") { | ||
s += u" use-symbols=\"yes\""; | ||
} | ||
if (h->xmlParens() == "yes") { | ||
s += u" parentheses-degrees=\"yes\""; | ||
} | ||
m_xml.tagRaw(s, h->xmlKind()); | ||
} else { | ||
// default is major | ||
m_xml.tag("kind", "major"); | ||
} | ||
} | ||
break; | ||
case HarmonyType::ROMAN: { | ||
// TODO: parse? | ||
m_xml.tag("function", h->hTextName()); // note: HTML escape done by tag() | ||
m_xml.tag("kind", { { "text", "" } }, "none"); | ||
int alter = 0; | ||
static const std::wregex roman(L"(b|#)?([ivIV]+)"); | ||
if (textName.contains(roman)) { | ||
StringList matches = textName.search(roman, { 1, 2 }); | ||
m_xml.startElement("numeral"); | ||
if (matches.at(0) == u"b") { | ||
alter = -1; | ||
} else if (matches.at(0) == u"#") { | ||
alter = 1; | ||
} | ||
const String numberStr = matches.at(1); | ||
size_t harmoy = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is just a name, but isn't is supposed to be |
||
if (numberStr.contains(u"v", CaseSensitivity::CaseInsensitive)) { | ||
if (numberStr.startsWith(u"i", CaseSensitivity::CaseInsensitive)) { | ||
harmoy = 4; | ||
} else { | ||
harmoy = 4 + numberStr.size(); | ||
} | ||
} else { | ||
harmoy = numberStr.size(); | ||
} | ||
m_xml.tag("numeral-root", { { "text", numberStr } }, harmoy); | ||
if (alter) { | ||
m_xml.tag("numeral-alter", alter); | ||
} | ||
m_xml.endElement(); | ||
// simple check for major or minor | ||
m_xml.tag("kind", numberStr.at(0).isUpper() ? "major" : "minor"); | ||
// infer inversion from ending digits | ||
if (textName.endsWith(u"64")) { | ||
m_xml.tag("inversion", 2); | ||
} else if (textName.endsWith(u"6")) { | ||
m_xml.tag("inversion", 1); | ||
} | ||
break; | ||
} | ||
} | ||
break; | ||
// fallthrough | ||
case HarmonyType::STANDARD: | ||
default: { | ||
m_xml.startElement("root"); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can someone (@cbjeukendrup?) explain to me what exactly this does? I don't understand the code in src/framework/global/types/string.cpp, and esp. not how to do this with plain Qt methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks for the parts of the regex (in parentheses) and stores them in the string list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'parts of the regex' ? So splits the b or # from i, v, I, V ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But this could surely be done in other ways.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now resorted to use
textName.at(0)
for the first andtextName.mid(alter? 1 : 0)
on the (potential) 2nd part of the expression, IMHO a lot simpler