Skip to content

Commit

Permalink
fix #24877
Browse files Browse the repository at this point in the history
  • Loading branch information
wschweer committed Mar 15, 2014
1 parent 97a52fc commit f367f8a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 75 deletions.
49 changes: 14 additions & 35 deletions libmscore/chordlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,10 +1428,11 @@ void ParsedChord::addToken(QString s, ChordTokenClass tc)
// a private id is assigned for id = 0
//---------------------------------------------------------

ChordDescription::ChordDescription(int i, ChordList* cl)
ChordDescription::ChordDescription(int i)
{
if (!i)
i = --(cl->privateID);
// i = --(cl->privateID);
i = -- ChordList::privateID;
id = i;
generated = false;
renderListGenerated = false;
Expand All @@ -1444,9 +1445,9 @@ ChordDescription::ChordDescription(int i, ChordList* cl)
// a private id is always assigned
//---------------------------------------------------------

ChordDescription::ChordDescription(const QString& name, ChordList* cl)
ChordDescription::ChordDescription(const QString& name)
{
id = --(cl->privateID);
id = -- ChordList::privateID;
generated = true;
names.append(name);
renderListGenerated = false;
Expand Down Expand Up @@ -1548,25 +1549,6 @@ void ChordDescription::write(Xml& xml) const

int ChordList::privateID = -1000;

ChordList::ChordList()
{
}

//---------------------------------------------------------
// ~ChordList
//---------------------------------------------------------

ChordList::~ChordList()
{
if (isDetached()) {
QMapIterator<int, ChordDescription*> i(*this);
while(i.hasNext()) {
i.next();
delete i.value();
}
}
}

//---------------------------------------------------------
// read
//---------------------------------------------------------
Expand Down Expand Up @@ -1620,21 +1602,18 @@ void ChordList::read(XmlReader& e)
// if no id attribute (id == 0), then assign it a private id
// user chords that match these ChordDescriptions will be treated as normal recognized chords
// except that the id will not be written to the score file
ChordDescription* cd = 0;
if (id)
cd = take(id);
if (!cd)
cd = new ChordDescription(id, this);
ChordDescription cd = (id && contains(id)) ? take(id) : ChordDescription(id);

// record updated id
id = cd->id;
id = cd.id;
// read rest of description
cd->read(e);
cd.read(e);
// restore updated id
cd->id = id;
cd.id = id;
// throw away previously parsed chords
cd->parsedChords.clear();
cd.parsedChords.clear();
// generate any missing info (including new parsed chords)
cd->complete(0,this);
cd.complete(0,this);
// add to list
insert(id, cd);
}
Expand Down Expand Up @@ -1674,8 +1653,8 @@ void ChordList::write(Xml& xml) const
writeRenderList(xml, &renderListRoot, "renderRoot");
if (!renderListBase.isEmpty())
writeRenderList(xml, &renderListBase, "renderBase");
foreach(ChordDescription* d, *this)
d->write(xml);
foreach(const ChordDescription& d, *this)
d.write(xml);
}

