Skip to content

Commit

Permalink
[musicxml] Replaced QMap to std::map
Browse files Browse the repository at this point in the history
Backport of musescore#21205, part 2
  • Loading branch information
igorkorsukov authored and Jojo-Schmitz committed Jan 26, 2024
1 parent f31e0f7 commit 1fe2a5d
Show file tree
Hide file tree
Showing 10 changed files with 396 additions and 395 deletions.
69 changes: 37 additions & 32 deletions importexport/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <math.h>
#include "config.h"

#include "global/containers.h"

#include "thirdparty/qzip/qzipwriter_p.h"

#include "mscore/preferences.h"
Expand Down Expand Up @@ -128,7 +130,7 @@ namespace Ms {
// typedefs
//---------------------------------------------------------

typedef QMap<int, const FiguredBass*> FigBassMap;
typedef std::map<int, const FiguredBass*> FigBassMap;

//---------------------------------------------------------
// attributes -- prints <attributes> tag when necessary
Expand Down Expand Up @@ -311,7 +313,7 @@ struct MeasurePrintContext final
//---------------------------------------------------------

typedef QHash<const ChordRest* const, const Trill*> TrillHash;
typedef QMap<const Instrument*, int> MxmlInstrumentMap;
typedef std::map<const Instrument*, int> MxmlInstrumentMap;

class ExportMusicXml {
Score* _score;
Expand Down Expand Up @@ -2240,12 +2242,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<qreal, KeySym> map;
std::map<qreal, KeySym> 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<int>(round(2 * ksym.spos.y()));
int step = (po - line) % 7;
_xml.tag("key-step", QString(QChar(table2[step])));
Expand Down Expand Up @@ -3723,7 +3725,7 @@ void ExportMusicXml::chord(Chord* chord, int staff, const std::vector<Lyrics*>*
{
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());
Expand Down Expand Up @@ -5680,10 +5682,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();
Expand All @@ -5705,8 +5707,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();
Expand All @@ -5716,7 +5718,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);
}
}
}
Expand Down Expand Up @@ -5850,7 +5852,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<int, KeySig*> keysigs; // map staff to key signature
std::map<int, KeySig*> keysigs; // map staff to key signature
for (Segment* seg = m->first(); seg; seg = seg->next()) {
if (seg->tick() > m->tick())
break;
Expand All @@ -5870,31 +5872,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 <key> 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 {
Expand Down Expand Up @@ -6038,16 +6040,16 @@ 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<int>(im.size()) });
}
}

//---------------------------------------------------------
// initReverseInstrMap
//---------------------------------------------------------

typedef QMap<int, const Instrument*> MxmlReverseInstrumentMap;
typedef std::map<int, const Instrument*> MxmlReverseInstrumentMap;

/**
Initialize the number t Instrument* map for a Part
Expand All @@ -6057,9 +6059,9 @@ typedef QMap<int, const Instrument*> 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 });
}
}

Expand Down Expand Up @@ -6497,19 +6499,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);
}
}

Expand Down Expand Up @@ -7028,7 +7033,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<int>(instrMap.size()));
}

// make sure clefs at end of measure get exported at start of next measure
Expand Down
Loading

0 comments on commit 1fe2a5d

Please sign in to comment.