From 01150a8110e01802cd7bbd9c2f7e43246494f9d8 Mon Sep 17 00:00:00 2001 From: Igor Korsukov Date: Thu, 25 Jan 2024 15:30:41 +0100 Subject: [PATCH] [musicxml] Replaced QMap to std::map Backport of #21205, part 2 --- importexport/musicxml/exportxml.cpp | 75 ++--- importexport/musicxml/importmxmlpass1.cpp | 162 +++++------ importexport/musicxml/importmxmlpass1.h | 22 +- importexport/musicxml/importmxmlpass2.cpp | 279 +++++++++---------- importexport/musicxml/importmxmlpass2.h | 8 +- importexport/musicxml/importxmlfirstpass.cpp | 11 +- importexport/musicxml/importxmlfirstpass.h | 8 +- importexport/musicxml/musicxml.h | 2 +- importexport/musicxml/musicxmlsupport.cpp | 244 ++++++++-------- importexport/musicxml/musicxmlsupport.h | 7 +- 10 files changed, 410 insertions(+), 408 deletions(-) diff --git a/importexport/musicxml/exportxml.cpp b/importexport/musicxml/exportxml.cpp index 28926916dd7bd..af51a198df490 100644 --- a/importexport/musicxml/exportxml.cpp +++ b/importexport/musicxml/exportxml.cpp @@ -38,6 +38,8 @@ #include "config.h" +#include "global/containers.h" + #include "libmscore/accidental.h" #include "libmscore/arpeggio.h" #include "libmscore/articulation.h" @@ -130,7 +132,7 @@ namespace Ms { // typedefs //--------------------------------------------------------- -typedef QMap FigBassMap; +typedef std::map FigBassMap; //--------------------------------------------------------- // attributes -- prints tag when necessary @@ -313,7 +315,7 @@ struct MeasurePrintContext final //--------------------------------------------------------- typedef QHash TrillHash; -typedef QMap MxmlInstrumentMap; +typedef std::map MxmlInstrumentMap; class ExportMusicXml { Score* _score; @@ -2306,12 +2308,12 @@ void ExportMusicXml::keysig(const KeySig* ks, ClefType ct, int staff, bool visib // are in insertion order -> sorting required // first put the KeySyms in a map - QMap map; + std::map map; for (const KeySym& ksym : keysyms) { - map.insert(ksym.spos.x(), ksym); + map.insert({ ksym.spos.x(), ksym}); } // then write them (automatically sorted on key) - for (const KeySym& ksym : map) { + for (const KeySym& ksym : mu::values(map)) { int line = static_cast(round(2 * ksym.spos.y())); int step = (po - line) % 7; _xml.tag("key-step", QString(QChar(table2[step]))); @@ -3891,7 +3893,7 @@ void ExportMusicXml::chord(Chord* chord, int staff, const std::vector* { Part* part = chord->score()->staff(chord->track() / VOICES)->part(); int partNr = _score->parts().indexOf(part); - int instNr = instrMap.value(part->instrument(_tick), -1); + int instNr = mu::value(instrMap, part->instrument(_tick), -1); /* qDebug("chord() %p parent %p isgrace %d #gracenotes %d graceidx %d", chord, chord->parent(), chord->isGrace(), chord->graceNotes().size(), chord->graceIndex()); @@ -5971,10 +5973,10 @@ static void figuredBass(XmlWriter& xml, int strack, int etrack, int track, const if (extend) { //qDebug("figuredbass() extend to %d + %d = %d", // cr->tick(), fb->ticks(), cr->tick() + fb->ticks()); - fbMap.insert(strack, fb); + fbMap.insert({ strack, fb }); } else - fbMap.remove(strack); + mu::remove(fbMap, strack); const Fraction crEndTick = cr->tick() + cr->actualTicks(); const Fraction fbEndTick = fb->segment()->tick() + fb->ticks(); const bool writeDuration = fb->ticks() < cr->actualTicks(); @@ -5995,8 +5997,8 @@ static void figuredBass(XmlWriter& xml, int strack, int etrack, int track, const } } // check for extend pending - if (fbMap.contains(strack)) { - const FiguredBass* fb = fbMap.value(strack); + if (mu::contains(fbMap, strack)) { + const FiguredBass* fb = fbMap.at(strack); Fraction crEndTick = cr->tick() + cr->actualTicks(); Fraction fbEndTick = fb->segment()->tick() + fb->ticks(); bool writeDuration = fb->ticks() < cr->actualTicks(); @@ -6006,7 +6008,7 @@ static void figuredBass(XmlWriter& xml, int strack, int etrack, int track, const } if (fbEndTick <= crEndTick) { //qDebug("figuredbass() at tick %d extend done", cr->tick() + cr->actualTicks()); - fbMap.remove(strack); + mu::remove(fbMap, strack); } } } @@ -6140,7 +6142,7 @@ void ExportMusicXml::keysigTimesig(const Measure* m, const Part* p) //qDebug("keysigTimesig m %p strack %d etrack %d", m, strack, etrack); // search all staves for non-generated key signatures - QMap keysigs; // map staff to key signature + std::map keysigs; // map staff to key signature for (Segment* seg = m->first(); seg; seg = seg->next()) { if (seg->tick() > m->tick()) break; @@ -6160,31 +6162,31 @@ void ExportMusicXml::keysigTimesig(const Measure* m, const Part* p) //ClefType ct = rest->staff()->clef(rest->tick()); // write the key signatues - if (!keysigs.isEmpty()) { + if (!keysigs.empty()) { // determine if all staves have a keysig and all keysigs are identical // in that case a single is written, without number=... attribute int nstaves = p->nstaves(); bool singleKey = true; // check if all staves have a keysig for (int i = 0; i < nstaves; i++) - if (!keysigs.contains(i)) + if (!mu::contains(keysigs, i)) singleKey = false; // check if all keysigs are identical if (singleKey) for (int i = 1; i < nstaves; i++) - if (!(keysigs.value(i)->key() == keysigs.value(0)->key())) + if (!(keysigs.at(i)->key() == keysigs.at(0)->key())) singleKey = false; // write the keysigs //qDebug(" singleKey %d", singleKey); if (singleKey) { // keysig applies to all staves - keysig(keysigs.value(0), p->staff(0)->clef(m->tick()), 0, keysigs.value(0)->visible()); + keysig(keysigs.at(0), p->staff(0)->clef(m->tick()), 0, keysigs.at(0)->visible()); } else { // staff-specific keysigs - for (int st : keysigs.keys()) - keysig(keysigs.value(st), p->staff(st)->clef(m->tick()), st + 1, keysigs.value(st)->visible()); + for (int st : mu::keys(keysigs)) + keysig(keysigs.at(st), p->staff(st)->clef(m->tick()), st + 1, keysigs.at(st)->visible()); } } else { @@ -6200,7 +6202,7 @@ void ExportMusicXml::keysigTimesig(const Measure* m, const Part* p) } // search all staves for non-generated time signatures - QMap timesigs; // map staff to time signature + std::map timesigs; // map staff to time signature for (Segment* seg = m->first(); seg; seg = seg->next()) { if (seg->tick() > m->tick()) break; @@ -6226,7 +6228,7 @@ void ExportMusicXml::keysigTimesig(const Measure* m, const Part* p) bool singleTime = true; // check if all staves have a keysig for (size_t i = 0; i < nstaves; i++) { - if (!timesigs.contains(static_cast(i))) + if (!mu::contains(timesigs, static_cast(i))) singleTime = false; } // check if all timesigs are identical @@ -6245,7 +6247,7 @@ void ExportMusicXml::keysigTimesig(const Measure* m, const Part* p) } else { // staff-specific timesig - for (int st : timesigs.keys()) + for (int st : mu::keys(timesigs)) timesig(timesigs[st], st + 1); } } @@ -6368,8 +6370,8 @@ static void initInstrMap(MxmlInstrumentMap& im, const InstrumentList* il, const im.clear(); for (auto i = il->begin(); i != il->end(); ++i) { const Instrument* pinstr = i->second; - if (!im.contains(pinstr)) - im.insert(pinstr, im.size()); + if (!mu::contains(im, pinstr)) + im.insert({ pinstr, static_cast(im.size()) }); } } @@ -6377,7 +6379,7 @@ static void initInstrMap(MxmlInstrumentMap& im, const InstrumentList* il, const // initReverseInstrMap //--------------------------------------------------------- -typedef QMap MxmlReverseInstrumentMap; +typedef std::map MxmlReverseInstrumentMap; /** Initialize the number t Instrument* map for a Part @@ -6387,9 +6389,9 @@ typedef QMap MxmlReverseInstrumentMap; static void initReverseInstrMap(MxmlReverseInstrumentMap& rim, const MxmlInstrumentMap& im) { rim.clear(); - for (const Instrument* i : im.keys()) { - int instNr = im.value(i); - rim.insert(instNr, i); + for (const Instrument* i : mu::keys(im)) { + int instNr = im.at(i); + rim.insert({ instNr, i }); } } @@ -6839,19 +6841,22 @@ static void partList(XmlWriter& xml, Score* score, MxmlInstrumentMap& instrMap) else { MxmlReverseInstrumentMap rim; initReverseInstrMap(rim, instrMap); - for (int instNr : rim.keys()) { - scoreInstrument(xml, idx + 1, instNr + 1, MScoreTextToMXML::toPlainText(rim.value(instNr)->trackName()), rim.value(instNr)); + for (int instNr : mu::keys(rim)) { + const Instrument* instr = rim.at(instNr); + scoreInstrument(xml, idx + 1, instNr + 1, + MScoreTextToMXML::toPlainText(instr->trackName()), + instr); } - for (auto ii = rim.constBegin(); ii != rim.constEnd(); ii++) { - int instNr = ii.key(); + for (auto ii = rim.cbegin(); ii != rim.cend(); ii++) { + int instNr = ii->first; int midiPort = part->midiPort() + 1; - if (ii.value()->channel().size() > 0) - midiPort = score->masterScore()->midiMapping(ii.value()->channel(0)->channel())->port() + 1; + if (ii->second->channel().size() > 0) + midiPort = score->masterScore()->midiMapping(ii->second->channel(0)->channel())->port() + 1; if (midiPort >= 1 && midiPort <= 16) xml.tag(QString("midi-device %1 port=\"%2\"").arg(instrId(idx+1, instNr + 1)).arg(midiPort), ""); else xml.tag(QString("midi-device %1").arg(instrId(idx+1, instNr + 1)), ""); - midiInstrument(xml, idx + 1, instNr + 1, rim.value(instNr), score); + midiInstrument(xml, idx + 1, instNr + 1, rim.at(instNr), score); } } @@ -7391,7 +7396,7 @@ void ExportMusicXml::writeMeasure(const Measure* const m, if (staves > 1) _xml.tag("staves", staves); if (instrMap.size() > 1) - _xml.tag("instruments", instrMap.size()); + _xml.tag("instruments", static_cast(instrMap.size())); } // make sure clefs at end of measure get exported at start of next measure diff --git a/importexport/musicxml/importmxmlpass1.cpp b/importexport/musicxml/importmxmlpass1.cpp index 56f13540faac9..bfc9275c50f31 100644 --- a/importexport/musicxml/importmxmlpass1.cpp +++ b/importexport/musicxml/importmxmlpass1.cpp @@ -72,18 +72,18 @@ static void allocateStaves(VoiceList& vcLst) // handle regular (non-overlapping) voices // note: outer loop executed vcLst.size() times, as each inner loop handles exactly one item - for (int i = 0; i < vcLst.size(); ++i) { + for (size_t i = 0; i < vcLst.size(); ++i) { // find the regular voice containing the highest number of chords and rests that has not been handled yet int max = 0; int key = -1; - for (VoiceList::const_iterator j = vcLst.constBegin(); j != vcLst.constEnd(); ++j) { - if (!j.value().overlaps() && j.value().numberChordRests() > max && j.value().staff() == -1) { - max = j.value().numberChordRests(); - key = j.key(); + for (VoiceList::const_iterator j = vcLst.cbegin(); j != vcLst.cend(); ++j) { + if (!j->second.overlaps() && j->second.numberChordRests() > max && j->second.staff() == -1) { + max = j->second.numberChordRests(); + key = j->first; } } if (key > 0) { - int prefSt = vcLst.value(key).preferredStaff(); + int prefSt = mu::value(vcLst, key).preferredStaff(); if (voicesAllocated[prefSt] < VOICES) { vcLst[key].setStaff(prefSt); voicesAllocated[prefSt]++; @@ -99,14 +99,14 @@ static void allocateStaves(VoiceList& vcLst) // the ones with the highest number of chords and rests get allocated first for (int h = 0; h < MAX_VOICE_DESC_STAVES; ++h) { // note: middle loop executed vcLst.size() times, as each inner loop handles exactly one item - for (int i = 0; i < vcLst.size(); ++i) { + for (size_t i = 0; i < vcLst.size(); ++i) { // find the overlapping voice containing the highest number of chords and rests that has not been handled yet int max = 0; int key = -1; - for (VoiceList::const_iterator j = vcLst.constBegin(); j != vcLst.constEnd(); ++j) { - if (j.value().overlaps() && j.value().numberChordRests(h) > max && j.value().staffAlloc(h) == -1) { - max = j.value().numberChordRests(h); - key = j.key(); + for (VoiceList::const_iterator j = vcLst.cbegin(); j != vcLst.cend(); ++j) { + if (j->second.overlaps() && j->second.numberChordRests(h) > max && j->second.staffAlloc(h) == -1) { + max = j->second.numberChordRests(h); + key = j->first;; } } if (key > 0) { @@ -140,9 +140,9 @@ static void allocateVoices(VoiceList& vcLst) nextVoice[i] = 0; // handle regular (non-overlapping) voices // a voice is allocated on one specific staff - for (VoiceList::const_iterator i = vcLst.constBegin(); i != vcLst.constEnd(); ++i) { - int staff = i.value().staff(); - int key = i.key(); + for (VoiceList::const_iterator i = vcLst.cbegin(); i != vcLst.cend(); ++i) { + int staff = i->second.staff(); + int key = i->first; if (staff >= 0) { vcLst[key].setVoice(nextVoice[staff]); nextVoice[staff]++; @@ -150,10 +150,10 @@ static void allocateVoices(VoiceList& vcLst) } // handle overlapping voices // each voice may be in every staff - for (VoiceList::const_iterator i = vcLst.constBegin(); i != vcLst.constEnd(); ++i) { + for (VoiceList::const_iterator i = vcLst.cbegin(); i != vcLst.cend(); ++i) { for (int j = 0; j < MAX_VOICE_DESC_STAVES; ++j) { - int staffAlloc = i.value().staffAlloc(j); - int key = i.key(); + int staffAlloc = i->second.staffAlloc(j); + int key = i->first; if (staffAlloc >= 0) { vcLst[key].setVoice(j, nextVoice[j]); nextVoice[j]++; @@ -173,8 +173,8 @@ static void allocateVoices(VoiceList& vcLst) static void copyOverlapData(VoiceOverlapDetector& vod, VoiceList& vcLst) { - for (VoiceList::const_iterator i = vcLst.constBegin(); i != vcLst.constEnd(); ++i) { - int key = i.key(); + for (VoiceList::const_iterator i = vcLst.cbegin(); i != vcLst.cend(); ++i) { + int key = i->first; if (vod.stavesOverlap(key)) vcLst[key].setOverlap(true); } @@ -235,7 +235,7 @@ bool MusicXMLParserPass1::determineMeasureLength(std::vector& ml) cons // determine number of measures: max number of measures in any part size_t nMeasures = 0; - for (const MusicXmlPart &part : _parts) { + for (const MusicXmlPart &part : mu::values(_parts)) { if (part.nMeasures() > nMeasures) nMeasures = part.nMeasures(); } @@ -243,7 +243,7 @@ bool MusicXMLParserPass1::determineMeasureLength(std::vector& ml) cons // determine max length of a specific measure in all parts for (size_t i = 0; i < nMeasures; ++i) { Fraction maxMeasDur; - foreach (const MusicXmlPart &part, _parts) { + for (const MusicXmlPart &part : mu::values(_parts)) { if (i < part.nMeasures()) { Fraction measDurPartJ = part.measureDuration(i); if (measDurPartJ > maxMeasDur) @@ -267,8 +267,8 @@ bool MusicXMLParserPass1::determineMeasureLength(std::vector& ml) cons VoiceList MusicXMLParserPass1::getVoiceList(const QString id) const { - if (_parts.contains(id)) - return _parts.value(id).voicelist; + if (mu::contains(_parts, id)) + return _parts.at(id).voicelist; return VoiceList(); } @@ -283,8 +283,8 @@ VoiceList MusicXMLParserPass1::getVoiceList(const QString id) const MusicXmlInstrList MusicXMLParserPass1::getInstrList(const QString id) const { - if (_parts.contains(id)) - return _parts.value(id)._instrList; + if (mu::contains(_parts, id)) + return _parts.at(id)._instrList; return MusicXmlInstrList(); } @@ -299,8 +299,8 @@ MusicXmlInstrList MusicXMLParserPass1::getInstrList(const QString id) const MusicXmlIntervalList MusicXMLParserPass1::getIntervals(const QString id) const { - if (_parts.contains(id)) - return _parts.value(id)._intervals; + if (mu::contains(_parts, id)) + return _parts.at(id)._intervals; return MusicXmlIntervalList(); } @@ -320,8 +320,8 @@ void MusicXMLParserPass1::setDrumsetDefault(const QString& id, const int line, const Direction sd) { - if (_instruments.contains(id) - && _instruments[id].contains(instrId)) { + if (mu::contains(_instruments, id) + && mu::contains(_instruments.at(id), instrId)) { _instruments[id][instrId].notehead = hg; _instruments[id][instrId].line = line; _instruments[id][instrId].stemDirection = sd; @@ -363,17 +363,17 @@ bool MusicXMLParserPass1::determineStaffMoveVoice(const QString& id, const int m //qDebug("voice mapper before: voice='%s' staff=%d", qPrintable(mxVoice), mxStaff); int s; // staff mapped by voice mapper int v; // voice mapped by voice mapper - if (voicelist.value(mxVoice).overlaps()) { + if (mu::value(voicelist, mxVoice).overlaps()) { // for overlapping voices, the staff does not change // and the voice is mapped and staff-dependent s = mxStaff; - v = voicelist.value(mxVoice).voice(s); + v = mu::value(voicelist, mxVoice).voice(s); } else { // for non-overlapping voices, both staff and voice are // set by the voice mapper - s = voicelist.value(mxVoice).staff(); - v = voicelist.value(mxVoice).voice(); + s = mu::value(voicelist, mxVoice).staff(); + v = mu::value(voicelist, mxVoice).voice(); } //qDebug("voice mapper mapped: s=%d v=%d", s, v); @@ -387,7 +387,7 @@ bool MusicXMLParserPass1::determineStaffMoveVoice(const QString& id, const int m msVoice = v; // make score-relative instead on part-relative - Part* part = _partMap.value(id); + Part* part = mu::value(_partMap, id); if (!part) return false; int scoreRelStaff = _score->staffIdx(part); // zero-based number of parts first staff in the score @@ -411,7 +411,7 @@ bool MusicXMLParserPass1::determineStaffMoveVoice(const QString& id, const int m bool MusicXMLParserPass1::hasPart(const QString& id) const { - return _parts.contains(id); + return mu::contains(_parts, id); } //--------------------------------------------------------- @@ -424,7 +424,7 @@ bool MusicXMLParserPass1::hasPart(const QString& id) const int MusicXMLParserPass1::trackForPart(const QString& id) const { - Part* part = _partMap.value(id); + Part* part = mu::value(_partMap, id); if (!part) return -1; int scoreRelStaff = _score->staffIdx(part); // zero-based number of parts first staff in the score @@ -457,8 +457,8 @@ Fraction MusicXMLParserPass1::getMeasureStart(const size_t i) const int MusicXMLParserPass1::octaveShift(const QString& id, const int staff, const Fraction f) const { - if (_parts.contains(id)) - return _parts.value(id).octaveShift(staff, f); + if (mu::contains(_parts, id)) + return _parts.at(id).octaveShift(staff, f); return 0; } @@ -1291,7 +1291,7 @@ static QString text2syms(const QString& t) // caching does not gain much ScoreFont* sf = ScoreFont::fallbackFont(); - QMap map; + std::map map; int maxStringSize = 0; // maximum string size found for (int i = int(SymId::noSym); i < int(SymId::lastSym); ++i) { @@ -1299,7 +1299,7 @@ static QString text2syms(const QString& t) QString string(sf->toString(id)); // insert all syms except space to prevent matching all regular spaces if (id != SymId::space) - map.insert(string, id); + map.insert({ string, id }); if (string.size() > maxStringSize) maxStringSize = string.size(); } @@ -1316,8 +1316,8 @@ static QString text2syms(const QString& t) QString sym; while (maxMatch > 0) { QString toBeMatched = in.left(maxMatch); - if (map.contains(toBeMatched)) { - sym = Sym::id2name(map.value(toBeMatched)); + if (mu::contains(map, toBeMatched)) { + sym = Sym::id2name(map.at(toBeMatched)); break; } maxMatch--; @@ -1944,7 +1944,7 @@ void MusicXMLParserPass1::partList(MusicXmlPartGroupList& partGroupList) static void createPart(Score* score, const QString& id, PartMap& pm) { Part* part = new Part(score); - pm.insert(id, part); + pm.insert({ id, part }); part->setId(id); score->appendPart(part); Staff* staff = new Staff(score); @@ -2130,14 +2130,14 @@ void MusicXMLParserPass1::scorePart() _logger->logDebugTrace("MusicXMLParserPass1::scorePart", &_e); QString id = _e.attributes().value("id").toString().trimmed(); - if (_parts.contains(id)) { + if (mu::contains(_parts, id)) { _logger->logError(QString("duplicate part id '%1'").arg(id), &_e); skipLogCurrElem(); return; } else { - _parts.insert(id, MusicXmlPart(id)); - _instruments.insert(id, MusicXMLInstruments()); + _parts.insert({ id, MusicXmlPart(id) }); + _instruments.insert({ id, MusicXMLInstruments() }); createPart(_score, id, _partMap); } @@ -2203,9 +2203,9 @@ void MusicXMLParserPass1::scorePart() // score-instrument elements in the score-part if (instrId.isEmpty()) { for (auto it = _instruments[id].cbegin(); it != _instruments[id].cend(); ++it) - _instruments[id][it.key()].midiPort = port.toInt() - 1; + _instruments[id][it->first].midiPort = port.toInt() - 1; } - else if (_instruments[id].contains(instrId)) + else if (mu::contains(_instruments.at(id), instrId)) _instruments[id][instrId].midiPort = port.toInt() - 1; _e.readElementText(); // empty string @@ -2242,32 +2242,32 @@ void MusicXMLParserPass1::scoreInstrument(const QString& partId) qPrintable(instrName) ); */ - _instruments[partId].insert(instrId, MusicXMLInstrument(instrName)); + _instruments[partId].insert({ instrId, MusicXMLInstrument(instrName) }); // Element instrument-name is typically not displayed in the score, // but used only internally - if (_instruments[partId].contains(instrId)) + if (mu::contains(_instruments.at(partId),instrId)) _instruments[partId][instrId].name = instrName; } else if (_e.name() == "instrument-abbreviation") { QString abbreviation = _e.readElementText(); - if (_instruments[partId].contains(instrId)) + if (mu::contains(_instruments.at(partId), instrId)) _instruments[partId][instrId].abbreviation = abbreviation; } else if (_e.name() == "instrument-sound") { QString instrSound = _e.readElementText(); - if (_instruments[partId].contains(instrId)) + if (mu::contains(_instruments.at(partId), instrId)) _instruments[partId][instrId].sound = instrSound; } else if (_e.name() == "virtual-instrument") { while (_e.readNextStartElement()) { if (_e.name() == "virtual-library") { QString virtualLibrary = _e.readElementText(); - if (_instruments[partId].contains(instrId)) + if (mu::contains(_instruments.at(partId), instrId)) _instruments[partId][instrId].virtLib = virtualLibrary; } else if (_e.name() == "virtual-name") { QString virtualName = _e.readElementText(); - if (_instruments[partId].contains(instrId)) + if (mu::contains(_instruments.at(partId), instrId)) _instruments[partId][instrId].virtName = virtualName; } else @@ -2305,7 +2305,7 @@ void MusicXMLParserPass1::midiInstrument(const QString& partId) _logger->logError(QString("incorrect midi-channel: %1").arg(channel), &_e); channel = 16; } - if (_instruments[partId].contains(instrId)) + if (mu::contains(_instruments.at(partId), instrId)) _instruments[partId][instrId].midiChannel = channel - 1; } else if (_e.name() == "midi-program") { @@ -2320,17 +2320,17 @@ void MusicXMLParserPass1::midiInstrument(const QString& partId) _logger->logError(QString("incorrect midi-program: %1").arg(program), &_e); program = 128; } - if (_instruments[partId].contains(instrId)) + if (mu::contains(_instruments.at(partId), instrId)) _instruments[partId][instrId].midiProgram = program - 1; } else if (_e.name() == "midi-unpitched") { - if (_instruments[partId].contains(instrId)) + if (mu::contains(_instruments.at(partId), instrId)) _instruments[partId][instrId].unpitched = _e.readElementText().toInt() - 1; } else if (_e.name() == "volume") { double vol = _e.readElementText().toDouble(); if (vol >= 0 && vol <= 100) { - if (_instruments[partId].contains(instrId)) + if (mu::contains(_instruments.at(partId), instrId)) _instruments[partId][instrId].midiVolume = static_cast((vol / 100) * 127); } else @@ -2339,7 +2339,7 @@ void MusicXMLParserPass1::midiInstrument(const QString& partId) else if (_e.name() == "pan") { double pan = _e.readElementText().toDouble(); if (pan >= -90 && pan <= 90) { - if (_instruments[partId].contains(instrId)) + if (mu::contains(_instruments.at(partId), instrId)) _instruments[partId][instrId].midiPan = static_cast(((pan + 90) / 180) * 127); } else @@ -2388,7 +2388,7 @@ void MusicXMLParserPass1::part() _logger->logDebugTrace("MusicXMLParserPass1::part", &_e); const QString id = _e.attributes().value("id").toString().trimmed(); - if (!_parts.contains(id)) { + if (!mu::contains(_parts, id)) { _logger->logError(QString("cannot find part '%1'").arg(id), &_e); skipLogCurrElem(); return; @@ -2412,7 +2412,7 @@ void MusicXMLParserPass1::part() } // Bug fix for Cubase 6.5.5..9.5.10 which generate 2 in a single staff part - setNumberOfStavesForPart(_partMap.value(id), _parts[id].maxStaff() + 1); + setNumberOfStavesForPart(mu::value(_partMap, id), _parts[id].maxStaff() + 1); // allocate MuseScore staff to MusicXML voices allocateStaves(_parts[id].voicelist); // allocate MuseScore voice to MusicXML voices @@ -2712,20 +2712,20 @@ void MusicXMLParserPass1::attributes(const QString& partId, const Fraction cTime _logger->logError("staves exceed MAX_VOICE_DESC_STAVES, but hidden staves can be discarded", &_e); // Some scores have parts with many staves (~10), but most are hidden // When this occurs, we can discard hidden staves - // and store a QMap between staffNumber and staffIndex. + // and store a std::map between staffNumber and staffIndex. int staffNumber = 1; - int staffIndex = 0; + size_t staffIndex = 0; for (; staffNumber <= staves; ++staffNumber) { if (hiddenStaves.find(staffNumber) != hiddenStaves.end()) { _logger->logError(QString("removing hidden staff %1").arg(staffNumber), &_e); continue; } - _parts[partId].insertStaffNumberToIndex(staffNumber, staffIndex); + _parts[partId].insertStaffNumberToIndex(staffNumber, static_cast(staffIndex)); ++staffIndex; } Q_ASSERT(staffIndex == _parts[partId].staffNumberToIndex().size()); - setNumberOfStavesForPart(_partMap.value(partId), staves - static_cast(hiddenStaves.size())); + setNumberOfStavesForPart(mu::value(_partMap, partId), staves - static_cast(hiddenStaves.size())); } else { // Otherwise, don't discard any staves @@ -2733,11 +2733,11 @@ void MusicXMLParserPass1::attributes(const QString& partId, const Fraction cTime // (MuseScore doesn't currently have a mechanism // for hiding non-empty staves, so this is an approximation // of the correct implementation) - setNumberOfStavesForPart(_partMap.value(partId), staves); + setNumberOfStavesForPart(mu::value(_partMap, partId), staves); for (int hiddenStaff : hiddenStaves) { - int hiddenStaffIndex = _parts.value(partId).staffNumberToIndex(hiddenStaff); + int hiddenStaffIndex = mu::value(_parts, partId).staffNumberToIndex(hiddenStaff); if (hiddenStaffIndex >= 0) - _partMap.value(partId)->staff(hiddenStaffIndex)->setHideWhenEmpty(Staff::HideMode::AUTO); + mu::value(_partMap, partId)->staff(hiddenStaffIndex)->setHideWhenEmpty(Staff::HideMode::AUTO); } } } @@ -2940,8 +2940,8 @@ void MusicXMLParserPass1::direction(const QString& partId, const Fraction cTime) // handle the stops first for (const MxmlOctaveShiftDesc& desc : stops) { - if (_octaveShifts.contains(desc.num)) { - MxmlOctaveShiftDesc prevDesc = _octaveShifts.value(desc.num); + if (mu::contains(_octaveShifts, static_cast(desc.num))) { + MxmlOctaveShiftDesc prevDesc = _octaveShifts.at(desc.num); if (prevDesc.tp == MxmlOctaveShiftDesc::Type::UP || prevDesc.tp == MxmlOctaveShiftDesc::Type::DOWN) { // a complete pair @@ -2950,16 +2950,16 @@ void MusicXMLParserPass1::direction(const QString& partId, const Fraction cTime) } else _logger->logError("double octave-shift stop", &_e); - _octaveShifts.remove(desc.num); + mu::remove(_octaveShifts, desc.num); } else - _octaveShifts.insert(desc.num, desc); + _octaveShifts.insert({ desc.num, desc }); } // then handle the starts for (const MxmlOctaveShiftDesc& desc : starts) { - if (_octaveShifts.contains(desc.num)) { - MxmlOctaveShiftDesc prevDesc = _octaveShifts.value(desc.num); + if (mu::contains(_octaveShifts, static_cast(desc.num))) { + MxmlOctaveShiftDesc prevDesc = _octaveShifts.at(desc.num); if (prevDesc.tp == MxmlOctaveShiftDesc::Type::STOP) { // a complete pair _parts[partId].addOctaveShift(staff, desc.size, desc.time); @@ -2967,10 +2967,10 @@ void MusicXMLParserPass1::direction(const QString& partId, const Fraction cTime) } else _logger->logError("double octave-shift start", &_e); - _octaveShifts.remove(desc.num); + mu::remove(_octaveShifts, desc.num); } else - _octaveShifts.insert(desc.num, desc); + _octaveShifts.insert({ desc.num, desc }); } } @@ -3540,7 +3540,7 @@ void MusicXMLParserPass1::note(const QString& partId, QString strStaff = _e.readElementText(); staff = _parts[partId].staffNumberToIndex(strStaff.toInt(&ok)); _parts[partId].setMaxStaff(staff); - Part* part = _partMap.value(partId); + Part* part = mu::value(_partMap, partId); if (!part) continue; if (!ok || staff < 0 || staff >= part->nstaves()) @@ -3602,9 +3602,9 @@ void MusicXMLParserPass1::note(const QString& partId, if (dura.isValid() && dura > Fraction(0, 1)) { // count the chords int voiceInt = voiceToInt(voice); - if (!_parts.value(partId).voicelist.contains(voiceInt)) { + if (!mu::contains(mu::value(_parts, partId).voicelist, voiceInt)) { VoiceDesc vs; - _parts[partId].voicelist.insert(voiceInt, vs); + _parts[partId].voicelist.insert({ voiceInt, vs }); } _parts[partId].voicelist[voiceInt].incrChordRests(staff); // determine note length for voiceInt overlap detection @@ -3670,8 +3670,8 @@ Fraction MusicXMLParserPass1::calcTicks(const int& intTicks, const int& _divisio // There are two strategies: // 1. Use a lookup table of previous adjustments // 2. Check if within maxDiff of a seenDenominator - if (_adjustedDurations.contains(dura)) { - dura = _adjustedDurations.value(dura); + if (mu::contains(_adjustedDurations, dura)) { + dura = _adjustedDurations.at(dura); } else if (dura.reduced().denominator() > 64) { for (int seenDenominator : _seenDenominators) { diff --git a/importexport/musicxml/importmxmlpass1.h b/importexport/musicxml/importmxmlpass1.h index 9aa5482891830..4c71b25365159 100644 --- a/importexport/musicxml/importmxmlpass1.h +++ b/importexport/musicxml/importmxmlpass1.h @@ -46,7 +46,7 @@ struct MxmlPageFormat { bool twosided { false }; }; -typedef QMap PartMap; +typedef std::map PartMap; typedef std::map MusicXmlPartGroupMap; //--------------------------------------------------------- @@ -166,9 +166,9 @@ class MusicXMLParserPass1 { int voiceToInt(const QString& voice); int trackForPart(const QString& id) const; bool hasPart(const QString& id) const; - Part* getPart(const QString& id) const { return _partMap.value(id); } - MusicXmlPart getMusicXmlPart(const QString& id) const { return _parts.value(id); } - MusicXMLInstruments getInstruments(const QString& id) const { return _instruments.value(id); } + Part* getPart(const QString& id) const { return mu::value(_partMap, id); } + MusicXmlPart getMusicXmlPart(const QString& id) const { return mu::value( _parts, id); } + MusicXMLInstruments getInstruments(const QString& id) const { return mu::value(_instruments, id); } void setDrumsetDefault(const QString& id, const QString& instrId, const NoteHead::Group hg, const int line, const Direction sd); MusicXmlInstrList getInstrList(const QString id) const; MusicXmlIntervalList getIntervals(const QString id) const; @@ -176,11 +176,11 @@ class MusicXMLParserPass1 { int octaveShift(const QString& id, const int staff, const Fraction f) const; const CreditWordsList& credits() const { return _credits; } bool hasBeamingInfo() const { return _hasBeamingInfo; } - bool isVocalStaff(const QString& id) const { return _parts[id].isVocalStaff(); } + bool isVocalStaff(const QString& id) const { return _parts.at(id).isVocalStaff(); } static VBox* createAndAddVBoxForCreditWords(Score* const score); int maxDiff() const { return _maxDiff; } - void insertAdjustedDuration(Fraction key, Fraction value) { _adjustedDurations.insert(key, value); } - QMap& adjustedDurations() { return _adjustedDurations; } + void insertAdjustedDuration(Fraction key, Fraction value) { _adjustedDurations.insert({ key, value }); } + std::map& adjustedDurations() { return _adjustedDurations; } void insertSeenDenominator(int val) { _seenDenominators.emplace(val); } void createDefaultHeader(Score* const score); void createMeasuresAndVboxes(Score* const score, @@ -203,14 +203,14 @@ class MusicXMLParserPass1 { QXmlStreamReader _e; QString _exporterString; ///< Name of the software which exported the file int _divs; ///< Current MusicXML divisions value - QMap _parts; ///< Parts data, mapped on part id + std::map _parts; ///< Parts data, mapped on part id std::set _systemStartMeasureNrs; ///< Measure numbers of measures starting a page std::set _pageStartMeasureNrs; ///< Measure numbers of measures starting a page std::vector _measureLength; ///< Length of each measure std::vector _measureStart; ///< Start time of each measure CreditWordsList _credits; ///< All credits collected PartMap _partMap; ///< TODO merge into MusicXmlPart ?? - QMap _instruments; ///< instruments for each part, mapped on part id + std::map _instruments; ///< instruments for each part, mapped on part id Score* _score; ///< MuseScore score MxmlLogger* _logger; ///< Error logger QString _errors; ///< Errors to present to the user @@ -220,11 +220,11 @@ class MusicXMLParserPass1 { // part specific data (TODO: move to part-specific class) Fraction _timeSigDura; ///< Measure duration according to last timesig read - QMap _octaveShifts; ///< Pending octave-shifts + std::map _octaveShifts; ///< Pending octave-shifts QSize _pageSize; ///< Page width read from defaults const int _maxDiff = 5; ///< Duration rounding tick threshold; - QMap _adjustedDurations; ///< Rounded durations + std::map _adjustedDurations; ///< Rounded durations std::set _seenDenominators; ///< Denominators seen. Used for rounding errors. }; diff --git a/importexport/musicxml/importmxmlpass2.cpp b/importexport/musicxml/importmxmlpass2.cpp index 2e89683f55bbb..2fab30803e4e5 100644 --- a/importexport/musicxml/importmxmlpass2.cpp +++ b/importexport/musicxml/importmxmlpass2.cpp @@ -371,13 +371,11 @@ static void fillGapsInFirstVoices(Measure* measure, Part* part) static bool hasDrumset(const MusicXMLInstruments& instruments) { bool res = false; - MusicXMLInstrumentsIterator ii(instruments); - while (ii.hasNext()) { - ii.next(); + for (const auto& p : instruments) { // debug: dump the instruments //qDebug("instrument: %s %s", qPrintable(ii.key()), qPrintable(ii.value().toString())); // find valid unpitched values - int unpitched = ii.value().unpitched; + int unpitched = p.second.unpitched; if (0 <= unpitched && unpitched <= 127) { res = true; } @@ -416,16 +414,15 @@ static bool hasDrumset(const MusicXMLInstruments& instruments) static void initDrumset(Drumset* drumset, const MusicXMLInstruments& instruments) { drumset->clear(); - MusicXMLInstrumentsIterator ii(instruments); - while (ii.hasNext()) { - ii.next(); + + for (const auto& ii : instruments) { // debug: also dump the drumset for this part //qDebug("initDrumset: instrument: %s %s", qPrintable(ii.key()), qPrintable(ii.value().toString())); - int unpitched = ii.value().unpitched; + int unpitched = ii.second.unpitched; if (0 <= unpitched && unpitched <= 127) { - drumset->drum(ii.value().unpitched) - = DrumInstrument(ii.value().name.toLatin1().constData(), - ii.value().notehead, ii.value().line, ii.value().stemDirection); + drumset->drum(ii.second.unpitched) + = DrumInstrument(ii.second.name.toLatin1().constData(), + ii.second.notehead, ii.second.line, ii.second.stemDirection); } } } @@ -584,7 +581,7 @@ static void setPartInstruments(MxmlLogger* logger, const QXmlStreamReader* const if (hasDrumset(instruments)) { // do not create multiple instruments for a drum part //qDebug("hasDrumset"); - MusicXMLInstrument mxmlInstr = instruments.first(); + MusicXMLInstrument mxmlInstr = instruments.begin()->second; updatePartWithInstrument(part, mxmlInstr, {}, true); return; } @@ -593,7 +590,7 @@ static void setPartInstruments(MxmlLogger* logger, const QXmlStreamReader* const // instrument details found, but no instrument ids found // -> only a single instrument is playing in the part //qDebug("single instrument"); - MusicXMLInstrument mxmlInstr = instruments.first(); + MusicXMLInstrument mxmlInstr = instruments.begin()->second; updatePartWithInstrument(part, mxmlInstr, intervList.interval({ 0, 1 })); return; } @@ -606,7 +603,7 @@ static void setPartInstruments(MxmlLogger* logger, const QXmlStreamReader* const Fraction tick = (*it).first; if (it == instrList.cbegin()) { prevInstrId = (*it).second; // first instrument id - MusicXMLInstrument mxmlInstr = instruments.value(prevInstrId); + MusicXMLInstrument mxmlInstr = mu::value(instruments, prevInstrId); updatePartWithInstrument(part, mxmlInstr, intervList.interval(tick)); } else { @@ -631,11 +628,11 @@ static void setPartInstruments(MxmlLogger* logger, const QXmlStreamReader* const if (!segment) logger->logError(QString("segment for instrument change at tick %1 not found") .arg(tick.ticks()), xmlreader); - else if (!instruments.contains(instrId)) + else if (!mu::contains(instruments, instrId)) logger->logError(QString("changed instrument '%1' at tick %2 not found in part '%3'") .arg(instrId).arg(tick.ticks()).arg(partId), xmlreader); else { - MusicXMLInstrument mxmlInstr = instruments.value(instrId); + MusicXMLInstrument mxmlInstr = mu::value(instruments, instrId); updatePartWithInstrumentChange(part, mxmlInstr, intervList.interval(tick), segment, track, tick); } } @@ -662,7 +659,7 @@ static QString text2syms(const QString& t) // caching does not gain much ScoreFont* sf = ScoreFont::fallbackFont(); - QMap map; + std::map map; int maxStringSize = 0; // maximum string size found for (int i = int(SymId::noSym); i < int(SymId::lastSym); ++i) { @@ -670,14 +667,14 @@ static QString text2syms(const QString& t) QString string(sf->toString(id)); // insert all syms except space to prevent matching all regular spaces if (id != SymId::space) - map.insert(string, id); + map.insert({ string, id }); if (string.size() > maxStringSize) maxStringSize = string.size(); } // Special case Dolet inference (TODO: put behind a setting or export type flag) - map.insert("$", SymId::segno); - map.insert("Ø", SymId::coda); + map.insert({ "$", SymId::segno }); + map.insert({ "Ø", SymId::coda }); //qDebug("text2syms map count %d maxsz %d filling time elapsed: %d ms", // map.size(), maxStringSize, time.elapsed()); @@ -692,8 +689,8 @@ static QString text2syms(const QString& t) QString sym; while (maxMatch > 0) { QString toBeMatched = in.left(maxMatch); - if (map.contains(toBeMatched)) { - sym = Sym::id2name(map.value(toBeMatched)); + if (mu::contains(map, toBeMatched)) { + sym = Sym::id2name(map.at(toBeMatched)); break; } maxMatch--; @@ -852,23 +849,23 @@ static void addLyric(MxmlLogger* logger, const QXmlStreamReader* const xmlreader static void addLyrics(MxmlLogger* logger, const QXmlStreamReader* const xmlreader, ChordRest* cr, - const QMap& numbrdLyrics, + const std::map& numbrdLyrics, const QSet& extLyrics, MusicXmlLyricsExtend& extendedLyrics) { - for (const auto lyricNo : numbrdLyrics.keys()) { - Lyrics* const lyric = numbrdLyrics.value(lyricNo); + for (const auto lyricNo : mu::keys(numbrdLyrics)) { + Lyrics* const lyric = numbrdLyrics.at(lyricNo); addLyric(logger, xmlreader, cr, lyric, lyricNo, extendedLyrics); if (extLyrics.contains(lyric)) extendedLyrics.addLyric(lyric); } } -static void addGraceNoteLyrics(const QMap& numberedLyrics, QSet extendedLyrics, +static void addGraceNoteLyrics(const std::map& numberedLyrics, QSet extendedLyrics, std::vector& gnLyrics) { - for (const auto lyricNo : numberedLyrics.keys()) { - Lyrics* const lyric = numberedLyrics[lyricNo]; + for (const auto lyricNo : mu::keys(numberedLyrics)) { + Lyrics* const lyric = numberedLyrics.at(lyricNo); if (lyric) { bool extend = extendedLyrics.contains(lyric); const GraceNoteLyrics gnl = GraceNoteLyrics(lyric, extend, lyricNo); @@ -1238,37 +1235,37 @@ static void addOtherOrnamentToChord(const Notation& notation, ChordRest* cr) static bool convertArticulationToSymId(const QString& mxmlName, SymId& id) { - QMap map; // map MusicXML articulation name to MuseScore symbol - map["accent"] = SymId::articAccentAbove; - map["staccatissimo"] = SymId::articStaccatissimoWedgeAbove; - map["staccato"] = SymId::articStaccatoAbove; - map["tenuto"] = SymId::articTenutoAbove; - map["strong-accent"] = SymId::articMarcatoAbove; - map["delayed-turn"] = SymId::ornamentTurn; - map["turn"] = SymId::ornamentTurn; - map["inverted-turn"] = SymId::ornamentTurnInverted; - map["stopped"] = SymId::brassMuteClosed; - map["up-bow"] = SymId::stringsUpBow; - map["down-bow"] = SymId::stringsDownBow; - map["detached-legato"] = SymId::articTenutoStaccatoAbove; - map["spiccato"] = SymId::articStaccatissimoAbove; - map["snap-pizzicato"] = SymId::pluckedSnapPizzicatoAbove; - map["schleifer"] = SymId::ornamentPrecompSlide; - map["open"] = SymId::brassMuteOpen; - map["open-string"] = SymId::brassMuteOpen; - map["thumb-position"] = SymId::stringsThumbPosition; - map["soft-accent"] = SymId::articSoftAccentAbove; - map["stress"] = SymId::articStressAbove; - map["unstress"] = SymId::articUnstressAbove; - - if (map.contains(mxmlName)) { - id = map.value(mxmlName); + static std::map map; // map MusicXML articulation name to MuseScore symbol + if (map.empty()) { + map["accent"] = SymId::articAccentAbove; + map["staccatissimo"] = SymId::articStaccatissimoWedgeAbove; + map["staccato"] = SymId::articStaccatoAbove; + map["tenuto"] = SymId::articTenutoAbove; + map["strong-accent"] = SymId::articMarcatoAbove; + map["delayed-turn"] = SymId::ornamentTurn; + map["turn"] = SymId::ornamentTurn; + map["inverted-turn"] = SymId::ornamentTurnInverted; + map["stopped"] = SymId::brassMuteClosed; + map["up-bow"] = SymId::stringsUpBow; + map["down-bow"] = SymId::stringsDownBow; + map["detached-legato"] = SymId::articTenutoStaccatoAbove; + map["spiccato"] = SymId::articStaccatissimoAbove; + map["snap-pizzicato"] = SymId::pluckedSnapPizzicatoAbove; + map["schleifer"] = SymId::ornamentPrecompSlide; + map["open"] = SymId::brassMuteOpen; + map["open-string"] = SymId::brassMuteOpen; + map["thumb-position"] = SymId::stringsThumbPosition; + map["soft-accent"] = SymId::articSoftAccentAbove; + map["stress"] = SymId::articStressAbove; + map["unstress"] = SymId::articUnstressAbove; + } + + if (mu::contains(map, mxmlName)) { + id = map.at(mxmlName); return true; } - else { - id = SymId::noSym; - return false; - } + id = SymId::noSym; + return false; } //--------------------------------------------------------- @@ -1281,18 +1278,20 @@ static bool convertArticulationToSymId(const QString& mxmlName, SymId& id) static SymId convertFermataToSymId(const QString& mxmlName) { - QMap map; // map MusicXML fermata name to MuseScore symbol - map["normal"] = SymId::fermataAbove; - map["angled"] = SymId::fermataShortAbove; - map["square"] = SymId::fermataLongAbove; - map["double-angled"] = SymId::fermataVeryShortAbove; - map["double-square"] = SymId::fermataVeryLongAbove; - map["double-dot"] = SymId::fermataLongHenzeAbove; - map["half-curve"] = SymId::fermataShortHenzeAbove; - map["curlew"] = SymId::curlewSign; - - if (map.contains(mxmlName)) - return map.value(mxmlName); + static std::map map; // map MusicXML fermata name to MuseScore symbol + if (map.empty()) { + map["normal"] = SymId::fermataAbove; + map["angled"] = SymId::fermataShortAbove; + map["square"] = SymId::fermataLongAbove; + map["double-angled"] = SymId::fermataVeryShortAbove; + map["double-square"] = SymId::fermataVeryLongAbove; + map["double-dot"] = SymId::fermataLongHenzeAbove; + map["half-curve"] = SymId::fermataShortHenzeAbove; + map["curlew"] = SymId::curlewSign; + } + + if (mu::contains(map, mxmlName)) + return map.at(mxmlName); return SymId::fermataAbove; } @@ -1306,30 +1305,32 @@ static SymId convertFermataToSymId(const QString& mxmlName) static NoteHead::Group convertNotehead(QString mxmlName) { - QMap map; // map MusicXML notehead name to a MuseScore headgroup - map["slash"] = int(NoteHead::Group::HEAD_SLASH); - map["triangle"] = int(NoteHead::Group::HEAD_TRIANGLE_UP); - map["diamond"] = int(NoteHead::Group::HEAD_DIAMOND); - map["cross"] = int(NoteHead::Group::HEAD_PLUS); - map["x"] = int(NoteHead::Group::HEAD_CROSS); - map["circled"] = int(NoteHead::Group::HEAD_CIRCLED); - map["circle-x"] = int(NoteHead::Group::HEAD_XCIRCLE); - map["inverted triangle"] = int(NoteHead::Group::HEAD_TRIANGLE_DOWN); - map["slashed"] = int(NoteHead::Group::HEAD_SLASHED1); - map["back slashed"] = int(NoteHead::Group::HEAD_SLASHED2); - map["normal"] = int(NoteHead::Group::HEAD_NORMAL); - map["rectangle"] = int(NoteHead::Group::HEAD_LA); - map["do"] = int(NoteHead::Group::HEAD_DO); - map["re"] = int(NoteHead::Group::HEAD_RE); - map["mi"] = int(NoteHead::Group::HEAD_MI); - map["fa"] = int(NoteHead::Group::HEAD_FA); - map["fa up"] = int(NoteHead::Group::HEAD_FA); - map["so"] = int(NoteHead::Group::HEAD_SOL); - map["la"] = int(NoteHead::Group::HEAD_LA); - map["ti"] = int(NoteHead::Group::HEAD_TI); - - if (map.contains(mxmlName)) - return NoteHead::Group(map.value(mxmlName)); + static std::map map; // map MusicXML notehead name to a MuseScore headgroup + if (map.empty()) { + map["slash"] = int(NoteHead::Group::HEAD_SLASH); + map["triangle"] = int(NoteHead::Group::HEAD_TRIANGLE_UP); + map["diamond"] = int(NoteHead::Group::HEAD_DIAMOND); + map["cross"] = int(NoteHead::Group::HEAD_PLUS); + map["x"] = int(NoteHead::Group::HEAD_CROSS); + map["circled"] = int(NoteHead::Group::HEAD_CIRCLED); + map["circle-x"] = int(NoteHead::Group::HEAD_XCIRCLE); + map["inverted triangle"] = int(NoteHead::Group::HEAD_TRIANGLE_DOWN); + map["slashed"] = int(NoteHead::Group::HEAD_SLASHED1); + map["back slashed"] = int(NoteHead::Group::HEAD_SLASHED2); + map["normal"] = int(NoteHead::Group::HEAD_NORMAL); + map["rectangle"] = int(NoteHead::Group::HEAD_LA); + map["do"] = int(NoteHead::Group::HEAD_DO); + map["re"] = int(NoteHead::Group::HEAD_RE); + map["mi"] = int(NoteHead::Group::HEAD_MI); + map["fa"] = int(NoteHead::Group::HEAD_FA); + map["fa up"] = int(NoteHead::Group::HEAD_FA); + map["so"] = int(NoteHead::Group::HEAD_SOL); + map["la"] = int(NoteHead::Group::HEAD_LA); + map["ti"] = int(NoteHead::Group::HEAD_TI); + } + + if (mu::contains(map, mxmlName)) + return NoteHead::Group(map.at(mxmlName)); else qDebug("unknown notehead %s", qPrintable(mxmlName)); // TODO // default: return 0 @@ -1435,7 +1436,7 @@ static void setSLinePlacement(SLine* sli, const QString placement) //--------------------------------------------------------- // note that in case of overlapping spanners, handleSpannerStart is called for every spanner -// as spanners QMap allows only one value per key, this does not hurt at all +// as spanners std::map allows only one value per key, this does not hurt at all static void handleSpannerStart(SLine* new_sp, int track, QString placement, const Fraction& tick, MusicXmlSpannerMap& spanners) { @@ -2208,14 +2209,14 @@ void MusicXMLParserPass2::part() // try to prevent an empty track name if (msPart->partName().isEmpty()) { QString instrId = _pass1.getInstrList(id).instrument(Fraction(0, 1)); - msPart->setPartName(instruments[instrId].name); + msPart->setPartName(mu::value(instruments, instrId).name); } #ifdef DEBUG_VOICE_MAPPER VoiceList voicelist = _pass1.getVoiceList(id); // debug: print voice mapper contents qDebug("voiceMapperStats: part '%s'", qPrintable(id)); - for (QMap::const_iterator i = voicelist.constBegin(); i != voicelist.constEnd(); ++i) { + for (std::map::const_iterator i = voicelist.cbBegin(); i != voicelist.cend(); ++i) { qDebug("voiceMapperStats: voice %s staff data %s", qPrintable(i.key()), qPrintable(i.value().toString())); } @@ -2260,11 +2261,11 @@ void MusicXMLParserPass2::part() const SpannerSet incompleteSpanners = findIncompleteSpannersAtPartEnd(); //qDebug("spanner list:"); - auto i = _spanners.constBegin(); - while (i != _spanners.constEnd()) { - SLine* const sp = i.key(); - Fraction tick1 = Fraction::fromTicks(i.value().first); - Fraction tick2 = Fraction::fromTicks(i.value().second); + auto i = _spanners.cbegin(); + while (i != _spanners.cend()) { + SLine* sp = i->first; + Fraction tick1 = Fraction::fromTicks(i->second.first); + Fraction tick2 = Fraction::fromTicks(i->second.second); if (sp->isPedal() && toPedal(sp)->endHookType() == HookType::HOOK_45) { // Handle pedal change end tick (slightly hacky) // Find CR on the end tick of @@ -2437,10 +2438,10 @@ static void markUserAccidentals(const int firstStaff, const int staves, const Key key, const Measure* measure, - const QMap& alterMap + const std::map& alterMap ) { - QMap accTmp; + std::map accTmp; AccidentalState currAcc; currAcc.init(key); @@ -2451,9 +2452,9 @@ static void markUserAccidentals(const int firstStaff, if (!e || e->type() != Ms::ElementType::CHORD) continue; Chord* chord = static_cast(e); - foreach (Note* nt, chord->notes()) { - if (alterMap.contains(nt)) { - int alter = alterMap.value(nt); + for (Note* nt : chord->notes()) { + if (mu::contains(alterMap, nt)) { + int alter = alterMap.at(nt); int ln = absStep(nt->tpc(), nt->pitch()); bool error = false; AccidentalVal currAccVal = currAcc.accidentalVal(ln, error); @@ -2462,25 +2463,25 @@ static void markUserAccidentals(const int firstStaff, if ((alter == -1 && currAccVal == AccidentalVal::FLAT && nt->accidental()->accidentalType() == AccidentalType::FLAT - && !accTmp.value(ln, false)) + && !mu::value(accTmp, ln, false)) || (alter == 0 && currAccVal == AccidentalVal::NATURAL && nt->accidental()->accidentalType() == AccidentalType::NATURAL - && !accTmp.value(ln, false)) + && !mu::value(accTmp, ln, false)) || (alter == 1 && currAccVal == AccidentalVal::SHARP && nt->accidental()->accidentalType() == AccidentalType::SHARP - && !accTmp.value(ln, false))) { + && !mu::value(accTmp, ln, false))) { nt->accidental()->setRole(AccidentalRole::USER); } else if (Accidental::isMicrotonal(nt->accidental()->accidentalType()) && nt->accidental()->accidentalType() < AccidentalType::END) { // microtonal accidental nt->accidental()->setRole(AccidentalRole::USER); - accTmp.insert(ln, false); + accTmp.insert({ ln, false }); } else { - accTmp.insert(ln, true); + accTmp.insert({ ln, true }); } } } @@ -2653,7 +2654,7 @@ void MusicXMLParserPass2::measure(const QString& partId, Tuplets tuplets; // Current tuplet for each voice in the current part // collect candidates for courtesy accidentals to work out at measure end - QMap alterMap; + std::map alterMap; DelayedDirectionsList delayedDirections; // Directions to be added to score *after* collecting all and sorting InferredFingeringsList inferredFingerings; // Directions to be reinterpreted as Fingerings HarmonyMap delayedHarmony; @@ -2689,7 +2690,7 @@ void MusicXMLParserPass2::measure(const QString& partId, if (n && !n->chord()->isGrace()) prevChord = n->chord(); // remember last non-grace chord if (n && n->accidental() && n->accidental()->accidentalType() != AccidentalType::NONE) - alterMap.insert(n, alt); + alterMap.insert({ n, alt }); if (missingPrev.isValid()) { mTime += missingPrev; } @@ -2787,7 +2788,7 @@ void MusicXMLParserPass2::measure(const QString& partId, fillGapsInFirstVoices(measure, part); // Prevent any beams from extending into the next measure - for (Beam* beam : beams.values()) + for (Beam* beam : mu::values(beams)) if (beam) removeBeam(beam); @@ -3665,7 +3666,7 @@ void MusicXMLParserDirection::otherDirection() else { // TODO: Multiple sets of maps for exporters other than Dolet 6/Sibelius // TODO: Add more symbols from Sibelius - QMap otherDirectionStrings; + std::map otherDirectionStrings; if (_pass1.exporterString().contains("dolet")) { otherDirectionStrings = { { QString("To Coda"), QString("To Coda") }, @@ -3673,7 +3674,7 @@ void MusicXMLParserDirection::otherDirection() { QString("CODA"), QString("coda") }, }; } - static const QMap otherDirectionSyms = { + static const std::map otherDirectionSyms = { { QString("Rhythm dot"), SymId::augmentationDot }, { QString("Whole rest"), SymId::restWhole }, { QString("l.v. down"), SymId::articLaissezVibrerBelow }, @@ -3684,11 +3685,11 @@ void MusicXMLParserDirection::otherDirection() { QString("Thick caesura"), SymId::caesuraThick } }; QString t = _e.readElementText(); - QString val = otherDirectionStrings.value(t); + QString val = otherDirectionStrings.at(t); if (!val.isEmpty()) _wordsText += val; else { - SymId sym = otherDirectionSyms.value(t); + SymId sym = otherDirectionSyms.at(t); Symbol* smuflSym = new Symbol(_score); smuflSym->setSym(sym); if (color.isValid()) @@ -4736,7 +4737,7 @@ void MusicXMLParserPass2::clearSpanner(const MusicXmlSpannerDesc& d) void MusicXMLParserPass2::deleteHandledSpanner(SLine* const& spanner) { - _spanners.remove(spanner); + mu::remove(_spanners, spanner); delete spanner; } @@ -5804,26 +5805,25 @@ static void setNoteHead(Note* note, const QColor noteheadColor, const bool noteh Calculate the beam mode based on the collected beamTypes. */ -static Beam::Mode computeBeamMode(const QMap& beamTypes) +static Beam::Mode computeBeamMode(const std::map& beamTypes) { // Start with uniquely-handled beam modes - if (beamTypes.value(1) == "continue" - && beamTypes.value(2) == "begin") + if (mu::value(beamTypes, 1) == "continue" + && mu::value(beamTypes, 2) == "begin") return Beam::Mode::BEGIN32; - else if (beamTypes.value(1) == "continue" - && beamTypes.value(2) == "continue" - && beamTypes.value(3) == "begin") + else if (mu::value(beamTypes, 1) == "continue" + && mu::value(beamTypes, 2) == "continue" + && mu::value(beamTypes, 3) == "begin") return Beam::Mode::BEGIN64; // Generic beam modes are naive to all except the first beam - else if (beamTypes.value(1) == "begin") + else if (mu::value(beamTypes, 1) == "begin") return Beam::Mode::BEGIN; - else if (beamTypes.value(1) == "continue") + else if (mu::value(beamTypes, 1) == "continue") return Beam::Mode::MID; - else if (beamTypes.value(1) == "end") + else if (mu::value(beamTypes, 1) == "end") return Beam::Mode::END; - else - // backward-hook, forward-hook, and other unknown combinations - return Beam::Mode::AUTO; + // backward-hook, forward-hook, and other unknown combinations + return Beam::Mode::AUTO; } //--------------------------------------------------------- @@ -5934,11 +5934,10 @@ static void setPitch(Note* note, MusicXMLParserPass1& pass1, const QString& part { const MusicXMLInstruments& instruments = pass1.getInstruments(partId); if (mnp.unpitched()) { - if (hasDrumset(instruments) - && instruments.contains(instrumentId)) { + if (hasDrumset(instruments) && mu::contains(instruments, instrumentId)) { // step and oct are display-step and ...-oct // get pitch from instrument definition in drumset instead - int unpitched = instruments[instrumentId].unpitched; + int unpitched = instruments.at(instrumentId).unpitched; note->setPitch(limit(unpitched, 0, 127)); // TODO - does this need to be key-aware? note->setTpc(pitch2tpc(unpitched, Key::C, Prefer::NEAREST)); // TODO: necessary ? @@ -6043,7 +6042,7 @@ Note* MusicXMLParserPass2::note(const QString& partId, bool graceSlash = false; bool printObject = _e.attributes().value("print-object") != "no"; Beam::Mode bm; - QMap beamTypes; + std::map beamTypes; QString instrumentId; QString tieType; MusicXMLParserLyric lyric { _pass1.getMusicXmlPart(partId).lyricNumberHandler(), _e, _score, _logger }; @@ -6143,8 +6142,8 @@ Note* MusicXMLParserPass2::note(const QString& partId, voice = "1"; // Define currBeam based on currentVoice to handle multi-voice beaming (and instantiate if not already) - if (!currBeams.contains(currentVoice)) - currBeams.insert(currentVoice, (Beam *)nullptr); + if (!mu::contains(currBeams, currentVoice)) + currBeams.insert({ currentVoice, (Beam *)nullptr }); Beam* &currBeam = currBeams[currentVoice]; bm = computeBeamMode(beamTypes); @@ -7035,12 +7034,12 @@ void MusicXMLParserPass2::harmony(const QString& partId, Measure* measure, const Collects beamTypes, used in computeBeamMode. */ -void MusicXMLParserPass2::beam(QMap& beamTypes) { +void MusicXMLParserPass2::beam(std::map& beamTypes) { bool hasBeamNo; int beamNo = _e.attributes().value("number").toInt(&hasBeamNo); QString s = _e.readElementText(); - beamTypes.insert(hasBeamNo ? beamNo : 1, s); + beamTypes.insert({ hasBeamNo ? beamNo : 1, s }); } //--------------------------------------------------------- @@ -7180,7 +7179,7 @@ void MusicXMLParserLyric::parse() _logger->logError(QString("too much lyrics (>%1)").arg(MAX_LYRICS), &_e); return; } - else if (_numberedLyrics.contains(lyricNo)) { + else if (mu::contains(_numberedLyrics, lyricNo)) { _logger->logError(QString("duplicate lyrics number (%1)").arg(lyricNumber), &_e); return; } diff --git a/importexport/musicxml/importmxmlpass2.h b/importexport/musicxml/importmxmlpass2.h index 4c26541946c0d..143b7c1066b29 100644 --- a/importexport/musicxml/importmxmlpass2.h +++ b/importexport/musicxml/importmxmlpass2.h @@ -37,7 +37,7 @@ namespace Ms { using GraceChordList = std::vector; using FiguredBassList = std::vector; using Tuplets = std::map; -using Beams = QMap; +using Beams = std::map; //--------------------------------------------------------- // MxmlStartStop @@ -132,7 +132,7 @@ class MusicXMLParserLyric { MusicXMLParserLyric(const LyricNumberHandler lyricNumberHandler, QXmlStreamReader& e, Score* score, MxmlLogger* logger); QSet extendedLyrics() const { return _extendedLyrics; } - QMap numberedLyrics() const { return _numberedLyrics; } + std::map numberedLyrics() const { return _numberedLyrics; } void parse(); private: void skipLogCurrElem(); @@ -141,7 +141,7 @@ class MusicXMLParserLyric { QXmlStreamReader& _e; Score* const _score = nullptr; // the score MxmlLogger* _logger = nullptr; ///< Error logger - QMap _numberedLyrics; // lyrics with valid number + std::map _numberedLyrics; // lyrics with valid number QSet _extendedLyrics; // lyrics with the extend flag set }; @@ -320,7 +320,7 @@ class MusicXMLParserPass2 { FretDiagram* frame(qreal& defaultY, qreal& relativeY); void harmony(const QString& partId, Measure* measure, const Fraction sTime, HarmonyMap& harmonyMap); Accidental* accidental(); - void beam(QMap& beamTypes); + void beam(std::map& beamTypes); void duration(Fraction& dura); void forward(Fraction& dura); void backup(Fraction& dura); diff --git a/importexport/musicxml/importxmlfirstpass.cpp b/importexport/musicxml/importxmlfirstpass.cpp index d117078152f98..3c70d905161aa 100644 --- a/importexport/musicxml/importxmlfirstpass.cpp +++ b/importexport/musicxml/importxmlfirstpass.cpp @@ -59,9 +59,9 @@ QString MusicXmlPart::toString() const QString res = QString("part id '%1' name '%2' print %3 abbr '%4' print %5 maxStaff %6\n") .arg(id, name).arg(_printName).arg(abbr).arg(_printAbbr, _maxStaff); - for (VoiceList::const_iterator i = voicelist.constBegin(); i != voicelist.constEnd(); ++i) { + for (VoiceList::const_iterator i = voicelist.cbegin(); i != voicelist.cend(); ++i) { res += QString("voice %1 map staff data %2\n") - .arg(QString(i.key() + 1), i.value().toString()); + .arg(QString(i->first + 1), i->second.toString()); } for (size_t i = 0; i < measureNumbers.size(); ++i) { @@ -223,10 +223,9 @@ int MusicXmlPart::staffNumberToIndex(const int staffNumber) const { if (_staffNumberToIndex.size() == 0) return staffNumber - 1; - else if (_staffNumberToIndex.contains(staffNumber)) - return _staffNumberToIndex[staffNumber]; - else - return -1; + else if (mu::contains(_staffNumberToIndex, staffNumber)) + return _staffNumberToIndex.at(staffNumber); + return -1; } //--------------------------------------------------------- diff --git a/importexport/musicxml/importxmlfirstpass.h b/importexport/musicxml/importxmlfirstpass.h index f7f14da880d1f..057385ff019e6 100644 --- a/importexport/musicxml/importxmlfirstpass.h +++ b/importexport/musicxml/importxmlfirstpass.h @@ -19,7 +19,7 @@ namespace Ms { -typedef QMap VoiceList; +typedef std::map VoiceList; //using Intervals = std::map; class MusicXmlIntervalList : public std::map { @@ -80,9 +80,9 @@ class MusicXmlPart { bool getPrintAbbr() const { return _printAbbr; } bool hasTab() const { return _hasTab; } void hasTab(const bool b) { _hasTab = b; } - QMap staffNumberToIndex() const { return _staffNumberToIndex; } + std::map staffNumberToIndex() const { return _staffNumberToIndex; } int staffNumberToIndex(const int staffNumber) const; - void insertStaffNumberToIndex(const int staffNumber, const int staffIndex) { _staffNumberToIndex.insert(staffNumber, staffIndex); } + void insertStaffNumberToIndex(const int staffNumber, const int staffIndex) { _staffNumberToIndex.insert({ staffNumber, staffIndex }); } LyricNumberHandler& lyricNumberHandler() { return _lyricNumberHandler; } const LyricNumberHandler& lyricNumberHandler() const { return _lyricNumberHandler; } void setMaxStaff(const int staff); @@ -102,7 +102,7 @@ class MusicXmlPart { LyricNumberHandler _lyricNumberHandler; int _maxStaff = -1; // maximum staff value found (0 based), -1 = none bool _hasLyrics = false; - QMap _staffNumberToIndex; // Mapping from staff number to index in staff list. + std::map _staffNumberToIndex; // Mapping from staff number to index in staff list. // Only for when staves are discarded in MusicXMLParserPass1::attributes. }; diff --git a/importexport/musicxml/musicxml.h b/importexport/musicxml/musicxml.h index 768c26f8b0ef7..e12cc1e89ac36 100644 --- a/importexport/musicxml/musicxml.h +++ b/importexport/musicxml/musicxml.h @@ -126,7 +126,7 @@ class SlurDesc { //--------------------------------------------------------- typedef std::vector MusicXmlPartGroupList; -typedef QMap > MusicXmlSpannerMap; +typedef std::map > MusicXmlSpannerMap; } // namespace Ms #endif diff --git a/importexport/musicxml/musicxmlsupport.cpp b/importexport/musicxml/musicxmlsupport.cpp index 89d3e0442caf9..bbd6d9ba43eb7 100644 --- a/importexport/musicxml/musicxmlsupport.cpp +++ b/importexport/musicxml/musicxmlsupport.cpp @@ -27,10 +27,11 @@ #include "musicxmlsupport.h" +#include "global/containers.h" namespace Ms { -const static QMap smuflAccidentalTypes { +const static std::map smuflAccidentalTypes { { "accidentalDoubleFlatOneArrowDown", AccidentalType::DOUBLE_FLAT_ONE_ARROW_DOWN }, { "accidentalFlatOneArrowDown", AccidentalType::FLAT_ONE_ARROW_DOWN }, { "accidentalNaturalOneArrowDown", AccidentalType::NATURAL_ONE_ARROW_DOWN }, @@ -156,19 +157,16 @@ VoiceOverlapDetector::VoiceOverlapDetector() void VoiceOverlapDetector::addNote(const int startTick, const int endTick, const int& voice, const int staff) { // if necessary, create the note list for voice - if (!_noteLists.contains(voice)) - _noteLists.insert(voice, NoteList()); + if (!mu::contains(_noteLists, voice)) + _noteLists.insert({ voice, NoteList()}); _noteLists[voice].addNote(startTick, endTick, staff); } void VoiceOverlapDetector::dump() const { // qDebug("VoiceOverlapDetector::dump()"); - QMapIterator i(_noteLists); - while (i.hasNext()) { - i.next(); - i.value().dump(i.key()); - } + for (auto p : _noteLists) + p.second.dump(p.first); } void VoiceOverlapDetector::newMeasure() @@ -179,10 +177,9 @@ void VoiceOverlapDetector::newMeasure() bool VoiceOverlapDetector::stavesOverlap(const int& voice) const { - if (_noteLists.contains(voice)) - return _noteLists.value(voice).anyStaffOverlaps(); - else - return false; + if (mu::contains(_noteLists, voice)) + return _noteLists.at(voice).anyStaffOverlaps(); + return false; } QString MusicXMLInstrument::toString() const @@ -520,58 +517,60 @@ QString accSymId2SmuflMxmlString(const SymId id) SymId mxmlString2accSymId(const QString mxmlName, const QString smufl) { - QMap map; // map MusicXML accidental name to MuseScore enum SymId - map["sharp"] = SymId::accidentalSharp; - map["natural"] = SymId::accidentalNatural; - map["flat"] = SymId::accidentalFlat; - map["double-sharp"] = SymId::accidentalDoubleSharp; - map["sharp-sharp"] = SymId::accidentalDoubleSharp; - //map["double-flat"] = SymId::accidentalDoubleFlat; // shouldn't harm, but doesn't exist in MusicXML - map["flat-flat"] = SymId::accidentalDoubleFlat; - map["natural-sharp"] = SymId::accidentalNaturalSharp; - map["natural-flat"] = SymId::accidentalNaturalFlat; - - map["quarter-flat"] = SymId::accidentalQuarterToneFlatStein; - map["quarter-sharp"] = SymId::accidentalQuarterToneSharpStein; - map["three-quarters-flat"] = SymId::accidentalThreeQuarterTonesFlatZimmermann; - map["three-quarters-sharp"] = SymId::accidentalThreeQuarterTonesSharpStein; - - map["sharp-down"] = SymId::accidentalQuarterToneSharpArrowDown; - map["sharp-up"] = SymId::accidentalThreeQuarterTonesSharpArrowUp; - map["natural-down"] = SymId::accidentalQuarterToneFlatNaturalArrowDown; - map["natural-up"] = SymId::accidentalQuarterToneSharpNaturalArrowUp; - map["flat-down"] = SymId::accidentalThreeQuarterTonesFlatArrowDown; - map["flat-up"] = SymId::accidentalQuarterToneFlatArrowUp; - map["double-sharp-down"] = SymId::accidentalThreeQuarterTonesSharpArrowDown; - map["double-sharp-up"] = SymId::accidentalFiveQuarterTonesSharpArrowUp; - map["flat-flat-down"] = SymId::accidentalFiveQuarterTonesFlatArrowDown; - map["flat-flat-up"] = SymId::accidentalThreeQuarterTonesFlatArrowUp; - - map["arrow-down"] = SymId::accidentalArrowDown; - map["arrow-up"] = SymId::accidentalArrowUp; - - map["triple-sharp"] = SymId::accidentalTripleSharp; - map["triple-flat"] = SymId::accidentalTripleFlat; - - map["slash-quarter-sharp"] = SymId::accidentalKucukMucennebSharp; - map["slash-sharp"] = SymId::accidentalBuyukMucennebSharp; - map["slash-flat"] = SymId::accidentalBakiyeFlat; - map["double-slash-flat"] = SymId::accidentalBuyukMucennebFlat; - - map["sharp-1"] = SymId::accidental1CommaSharp; - map["sharp-2"] = SymId::accidental2CommaSharp; - map["sharp-3"] = SymId::accidental3CommaSharp; - map["sharp-5"] = SymId::accidental5CommaSharp; - map["flat-1"] = SymId::accidental1CommaFlat; - map["flat-2"] = SymId::accidental2CommaFlat; - map["flat-3"] = SymId::accidental3CommaFlat; - map["flat-4"] = SymId::accidental4CommaFlat; - - map["sori"] = SymId::accidentalSori; - map["koron"] = SymId::accidentalKoron; - - if (map.contains(mxmlName)) - return map.value(mxmlName); + static std::map map; // map MusicXML accidental name to MuseScore enum SymId + if (map.empty()) { + map["sharp"] = SymId::accidentalSharp; + map["natural"] = SymId::accidentalNatural; + map["flat"] = SymId::accidentalFlat; + map["double-sharp"] = SymId::accidentalDoubleSharp; + map["sharp-sharp"] = SymId::accidentalDoubleSharp; + //map["double-flat"] = SymId::accidentalDoubleFlat; // shouldn't harm, but doesn't exist in MusicXML + map["flat-flat"] = SymId::accidentalDoubleFlat; + map["natural-sharp"] = SymId::accidentalNaturalSharp; + map["natural-flat"] = SymId::accidentalNaturalFlat; + + map["quarter-flat"] = SymId::accidentalQuarterToneFlatStein; + map["quarter-sharp"] = SymId::accidentalQuarterToneSharpStein; + map["three-quarters-flat"] = SymId::accidentalThreeQuarterTonesFlatZimmermann; + map["three-quarters-sharp"] = SymId::accidentalThreeQuarterTonesSharpStein; + + map["sharp-down"] = SymId::accidentalQuarterToneSharpArrowDown; + map["sharp-up"] = SymId::accidentalThreeQuarterTonesSharpArrowUp; + map["natural-down"] = SymId::accidentalQuarterToneFlatNaturalArrowDown; + map["natural-up"] = SymId::accidentalQuarterToneSharpNaturalArrowUp; + map["flat-down"] = SymId::accidentalThreeQuarterTonesFlatArrowDown; + map["flat-up"] = SymId::accidentalQuarterToneFlatArrowUp; + map["double-sharp-down"] = SymId::accidentalThreeQuarterTonesSharpArrowDown; + map["double-sharp-up"] = SymId::accidentalFiveQuarterTonesSharpArrowUp; + map["flat-flat-down"] = SymId::accidentalFiveQuarterTonesFlatArrowDown; + map["flat-flat-up"] = SymId::accidentalThreeQuarterTonesFlatArrowUp; + + map["arrow-down"] = SymId::accidentalArrowDown; + map["arrow-up"] = SymId::accidentalArrowUp; + + map["triple-sharp"] = SymId::accidentalTripleSharp; + map["triple-flat"] = SymId::accidentalTripleFlat; + + map["slash-quarter-sharp"] = SymId::accidentalKucukMucennebSharp; + map["slash-sharp"] = SymId::accidentalBuyukMucennebSharp; + map["slash-flat"] = SymId::accidentalBakiyeFlat; + map["double-slash-flat"] = SymId::accidentalBuyukMucennebFlat; + + map["sharp-1"] = SymId::accidental1CommaSharp; + map["sharp-2"] = SymId::accidental2CommaSharp; + map["sharp-3"] = SymId::accidental3CommaSharp; + map["sharp-5"] = SymId::accidental5CommaSharp; + map["flat-1"] = SymId::accidental1CommaFlat; + map["flat-2"] = SymId::accidental2CommaFlat; + map["flat-3"] = SymId::accidental3CommaFlat; + map["flat-4"] = SymId::accidental4CommaFlat; + + map["sori"] = SymId::accidentalSori; + map["koron"] = SymId::accidentalKoron; + } + + if (mu::contains(map, mxmlName)) + return map.at(mxmlName); else if (mxmlName == "other") return Sym::name2id(smufl); else @@ -650,7 +649,7 @@ QString accidentalType2MxmlString(const AccidentalType type) QString accidentalType2SmuflMxmlString(const AccidentalType type) { - return smuflAccidentalTypes.key(type); + return mu::key(smuflAccidentalTypes, type); } //--------------------------------------------------------- @@ -664,60 +663,61 @@ QString accidentalType2SmuflMxmlString(const AccidentalType type) AccidentalType mxmlString2accidentalType(const QString mxmlName, const QString smufl) { - QMap map; // map MusicXML accidental name to MuseScore enum AccidentalType - map["sharp"] = AccidentalType::SHARP; - map["natural"] = AccidentalType::NATURAL; - map["flat"] = AccidentalType::FLAT; - map["double-sharp"] = AccidentalType::SHARP2; - map["sharp-sharp"] = AccidentalType::SHARP2; - //map["double-flat"] = AccidentalType::FLAT2; // shouldn't harm, but doesn't exist in MusicXML - map["flat-flat"] = AccidentalType::FLAT2; - map["natural-sharp"] = AccidentalType::SHARP; - map["natural-flat"] = AccidentalType::FLAT; - - map["quarter-flat"] = AccidentalType::MIRRORED_FLAT; - map["quarter-sharp"] = AccidentalType::SHARP_SLASH; - map["three-quarters-flat"] = AccidentalType::MIRRORED_FLAT2; - map["three-quarters-sharp"] = AccidentalType::SHARP_SLASH4; - - map["sharp-up"] = AccidentalType::SHARP_ARROW_UP; - map["natural-down"] = AccidentalType::NATURAL_ARROW_DOWN; - map["natural-up"] = AccidentalType::NATURAL_ARROW_UP; - map["sharp-down"] = AccidentalType::SHARP_ARROW_DOWN; - map["flat-down"] = AccidentalType::FLAT_ARROW_DOWN; - map["flat-up"] = AccidentalType::FLAT_ARROW_UP; - map["double-sharp-down"] = AccidentalType::SHARP2_ARROW_DOWN; - map["double-sharp-up"] = AccidentalType::SHARP2_ARROW_UP; - map["flat-flat-down"] = AccidentalType::FLAT2_ARROW_DOWN; - map["flat-flat-up"] = AccidentalType::FLAT2_ARROW_UP; - - map["arrow-down"] = AccidentalType::ARROW_DOWN; - map["arrow-up"] = AccidentalType::ARROW_UP; - - map["triple-sharp"] = AccidentalType::SHARP3; - map["triple-flat"] = AccidentalType::FLAT3; - - map["slash-quarter-sharp"] = AccidentalType::SHARP_SLASH3; // MIRRORED_FLAT_SLASH; ? - map["slash-sharp"] = AccidentalType::SHARP_SLASH2; // SHARP_SLASH; ? - map["slash-flat"] = AccidentalType::FLAT_SLASH; - map["double-slash-flat"] = AccidentalType::FLAT_SLASH2; - - map["sharp-1"] = AccidentalType::ONE_COMMA_SHARP; - map["sharp-2"] = AccidentalType::TWO_COMMA_SHARP; - map["sharp-3"] = AccidentalType::THREE_COMMA_SHARP; - map["sharp-5"] = AccidentalType::FIVE_COMMA_SHARP; - map["flat-1"] = AccidentalType::ONE_COMMA_FLAT; - map["flat-2"] = AccidentalType::TWO_COMMA_FLAT; - map["flat-3"] = AccidentalType::THREE_COMMA_FLAT; - map["flat-4"] = AccidentalType::FOUR_COMMA_FLAT; - - map["sori"] = AccidentalType::SORI; - map["koron"] = AccidentalType::KORON; - - if (map.contains(mxmlName)) - return map.value(mxmlName); - else if (mxmlName == "other" && smuflAccidentalTypes.contains(smufl)) - return smuflAccidentalTypes.value(smufl); + static std::map map; // map MusicXML accidental name to MuseScore enum AccidentalType + if (map.empty()) { + map["sharp"] = AccidentalType::SHARP; + map["natural"] = AccidentalType::NATURAL; + map["flat"] = AccidentalType::FLAT; + map["double-sharp"] = AccidentalType::SHARP2; + map["sharp-sharp"] = AccidentalType::SHARP2; + //map["double-flat"] = AccidentalType::FLAT2; // shouldn't harm, but doesn't exist in MusicXML + map["flat-flat"] = AccidentalType::FLAT2; + map["natural-sharp"] = AccidentalType::SHARP; + map["natural-flat"] = AccidentalType::FLAT; + + map["quarter-flat"] = AccidentalType::MIRRORED_FLAT; + map["quarter-sharp"] = AccidentalType::SHARP_SLASH; + map["three-quarters-flat"] = AccidentalType::MIRRORED_FLAT2; + map["three-quarters-sharp"] = AccidentalType::SHARP_SLASH4; + + map["sharp-up"] = AccidentalType::SHARP_ARROW_UP; + map["natural-down"] = AccidentalType::NATURAL_ARROW_DOWN; + map["natural-up"] = AccidentalType::NATURAL_ARROW_UP; + map["sharp-down"] = AccidentalType::SHARP_ARROW_DOWN; + map["flat-down"] = AccidentalType::FLAT_ARROW_DOWN; + map["flat-up"] = AccidentalType::FLAT_ARROW_UP; + map["double-sharp-down"] = AccidentalType::SHARP2_ARROW_DOWN; + map["double-sharp-up"] = AccidentalType::SHARP2_ARROW_UP; + map["flat-flat-down"] = AccidentalType::FLAT2_ARROW_DOWN; + map["flat-flat-up"] = AccidentalType::FLAT2_ARROW_UP; + + map["arrow-down"] = AccidentalType::ARROW_DOWN; + map["arrow-up"] = AccidentalType::ARROW_UP; + + map["triple-sharp"] = AccidentalType::SHARP3; + map["triple-flat"] = AccidentalType::FLAT3; + + map["slash-quarter-sharp"] = AccidentalType::SHARP_SLASH3; // MIRRORED_FLAT_SLASH; ? + map["slash-sharp"] = AccidentalType::SHARP_SLASH2; // SHARP_SLASH; ? + map["slash-flat"] = AccidentalType::FLAT_SLASH; + map["double-slash-flat"] = AccidentalType::FLAT_SLASH2; + + map["sharp-1"] = AccidentalType::ONE_COMMA_SHARP; + map["sharp-2"] = AccidentalType::TWO_COMMA_SHARP; + map["sharp-3"] = AccidentalType::THREE_COMMA_SHARP; + map["sharp-5"] = AccidentalType::FIVE_COMMA_SHARP; + map["flat-1"] = AccidentalType::ONE_COMMA_FLAT; + map["flat-2"] = AccidentalType::TWO_COMMA_FLAT; + map["flat-3"] = AccidentalType::THREE_COMMA_FLAT; + map["flat-4"] = AccidentalType::FOUR_COMMA_FLAT; + + map["sori"] = AccidentalType::SORI; + map["koron"] = AccidentalType::KORON; + } + if (mu::contains(map, mxmlName)) + return map.at(mxmlName); + else if (mxmlName == "other" && mu::contains(smuflAccidentalTypes, smufl)) + return smuflAccidentalTypes.at(smufl); else qDebug("mxmlString2accidentalType: unknown accidental '%s'", qPrintable(mxmlName)); return AccidentalType::NONE; @@ -733,15 +733,15 @@ AccidentalType mxmlString2accidentalType(const QString mxmlName, const QString s QString mxmlAccidentalTextToChar(const QString mxmlName) { - static QMap map; // map MusicXML accidental name to MuseScore enum AccidentalType + static std::map map; // map MusicXML accidental name to MuseScore enum AccidentalType if (map.empty()) { map["sharp"] = "♯"; map["natural"] = "♮"; map["flat"] = "♭"; } - if (map.contains(mxmlName)) - return map.value(mxmlName); + if (mu::contains(map, mxmlName)) + return map.at(mxmlName); else qDebug("mxmlAccidentalTextToChar: unsupported accidental '%s'", qPrintable(mxmlName)); return ""; diff --git a/importexport/musicxml/musicxmlsupport.h b/importexport/musicxml/musicxmlsupport.h index cd4d56aab9b61..9f26d9059dde9 100644 --- a/importexport/musicxml/musicxmlsupport.h +++ b/importexport/musicxml/musicxmlsupport.h @@ -135,7 +135,7 @@ class VoiceOverlapDetector { void newMeasure(); bool stavesOverlap(const int& voice) const; private: - QMap _noteLists; ///< The notelists for all the voices + std::map _noteLists; ///< The notelists for all the voices }; //--------------------------------------------------------- @@ -165,7 +165,7 @@ struct MusicXMLInstrument { QString toString() const; - MusicXMLInstrument() // required by QMap + MusicXMLInstrument() // required by std::map : unpitched(-1), name(), midiChannel(-1), midiPort(-1), midiProgram(-1), midiVolume(100), midiPan(63), notehead(NoteHead::Group::HEAD_INVALID), line(0), stemDirection(Direction::AUTO) {} MusicXMLInstrument(QString s) @@ -182,8 +182,7 @@ struct MusicXMLInstrument { A MusicXML drumset or set of instruments in a multi-instrument part. */ -typedef QMap MusicXMLInstruments; -typedef QMapIterator MusicXMLInstrumentsIterator; +typedef std::map MusicXMLInstruments; //---------------------------------------------------------