Skip to content

Commit

Permalink
[musicxml] Replaced QSet to std::set
Browse files Browse the repository at this point in the history
Backport of musescore#21205, part 3
  • Loading branch information
igorkorsukov authored and Jojo-Schmitz committed Jan 26, 2024
1 parent 1fe2a5d commit ef24103
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
53 changes: 31 additions & 22 deletions importexport/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ class ExportMusicXml {
void findAndExportClef(const Measure* const m, const int staves, const int strack, const int etrack);
void exportDefaultClef(const Part* const part, const Measure* const m);
void writeElement(Element* el, const Measure* m, int sstaff, bool useDrumset);
void writeMeasureTracks(const Measure* const m, const int partIndex, const int strack, const int staves, const bool useDrumset, FigBassMap& fbMap, QSet<const Spanner*>& spannersStopped);
void writeMeasure(const Measure* const m, const int idx, const int staffCount, MeasureNumberStateHandler& mnsh, FigBassMap& fbMap, const MeasurePrintContext& mpc, QSet<const Spanner*>& spannersStopped);
void writeMeasureTracks(const Measure* const m, const int partIndex, const int strack, const int staves, const bool useDrumset, FigBassMap& fbMap, std::set<const Spanner*>& spannersStopped);
void writeMeasure(const Measure* const m, const int idx, const int staffCount, MeasureNumberStateHandler& mnsh, FigBassMap& fbMap, const MeasurePrintContext& mpc, std::set<const Spanner*>& spannersStopped);
void repeatAtMeasureStart(Attributes& attr, const Measure* const m, int strack, int etrack, int track);
void repeatAtMeasureStop(const Measure* const m, int strack, int etrack, int track);
void writeParts();
Expand Down Expand Up @@ -4966,15 +4966,24 @@ void ExportMusicXml::textLine(TextLineBase const* const tl, int staff, const Fra
// supported by MusicXML need to be filtered out. Everything not recognized
// as MusicXML dynamics is written as other-dynamics.

template<typename T>
inline std::set<QString>& operator<<(std::set<QString>& s, const T& v)
{
s.insert(v);
return s;
}

void ExportMusicXml::dynamic(Dynamic const* const dyn, int staff)
{
QSet<QString> set; // the valid MusicXML dynamics
set << "f" << "ff" << "fff" << "ffff" << "fffff" << "ffffff"
<< "fp" << "fz"
<< "mf" << "mp"
<< "p" << "pp" << "ppp" << "pppp" << "ppppp" << "pppppp"
<< "rf" << "rfz"
<< "sf" << "sffz" << "sfp" << "sfpp" << "sfz";
static std::set<QString> set; // the valid MusicXML dynamics
if (set.empty()) {
set << "f" << "ff" << "fff" << "ffff" << "fffff" << "ffffff"
<< "fp" << "fz"
<< "mf" << "mp"
<< "p" << "pp" << "ppp" << "pppp" << "ppppp" << "pppppp"
<< "rf" << "rfz"
<< "sf" << "sffz" << "sfp" << "sfpp" << "sfz";
}

directionTag(_xml, _attr, dyn);

Expand All @@ -4986,7 +4995,7 @@ void ExportMusicXml::dynamic(Dynamic const* const dyn, int staff)
_xml.stag(tagName);
const QString dynTypeName = dyn->dynamicTypeName();

if (set.contains(dynTypeName)) {
if (mu::contains(set, dynTypeName)) {
_xml.tagE(dynTypeName);
}
else if (dynTypeName != "") {
Expand Down Expand Up @@ -5024,7 +5033,7 @@ void ExportMusicXml::dynamic(Dynamic const* const dyn, int staff)
// found a non-dynamics character
if (inDynamicsSym) {
if (text != "") {
if (set.contains(text))
if (mu::contains(set, text))
_xml.tagE(text);
else
_xml.tag("other-dynamics", text);
Expand All @@ -5036,7 +5045,7 @@ void ExportMusicXml::dynamic(Dynamic const* const dyn, int staff)
}
}
if (text != "") {
if (inDynamicsSym && set.contains(text))
if (inDynamicsSym && mu::contains(set, text))
_xml.tagE(text);
else
_xml.tag("other-dynamics", text);
Expand Down Expand Up @@ -5793,15 +5802,15 @@ static void spannerStart(ExportMusicXml* exp, int strack, int etrack, int track,
// note that more than one voice may contains notes ending at tick2,
// remember which spanners have already been stopped (the "stopped" set)

static void spannerStop(ExportMusicXml* exp, int strack, int etrack, const Fraction& tick2, int sstaff, QSet<const Spanner*>& stopped)
static void spannerStop(ExportMusicXml* exp, int strack, int etrack, const Fraction& tick2, int sstaff, std::set<const Spanner*>& stopped)
{
for (auto it : exp->score()->spanner()) {
Spanner* e = it.second;
const Spanner* e = it.second;

if (e->tick2() != tick2 || e->track() < strack || e->track() >= etrack)
continue;

if (!stopped.contains(e)) {
if (!mu::contains(stopped, e)) {
stopped.insert(e);
switch (e->type()) {
case ElementType::HAIRPIN:
Expand All @@ -5814,7 +5823,7 @@ static void spannerStop(ExportMusicXml* exp, int strack, int etrack, const Fract
exp->pedal(toPedal(e), sstaff, Fraction(-1,1));
break;
case ElementType::TEXTLINE:
exp->textLine(toTextLineBase(e), sstaff, Fraction(-1,1));
exp->textLine(static_cast<const TextLineBase*>(e), sstaff, Fraction(-1,1));
break;
case ElementType::LET_RING:
exp->textLine(toLetRing(e), sstaff, Fraction(-1,1));
Expand Down Expand Up @@ -6353,7 +6362,7 @@ void ExportMusicXml::findAndExportClef(const Measure* const m, const int staves,
Find the set of pitches actually used in a part.
*/

typedef QSet<int> pitchSet; // the set of pitches used
typedef std::set<int> pitchSet; // the set of pitches used

static void addChordPitchesToSet(const Chord* c, pitchSet& set)
{
Expand Down Expand Up @@ -6483,7 +6492,7 @@ static void partList(XmlWriter& xml, Score* score, MxmlInstrumentMap& instrMap)
DrumInstrument di = drumset->drum(i);
if (di.notehead != NoteHead::Group::HEAD_INVALID)
scoreInstrument(xml, idx + 1, i + 1, di.name);
else if (pitches.contains(i))
else if (mu::contains(pitches, i))
scoreInstrument(xml, idx + 1, i + 1, QString("Instrument %1").arg(i + 1));
}
int midiPort = part->midiPort() + 1;
Expand All @@ -6492,7 +6501,7 @@ static void partList(XmlWriter& xml, Score* score, MxmlInstrumentMap& instrMap)

for (int i = 0; i < 128; ++i) {
DrumInstrument di = drumset->drum(i);
if (di.notehead != NoteHead::Group::HEAD_INVALID || pitches.contains(i))
if (di.notehead != NoteHead::Group::HEAD_INVALID || mu::contains(pitches, i))
midiInstrument(xml, idx + 1, i + 1, part->instrument(), score, i + 1);
}
}
Expand Down Expand Up @@ -6897,7 +6906,7 @@ void ExportMusicXml::writeMeasureTracks(const Measure* const m,
const int strack, const int staves, // TODO remove ??
const bool useDrumset,
FigBassMap& fbMap,
QSet<const Spanner*>& spannersStopped)
std::set<const Spanner*>& spannersStopped)
{
bool tboxesAboveWritten = false;
const auto tboxesAbove = findTextFramesToWriteAsWordsAbove(m);
Expand Down Expand Up @@ -6992,7 +7001,7 @@ void ExportMusicXml::writeMeasure(const Measure* const m,
MeasureNumberStateHandler& mnsh,
FigBassMap& fbMap,
const MeasurePrintContext& mpc,
QSet<const Spanner*>& spannersStopped)
std::set<const Spanner*>& spannersStopped)
{
const auto part = _score->parts().at(partIndex);
const int staves = part->nstaves();
Expand Down Expand Up @@ -7114,7 +7123,7 @@ void ExportMusicXml::writeParts()

// set of spanners already stopped in this part
// required to prevent multiple spanner stops for the same spanner
QSet<const Spanner*> spannersStopped;
std::set<const Spanner*> spannersStopped;

const auto& pages = _score->pages();
MeasurePrintContext mpc;
Expand Down
8 changes: 4 additions & 4 deletions importexport/musicxml/importmxmlpass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ void MusicXMLParserPass1::scorePartwise()
// set of (typically multi-staff) parts containing one or more explicit brackets
// spanning only that part: these won't get an implicit brace later
// e.g. a two-staff piano part with an explicit brace
QSet<Part const* const> partSet;
std::set<const Part*> partSet;

// handle the explicit brackets
const QList<Part*>& il = _score->parts();
Expand Down Expand Up @@ -1172,14 +1172,14 @@ void MusicXMLParserPass1::scorePartwise()
staff->setBracketSpan(pg->column, stavesSpan);
// add part to set (skip implicit bracket later)
if (pg->span == 1)
partSet << il.at(pg->start);
partSet.insert(il.at(pg->start));
}
}

// handle the implicit brackets:
// multi-staff parts w/o explicit brackets get a brace
foreach (Part const* const p, il) {
if (p->nstaves() > 1 && !partSet.contains(p)) {
for (const Part* p : il) {
if (p->nstaves() > 1 && !mu::contains(partSet, p)) {
const int column = p->staff(0)->bracketLevels() + 1;
p->staff(0)->setBracketType(column, BracketType::BRACE);
p->staff(0)->setBracketSpan(column, p->nstaves());
Expand Down
6 changes: 3 additions & 3 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void MusicXmlLyricsExtend::setExtend(const int no, const int track, const Fracti
}
// cleanup
for (Lyrics* l: list) {
_lyrics.remove(l);
mu::remove(_lyrics, l);
}
}

Expand Down Expand Up @@ -885,13 +885,13 @@ static void addLyric(MxmlLogger* logger, const QXmlStreamReader* const xmlreader
static void addLyrics(MxmlLogger* logger, const QXmlStreamReader* const xmlreader,
ChordRest* cr,
const std::map<int, Lyrics*>& numbrdLyrics,
const QSet<Lyrics*>& extLyrics,
const std::set<Lyrics*>& extLyrics,
MusicXmlLyricsExtend& extendedLyrics)
{
for (const auto lyricNo : mu::keys(numbrdLyrics)) {
const auto lyric = numbrdLyrics.at(lyricNo);
addLyric(logger, xmlreader, cr, lyric, lyricNo, extendedLyrics);
if (extLyrics.contains(lyric))
if (mu::contains(extLyrics, lyric))
extendedLyrics.addLyric(lyric);
}
}
Expand Down
6 changes: 3 additions & 3 deletions importexport/musicxml/importmxmlpass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class MusicXmlLyricsExtend {
void setExtend(const int no, const int track, const Fraction& tick);

private:
QSet<Lyrics*> _lyrics;
std::set<Lyrics*> _lyrics;
};

//---------------------------------------------------------
Expand All @@ -123,7 +123,7 @@ class MusicXMLParserLyric {
public:
MusicXMLParserLyric(const LyricNumberHandler lyricNumberHandler,
QXmlStreamReader& e, Score* score, MxmlLogger* logger);
QSet<Lyrics*> extendedLyrics() const { return _extendedLyrics; }
std::set<Lyrics*> extendedLyrics() const { return _extendedLyrics; }
std::map<int, Lyrics*> numberedLyrics() const { return _numberedLyrics; }
void parse();
private:
Expand All @@ -133,7 +133,7 @@ class MusicXMLParserLyric {
Score* const _score; // the score
MxmlLogger* _logger; ///< Error logger
std::map<int, Lyrics*> _numberedLyrics; // lyrics with valid number
QSet<Lyrics*> _extendedLyrics; // lyrics with the extend flag set
std::set<Lyrics*> _extendedLyrics; // lyrics with the extend flag set
};

//---------------------------------------------------------
Expand Down

0 comments on commit ef24103

Please sign in to comment.