Skip to content

Commit

Permalink
[musicxml] Replaced QList to std::vector
Browse files Browse the repository at this point in the history
Backport of musescore#21205, part 1
  • Loading branch information
igorkorsukov authored and Jojo-Schmitz committed Jan 26, 2024
1 parent c911efd commit f31e0f7
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 118 deletions.
26 changes: 13 additions & 13 deletions importexport/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ static void findTrills(const Measure* const measure, int strack, int etrack, Tri
// helpers for ::calcDivisions
//---------------------------------------------------------

typedef QList<int> IntVector;
typedef std::vector<int> IntVector;
static IntVector integers;
static IntVector primes;

Expand All @@ -1020,7 +1020,7 @@ static IntVector primes;
static bool canDivideBy(int d)
{
bool res = true;
for (int i = 0; i < integers.count(); i++) {
for (size_t i = 0; i < integers.size(); i++) {
if ((integers[i] <= 1) || ((integers[i] % d) != 0)) {
res = false;
}
Expand All @@ -1032,15 +1032,15 @@ static bool canDivideBy(int d)

static void divideBy(int d)
{
for (int i = 0; i < integers.count(); i++) {
for (size_t i = 0; i < integers.size(); i++) {
integers[i] /= d;
}
}

static void addInteger(int len)
{
if (len > 0 && !integers.contains(len)) {
integers.append(len);
if (len > 0 && !mu::contains(integers, len)) {
integers.push_back(len);
}
}

Expand Down Expand Up @@ -1096,10 +1096,10 @@ void ExportMusicXml::calcDivisions()
// init
integers.clear();
primes.clear();
integers.append(MScore::division);
primes.append(2);
primes.append(3);
primes.append(5);
integers.push_back(MScore::division);
primes.push_back(2);
primes.push_back(3);
primes.push_back(5);

const QList<Part*>& il = _score->parts();

Expand Down Expand Up @@ -1162,7 +1162,7 @@ void ExportMusicXml::calcDivisions()
}

// do it: divide by all primes as often as possible
for (int u = 0; u < primes.count(); u++)
for (size_t u = 0; u < primes.size(); u++)
while (canDivideBy(primes[u]))
divideBy(primes[u]);

Expand Down Expand Up @@ -2717,7 +2717,7 @@ static void tremoloSingleStartStop(Chord* chord, Notations& notations, Ornaments
// fermatas
//---------------------------------------------------------

static void fermatas(const QVector<Element*>& cra, XmlWriter& xml, Notations& notations)
static void fermatas(const std::vector<Element*>& cra, XmlWriter& xml, Notations& notations)
{
for (const Element* e : cra) {
if (!e->isFermata())
Expand Down Expand Up @@ -3057,7 +3057,7 @@ void ExportMusicXml::chordAttributes(Chord* chord, Notations& notations, Technic
TrillHash& trillStart, TrillHash& trillStop)
{
if (!chord->isGrace()) {
QVector<Element*> fl;
std::vector<Element*> fl;
for (Element* e : chord->segment()->annotations()) {
if (e->track() == chord->track() && e->isFermata())
fl.push_back(e);
Expand Down Expand Up @@ -3983,7 +3983,7 @@ void ExportMusicXml::rest(Rest* rest, int staff, const std::vector<Lyrics*>* ll)
_xml.tag("staff", staff);

Notations notations;
QVector<Element*> fl;
std::vector<Element*> fl;
for (Element* e : rest->segment()->annotations()) {
if (e->isFermata() && e->track() == rest->track())
fl.push_back(e);
Expand Down
48 changes: 24 additions & 24 deletions importexport/musicxml/importmxmlpass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void MusicXMLParserPass1::addError(const QString& error)
Initialize members as required for reading the MusicXML part element.
TODO: factor out part reading into a separate class
TODO: preferably use automatically initialized variables
Note that Qt automatically initializes new elements in QVector (tuplets).
Note that Qt automatically initializes new elements in std::vector (tuplets).
*/

void MusicXMLParserPass1::initPartState(const QString& /* partId */)
Expand All @@ -230,19 +230,19 @@ void MusicXMLParserPass1::initPartState(const QString& /* partId */)
Return false on error.
*/

bool MusicXMLParserPass1::determineMeasureLength(QVector<Fraction>& ml) const
bool MusicXMLParserPass1::determineMeasureLength(std::vector<Fraction>& ml) const
{
ml.clear();

// determine number of measures: max number of measures in any part
int nMeasures = 0;
foreach (const MusicXmlPart &part, _parts) {
size_t nMeasures = 0;
for (const MusicXmlPart &part : _parts) {
if (part.nMeasures() > nMeasures)
nMeasures = part.nMeasures();
}

// determine max length of a specific measure in all parts
for (int i = 0; i < nMeasures; ++i) {
for (size_t i = 0; i < nMeasures; ++i) {
Fraction maxMeasDur;
foreach (const MusicXmlPart &part, _parts) {
if (i < part.nMeasures()) {
Expand All @@ -252,7 +252,7 @@ bool MusicXMLParserPass1::determineMeasureLength(QVector<Fraction>& ml) const
}
}
//qDebug("determineMeasureLength() measure %d %s (%d)", i, qPrintable(maxMeasDur.print()), maxMeasDur.ticks());
ml.append(maxMeasDur);
ml.push_back(maxMeasDur);
}
return true;
}
Expand Down Expand Up @@ -440,9 +440,9 @@ int MusicXMLParserPass1::trackForPart(const QString& id) const
Return the measure start time for measure \a i.
*/

Fraction MusicXMLParserPass1::getMeasureStart(const int i) const
Fraction MusicXMLParserPass1::getMeasureStart(const size_t i) const
{
if (0 <= i && i < _measureStart.size())
if (i < _measureStart.size())
return _measureStart.at(i);
else
return Fraction(0, 0); // invalid
Expand Down Expand Up @@ -856,7 +856,7 @@ void MusicXMLParserPass1::createDefaultHeader(Score* const score)
*/

void MusicXMLParserPass1::createMeasuresAndVboxes(Score* const score,
const QVector<Fraction>& ml, const QVector<Fraction>& ms,
const std::vector<Fraction>& ml, const std::vector<Fraction>& ms,
const std::set<int>& systemStartMeasureNrs,
const std::set<int>& pageStartMeasureNrs,
const CreditWordsList& crWords,
Expand All @@ -866,7 +866,7 @@ void MusicXMLParserPass1::createMeasuresAndVboxes(Score* const score,
createDefaultHeader(score);

int pageNr = 0;
for (int i = 0; i < ml.size(); ++i) {
for (size_t i = 0; i < ml.size(); ++i) {

VBox* vbox = nullptr;

Expand Down Expand Up @@ -907,7 +907,7 @@ void MusicXMLParserPass1::createMeasuresAndVboxes(Score* const score,
or start tick measure equals start tick previous measure plus length previous measure
*/

static void determineMeasureStart(const QVector<Fraction>& ml, QVector<Fraction>& ms)
static void determineMeasureStart(const std::vector<Fraction>& ml, std::vector<Fraction>& ms)
{
ms.resize(ml.size());
if (!(ms.size() > 0))
Expand All @@ -916,7 +916,7 @@ static void determineMeasureStart(const QVector<Fraction>& ml, QVector<Fraction>
// first measure starts at t = 0
ms[0] = Fraction(0, 1);
// all others start at start time previous measure plus length previous measure
for (int i = 1; i < ml.size(); i++)
for (size_t i = 1; i < ml.size(); i++)
ms[i] = ms.at(i - 1) + ml.at(i - 1);
//for (int i = 0; i < ms.size(); i++)
// qDebug("measurestart ms[%d] %s", i + 1, qPrintable(ms.at(i).print()));
Expand Down Expand Up @@ -967,7 +967,7 @@ static void dumpCredits(const CreditWordsList& credits)
Required by TimeSigMap::tickValues(), called (indirectly) by Segment::add().
*/

static void fixupSigmap(MxmlLogger* logger, Score* score, const QVector<Fraction>& measureLength)
static void fixupSigmap(MxmlLogger* logger, Score* score, const std::vector<Fraction>& measureLength)
{
auto it = score->sigmap()->find(0);

Expand All @@ -977,7 +977,7 @@ static void fixupSigmap(MxmlLogger* logger, Score* score, const QVector<Fraction
// use length of first measure instead time signature.
// if there is no first measure, we probably don't care,
// but set a default anyway.
Fraction tsig = measureLength.isEmpty() ? Fraction(4, 4) : measureLength.at(0);
Fraction tsig = measureLength.empty() ? Fraction(4, 4) : measureLength.at(0);
score->sigmap()->add(0, tsig);
}
}
Expand Down Expand Up @@ -1178,7 +1178,7 @@ void MusicXMLParserPass1::scorePartwise()

// handle the implicit brackets:
// multi-staff parts w/o explicit brackets get a brace
for (Part const* const p : il) {
foreach (Part const* const p, il) {
if (p->nstaves() > 1 && !partSet.contains(p)) {
const int column = p->staff(0)->bracketLevels() + 1;
p->staff(0)->setBracketType(column, BracketType::BRACE);
Expand Down Expand Up @@ -1469,7 +1469,7 @@ void MusicXMLParserPass1::credit(CreditWordsList& credits)
// use credit-type only if exactly one was found
QString crtype = (crtypes.size() == 1) ? crtypes.at(0) : "";
CreditWords* cw = new CreditWords(page, crtype, defaultx, defaulty, fontSize, justify, halign, valign, crwords);
credits.append(cw);
credits.push_back(cw);
}

}
Expand Down Expand Up @@ -2817,8 +2817,8 @@ void MusicXMLParserPass1::direction(const QString& partId, const Fraction cTime)
// note: file order is direction-type first, then staff
// this means staff is still unknown when direction-type is handled

QList<MxmlOctaveShiftDesc> starts;
QList<MxmlOctaveShiftDesc> stops;
std::vector<MxmlOctaveShiftDesc> starts;
std::vector<MxmlOctaveShiftDesc> stops;
int staff = 0;

while (_e.readNextStartElement()) {
Expand All @@ -2840,7 +2840,7 @@ void MusicXMLParserPass1::direction(const QString& partId, const Fraction cTime)
}

// handle the stops first
foreach (auto desc, stops) {
for (const MxmlOctaveShiftDesc& desc : stops) {
if (_octaveShifts.contains(desc.num)) {
MxmlOctaveShiftDesc prevDesc = _octaveShifts.value(desc.num);
if (prevDesc.tp == MxmlOctaveShiftDesc::Type::UP
Expand All @@ -2858,7 +2858,7 @@ void MusicXMLParserPass1::direction(const QString& partId, const Fraction cTime)
}

// then handle the starts
foreach (auto desc, starts) {
for (const MxmlOctaveShiftDesc& desc : starts) {
if (_octaveShifts.contains(desc.num)) {
MxmlOctaveShiftDesc prevDesc = _octaveShifts.value(desc.num);
if (prevDesc.tp == MxmlOctaveShiftDesc::Type::STOP) {
Expand All @@ -2884,8 +2884,8 @@ void MusicXMLParserPass1::direction(const QString& partId, const Fraction cTime)
*/

void MusicXMLParserPass1::directionType(const Fraction cTime,
QList<MxmlOctaveShiftDesc>& starts,
QList<MxmlOctaveShiftDesc>& stops)
std::vector<MxmlOctaveShiftDesc>& starts,
std::vector<MxmlOctaveShiftDesc>& stops)
{
while (_e.readNextStartElement()) {
if (_e.name() == "octave-shift") {
Expand All @@ -2908,9 +2908,9 @@ void MusicXMLParserPass1::directionType(const Fraction cTime,
osDesc.num = n;
if (osDesc.tp == MxmlOctaveShiftDesc::Type::UP
|| osDesc.tp == MxmlOctaveShiftDesc::Type::DOWN)
starts.append(osDesc);
starts.push_back(osDesc);
else if (osDesc.tp == MxmlOctaveShiftDesc::Type::STOP)
stops.append(osDesc);
stops.push_back(osDesc);
}
else {
_logger->logError(QString("invalid octave-shift number %1").arg(number), &_e);
Expand Down
12 changes: 6 additions & 6 deletions importexport/musicxml/importmxmlpass1.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class MusicXMLParserPass1 {
void transpose(const QString& partId, const Fraction& tick);
void divisions();
void direction(const QString& partId, const Fraction cTime);
void directionType(const Fraction cTime, QList<MxmlOctaveShiftDesc>& starts, QList<MxmlOctaveShiftDesc>& stops);
void directionType(const Fraction cTime, std::vector<MxmlOctaveShiftDesc>& starts, std::vector<MxmlOctaveShiftDesc>& stops);
void handleOctaveShift(const Fraction cTime, const QString& type, short size, MxmlOctaveShiftDesc& desc);
void notations(MxmlStartStop& tupletStartStop);
void note(const QString& partId, const Fraction cTime, Fraction& missingPrev, Fraction& dura, Fraction& missingCurr, VoiceOverlapDetector& vod, MxmlTupletStates& tupletStates);
Expand All @@ -159,7 +159,7 @@ class MusicXMLParserPass1 {
void pitch(int& step, float& alter, int& oct);
void rest();
void skipLogCurrElem();
bool determineMeasureLength(QVector<Fraction>& ml) const;
bool determineMeasureLength(std::vector<Fraction>& ml) const;
VoiceList getVoiceList(const QString id) const;
bool determineStaffMoveVoice(const QString& id, const int mxStaff, const int& mxVoice,
int& msMove, int& msTrack, int& msVoice) const;
Expand All @@ -172,7 +172,7 @@ class MusicXMLParserPass1 {
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;
Fraction getMeasureStart(const int i) const;
Fraction getMeasureStart(const size_t i) const;
int octaveShift(const QString& id, const int staff, const Fraction f) const;
const CreditWordsList& credits() const { return _credits; }
bool hasBeamingInfo() const { return _hasBeamingInfo; }
Expand All @@ -184,7 +184,7 @@ class MusicXMLParserPass1 {
void insertSeenDenominator(int val) { _seenDenominators.emplace(val); }
void createDefaultHeader(Score* const score);
void createMeasuresAndVboxes(Score* const score,
const QVector<Fraction>& ml, const QVector<Fraction>& ms,
const std::vector<Fraction>& ml, const std::vector<Fraction>& ms,
const std::set<int>& systemStartMeasureNrs,
const std::set<int>& pageStartMeasureNrs,
const CreditWordsList& crWords,
Expand All @@ -204,8 +204,8 @@ class MusicXMLParserPass1 {
QMap<QString, MusicXmlPart> _parts; ///< Parts data, mapped on part id
std::set<int> _systemStartMeasureNrs; ///< Measure numbers of measures starting a page
std::set<int> _pageStartMeasureNrs; ///< Measure numbers of measures starting a page
QVector<Fraction> _measureLength; ///< Length of each measure
QVector<Fraction> _measureStart; ///< Start time of each measure
std::vector<Fraction> _measureLength; ///< Length of each measure
std::vector<Fraction> _measureStart; ///< Start time of each measure
CreditWordsList _credits; ///< All credits collected
PartMap _partMap; ///< TODO merge into MusicXmlPart ??
QMap<QString, MusicXMLInstruments> _instruments; ///< instruments for each part, mapped on part id
Expand Down
Loading

0 comments on commit f31e0f7

Please sign in to comment.