//---------------------------------------------------------
Expand Down
10 changes: 4 additions & 6 deletions libmscore/chordlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ struct ChordDescription {
QString _quality;

public:
ChordDescription(int, ChordList*);
ChordDescription(const QString&, ChordList*);
ChordDescription() {}
ChordDescription(int);
ChordDescription(const QString&);
QString quality() const { return _quality; }
void complete(ParsedChord* pc, const ChordList*);
void read(XmlReader&);
Expand Down Expand Up @@ -223,7 +224,7 @@ struct ChordFont {
// ChordList
//---------------------------------------------------------

class ChordList : public QMap<int, ChordDescription*> {
class ChordList : public QMap<int, ChordDescription> {
QHash<QString, ChordSymbol> symbols;

public:
Expand All @@ -233,9 +234,6 @@ class ChordList : public QMap<int, ChordDescription*> {
QList<ChordToken> chordTokenList;
static int privateID;

ChordList();

virtual ~ChordList();
void write(Xml& xml) const;
void read(XmlReader&);
bool read(const QString&);
Expand Down
55 changes: 27 additions & 28 deletions libmscore/harmony.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ QString Harmony::harmonyName()
hc.add(_degreeList);
// try to find the chord in chordList
const ChordDescription* newExtension = 0;
ChordList* cl = score()->style()->chordList();
foreach(const ChordDescription* cd, *cl) {
if (cd->chord == hc && !cd->names.isEmpty()) {
newExtension = cd;
const ChordList* cl = score()->style()->chordList();
for (const ChordDescription& cd : *cl) {
if (cd.chord == hc && !cd.names.isEmpty()) {
newExtension = &cd;
break;
}
}
Expand Down Expand Up @@ -117,11 +117,11 @@ void Harmony::resolveDegreeList()
// _descr->chord.print();

// try to find the chord in chordList
ChordList* cl = score()->style()->chordList();
foreach(const ChordDescription* cd, *cl) {
if ((cd->chord == hc) && !cd->names.isEmpty()) {
qDebug("ResolveDegreeList: found in table as %s", qPrintable(cd->names.front()));
_id = cd->id;
const ChordList* cl = score()->style()->chordList();
foreach(const ChordDescription& cd, *cl) {
if ((cd.chord == hc) && !cd.names.isEmpty()) {
qDebug("ResolveDegreeList: found in table as %s", qPrintable(cd.names.front()));
_id = cd.id;
_degreeList.clear();
return;
}
Expand Down Expand Up @@ -679,14 +679,14 @@ const ChordDescription* Harmony::fromXml(const QString& kind, const QList<HDegre
degrees.append(d.text());

QString lowerCaseKind = kind.toLower();
ChordList* cl = score()->style()->chordList();
foreach(const ChordDescription* cd, *cl) {
QString k = cd->xmlKind;
const ChordList* cl = score()->style()->chordList();
foreach(const ChordDescription& cd, *cl) {
QString k = cd.xmlKind;
QString lowerCaseK = k.toLower(); // required for xmlKind Tristan
QStringList d = cd->xmlDegrees;
QStringList d = cd.xmlDegrees;
if ((lowerCaseKind == lowerCaseK) && (d == degrees)) {
// qDebug("harmony found in db: %s %s -> %d", qPrintable(kind), qPrintable(degrees), cd->id);
return cd;
return &cd;
}
}
return 0;
Expand All @@ -701,10 +701,10 @@ const ChordDescription* Harmony::fromXml(const QString& kind, const QList<HDegre
const ChordDescription* Harmony::fromXml(const QString& kind)
{
QString lowerCaseKind = kind.toLower();
ChordList* cl = score()->style()->chordList();
foreach(const ChordDescription* cd, *cl) {
if (lowerCaseKind == cd->xmlKind)
return cd;
const ChordList* cl = score()->style()->chordList();
foreach(const ChordDescription& cd, *cl) {
if (lowerCaseKind == cd.xmlKind)
return &cd;
}
return 0;
}
Expand Down Expand Up @@ -748,14 +748,14 @@ const ChordDescription* Harmony::descr(const QString& name, const ParsedChord* p
const ChordList* cl = score()->style()->chordList();
const ChordDescription* match = 0;
if (cl) {
foreach (const ChordDescription* cd, *cl) {
foreach (const QString& s, cd->names) {
foreach (const ChordDescription& cd, *cl) {
foreach (const QString& s, cd.names) {
if (s == name)
return cd;
return &cd;
else if (pc) {
foreach (const ParsedChord& sParsed, cd->parsedChords) {
foreach (const ParsedChord& sParsed, cd.parsedChords) {
if (sParsed == *pc)
match = cd;
match = &cd;
}
}
}
Expand Down Expand Up @@ -812,13 +812,12 @@ const ChordDescription* Harmony::getDescription(const QString& name, const Parse
const ChordDescription* Harmony::generateDescription()
{
ChordList* cl = score()->style()->chordList();
ChordDescription* cd = new ChordDescription(_textName, cl);
cd->complete(_parsedForm, cl);
ChordDescription cd(_textName);
cd.complete(_parsedForm, cl);
// remove parsed chord from description
// so we will only match it literally in the future
cd->parsedChords.clear();
cl->insert(cd->id, cd);
return cd;
cd.parsedChords.clear();
return &*cl->insert(cd.id, cd);
}

//---------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion libmscore/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,9 @@ void StyleData::save(Xml& xml, bool optimize) const

const ChordDescription* StyleData::chordDescription(int id) const
{
return _chordList.value(id);
if (!_chordList.contains(id))
return 0;
return &*_chordList.find(id);
}

//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/style.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ class MStyle {
bool isDefault(StyleIdx idx) const;
const ChordDescription* chordDescription(int id) const;
ChordList* chordList();

void setChordList(ChordList*, bool custom = true); // Style gets ownership of ChordList

const TextStyle& textStyle(int) const;
Expand Down
10 changes: 5 additions & 5 deletions mscore/harmonyedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ void ChordStyleEditor::loadChordDescriptionFile(const QString& s)
void ChordStyleEditor::setChordList(ChordList* cl)
{
harmonyList->clear();
foreach (ChordDescription* d, *cl) {
foreach (const ChordDescription& d, *cl) {
QTreeWidgetItem* item = new QTreeWidgetItem;
item->setData(0, Qt::UserRole, QVariant::fromValue<void*>(d));
item->setText(0, QString("%1").arg(d->id));
if (!d->names.isEmpty())
item->setText(1, QString("%1").arg(d->names.front()));
item->setData(0, Qt::UserRole, QVariant::fromValue<void*>((void*)&d));
item->setText(0, QString("%1").arg(d.id));
if (!d.names.isEmpty())
item->setText(1, QString("%1").arg(d.names.front()));
harmonyList->addTopLevelItem(item);
}
delete chordList;
Expand Down

0 comments on commit f367f8a

Please sign in to comment.