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 Sep 5, 2024
1 parent 01150a8 commit aa6c7cb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
53 changes: 31 additions & 22 deletions importexport/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,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 @@ -5241,15 +5241,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 @@ -5261,7 +5270,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.isEmpty()) {
Expand Down Expand Up @@ -5299,7 +5308,7 @@ void ExportMusicXml::dynamic(Dynamic const* const dyn, int staff)
// found a non-dynamics character
if (inDynamicsSym) {
if (!text.isEmpty()) {
if (set.contains(text))
if (mu::contains(set, text))
_xml.tagE(text);
else
_xml.tag("other-dynamics", text);
Expand All @@ -5311,7 +5320,7 @@ void ExportMusicXml::dynamic(Dynamic const* const dyn, int staff)
}
}
if (!text.isEmpty()) {
if (inDynamicsSym && set.contains(text))
if (inDynamicsSym && mu::contains(set, text))
_xml.tagE(text);
else
_xml.tag("other-dynamics", text);
Expand Down Expand Up @@ -6083,15 +6092,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 @@ -6104,7 +6113,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 @@ -6683,7 +6692,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 @@ -6825,7 +6834,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 @@ -6834,7 +6843,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 @@ -7254,7 +7263,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 @@ -7355,7 +7364,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 Part* part = _score->parts().at(partIndex);
const int staves = part->nstaves();
Expand Down Expand Up @@ -7477,7 +7486,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 @@ -1158,7 +1158,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 @@ -1190,14 +1190,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
10 changes: 5 additions & 5 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,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 @@ -850,24 +850,24 @@ 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)) {
Lyrics* const lyric = numbrdLyrics.at(lyricNo);
addLyric(logger, xmlreader, cr, lyric, lyricNo, extendedLyrics);
if (extLyrics.contains(lyric))
if (mu::contains(extLyrics, lyric))
extendedLyrics.addLyric(lyric);
}
}

static void addGraceNoteLyrics(const std::map<int, Lyrics*>& numberedLyrics, QSet<Lyrics*> extendedLyrics,
static void addGraceNoteLyrics(const std::map<int, Lyrics*>& numberedLyrics, std::set<Lyrics*> extendedLyrics,
std::vector<GraceNoteLyrics>& gnLyrics)
{
for (const auto lyricNo : mu::keys(numberedLyrics)) {
Lyrics* const lyric = numberedLyrics.at(lyricNo);
if (lyric) {
bool extend = extendedLyrics.contains(lyric);
bool extend = mu::contains(extendedLyrics, lyric);
const GraceNoteLyrics gnl = GraceNoteLyrics(lyric, extend, lyricNo);
gnLyrics.push_back(gnl);
}
Expand Down
6 changes: 3 additions & 3 deletions importexport/musicxml/importmxmlpass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class MusicXmlLyricsExtend {
void setExtend(const int no, const int track, const Fraction& tick, const Lyrics* prevAddedLyrics);

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

struct GraceNoteLyrics {
Expand All @@ -131,7 +131,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 @@ -142,7 +142,7 @@ class MusicXMLParserLyric {
Score* const _score = nullptr; // the score
MxmlLogger* _logger = nullptr; ///< 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 aa6c7cb

Please sign in to comment.