diff options
-rw-r--r-- | muse/al/xml.cpp | 13 | ||||
-rw-r--r-- | muse/al/xml.h | 4 | ||||
-rw-r--r-- | muse/muse/instruments/editinstrument.cpp | 19 | ||||
-rw-r--r-- | muse/muse/instruments/minstrument.cpp | 81 | ||||
-rw-r--r-- | muse/muse/instruments/minstrument.h | 18 | ||||
-rw-r--r-- | muse/muse/midictrl.cpp | 2 | ||||
-rw-r--r-- | muse/muse/midiedit/drummap.cpp | 51 | ||||
-rw-r--r-- | muse/muse/midiedit/drummap.h | 1 |
8 files changed, 151 insertions, 38 deletions
diff --git a/muse/al/xml.cpp b/muse/al/xml.cpp index a117a5e7..121922a5 100644 --- a/muse/al/xml.cpp +++ b/muse/al/xml.cpp @@ -117,6 +117,13 @@ void Xml::stag(const char* format, ...) ++level; } +void Xml::stag(const QString& s) + { + putLevel(); + *this << '<' << s << '>' << endl; + ++level; + } + //--------------------------------------------------------- // etag //--------------------------------------------------------- @@ -146,6 +153,12 @@ void Xml::tagE(const char* format, ...) *this << "/>" << endl; } +void Xml::tagE(const QString& s) + { + putLevel(); + *this << '<' << s << "/>" << endl; + } + void Xml::tag(const char* name, int val) { putLevel(); diff --git a/muse/al/xml.h b/muse/al/xml.h index e71b57a8..6208e8ee 100644 --- a/muse/al/xml.h +++ b/muse/al/xml.h @@ -42,8 +42,10 @@ class Xml : public QTextStream { void nput(const char* format, ...); void stag(const char* format, ...); - void etag(const char* format); + void stag(const QString&); + void etag(const char*); + void tagE(const QString&); void tagE(const char* format, ...); void tdata(const QString&); diff --git a/muse/muse/instruments/editinstrument.cpp b/muse/muse/instruments/editinstrument.cpp index de4bdc4c..25fdac10 100644 --- a/muse/muse/instruments/editinstrument.cpp +++ b/muse/muse/instruments/editinstrument.cpp @@ -22,6 +22,7 @@ #include "minstrument.h" #include "ctrl.h" #include "midictrl.h" +#include "al/xml.h" //--------------------------------------------------------- // EditInstrument @@ -189,6 +190,24 @@ void EditInstrument::fileSaveAs() tr("MusE: Save Instrument Definition"), path, tr("Instrument Definition (*.idf)")); + if (s.isEmpty()) + return; + QFile f(s); + if (!f.open(QIODevice::WriteOnly)) { + QString s("Creating file failed: "); + s += strerror(errno); + QMessageBox::critical(this, + tr("MusE: Create file failed"), s); + return; + } + Xml xml(&f); + instrument->write(xml); + f.close(); + if (f.error()) { + QString s = QString("Write File\n") + f.fileName() + QString("\nfailed: ") + + f.errorString(); + QMessageBox::critical(this, tr("MusE: Write File failed"), s); + } } //--------------------------------------------------------- diff --git a/muse/muse/instruments/minstrument.cpp b/muse/muse/instruments/minstrument.cpp index dfd4a8be..ae02dd3c 100644 --- a/muse/muse/instruments/minstrument.cpp +++ b/muse/muse/instruments/minstrument.cpp @@ -37,6 +37,7 @@ MidiInstrument* genericMidiInstrument; Patch::Patch() { drumMap = 0; + categorie = -1; } Patch::~Patch() @@ -211,7 +212,7 @@ MidiInstrument::~MidiInstrument() // readPatchGroup //--------------------------------------------------------- -void PatchGroup::read(QDomNode node) +void PatchGroup::read(QDomNode node, MidiInstrument* instrument) { for (; !node.isNull(); node = node.nextSibling()) { QDomElement e = node.toElement(); @@ -219,12 +220,12 @@ void PatchGroup::read(QDomNode node) if (tag == "Patch") { Patch* patch = new Patch; - patch->read(node, false); + patch->read(node, false, instrument); patches.push_back(patch); } else if (tag == "drummap") { Patch* patch = new Patch; - patch->read(node, true); + patch->read(node, true, instrument); patches.push_back(patch); } else if (!tag.isEmpty()) @@ -237,14 +238,16 @@ void PatchGroup::read(QDomNode node) // read //--------------------------------------------------------- -void Patch::read(QDomNode node, bool dr) +void Patch::read(QDomNode node, bool dr, MidiInstrument* instrument) { QDomElement e = node.toElement(); - name = e.attribute(QString("name")); - typ = e.attribute(QString("mode"), "-1").toInt(); - hbank = e.attribute(QString("hbank"), "-1").toInt(); - lbank = e.attribute(QString("lbank"), "-1").toInt(); - prog = e.attribute(QString("prog"), "0").toInt(); + name = e.attribute("name"); + typ = e.attribute("mode", "-1").toInt(); + hbank = e.attribute("hbank", "-1").toInt(); + lbank = e.attribute("lbank", "-1").toInt(); + prog = e.attribute("prog", "0").toInt(); + QString cat = e.attribute("cat"); + categorie = instrument->categories().indexOf(cat); drumMap = 0; if (!dr) return; @@ -266,6 +269,30 @@ void Patch::read(QDomNode node, bool dr) } //--------------------------------------------------------- +// write +//--------------------------------------------------------- + +void Patch::write(Xml& xml) + { + if (drumMap == 0) { + QString s = QString("Patch name=\"%1\"").arg(name); + if (typ != -1) + s += QString(" mode=\"%d\"").arg(typ); + s += QString(" hbank=\"%1\" lbank=\"%2\" prog=\"%3\"").arg(hbank).arg(lbank).arg(prog); + xml.tagE(s); + return; + } + QString s = QString("drummap name=\"%1\"").arg(name); + s += QString(" hbank=\"%1\" lbank=\"%2\" prog=\"%3\"").arg(hbank).arg(lbank).arg(prog); + xml.stag(s); + for (int i = 0; i < DRUM_MAPSIZE; ++i) { + DrumMapEntry* dm = drumMap->entry(i); + dm->write(xml); + } + xml.etag("drummap"); + } + +//--------------------------------------------------------- // readMidiState //--------------------------------------------------------- @@ -288,7 +315,7 @@ void MidiInstrument::read(QDomNode node) QString tag(e.tagName()); if (tag == "Patch") { Patch* patch = new Patch; - patch->read(node, false); + patch->read(node, false, this); if (pg.empty()) { PatchGroup p; p.patches.push_back(patch); @@ -297,11 +324,13 @@ void MidiInstrument::read(QDomNode node) else pg[0].patches.push_back(patch); } - else if (tag == "Category") - ; // TODO "Category" + else if (tag == "Category") { + QString name = e.attribute(QString("name")); + _categories.append(name); + } else if (tag == "drummap") { Patch* patch = new Patch; - patch->read(node, true); + patch->read(node, true, this); if (pg.empty()) { PatchGroup p; p.patches.push_back(patch); @@ -313,7 +342,7 @@ void MidiInstrument::read(QDomNode node) else if (tag == "PatchGroup") { PatchGroup p; p.name = e.attribute("name"); - p.read(node.firstChild()); + p.read(node.firstChild(), this); pg.push_back(p); } else if (tag == "Controller") { @@ -475,4 +504,28 @@ MidiController* MidiInstrument::midiController(int num) const return c; } +//--------------------------------------------------------- +// write +//--------------------------------------------------------- + +void MidiInstrument::write(Xml& xml) + { + xml.header(); + xml.stag("muse version=\"2.1\""); + xml.stag("MidiInstrument name=\"%s\"", iname().toUtf8().data()); + + foreach(const QString& s, _categories) + xml.tagE("Category name=\"%s\"", s.toUtf8().data()); + + std::vector<PatchGroup>* pg = groups(); + for (std::vector<PatchGroup>::iterator g = pg->begin(); g != pg->end(); ++g) { + xml.stag("PatchGroup name=\"%s\"", g->name.toUtf8().data()); + for (iPatch p = g->patches.begin(); p != g->patches.end(); ++p) + (*p)->write(xml); + xml.etag("PatchGroup"); + } + for (iMidiController ic = _controller->begin(); ic != _controller->end(); ++ic) + (*ic)->write(xml); + xml.etag("MidiInstrument"); + } diff --git a/muse/muse/instruments/minstrument.h b/muse/muse/instruments/minstrument.h index f8e7f99b..5c7b081e 100644 --- a/muse/muse/instruments/minstrument.h +++ b/muse/muse/instruments/minstrument.h @@ -23,12 +23,18 @@ #include "globaldefs.h" +namespace AL { + class Xml; + }; +using AL::Xml; + class MidiOutPort; class EventList; class MidiControllerList; class MidiController; class MidiEvent; class DrumMap; +class MidiInstrument; //--------------------------------------------------------- // Patch @@ -38,8 +44,11 @@ struct Patch { signed char typ; // 1 - GM 2 - GS 4 - XG signed char hbank, lbank, prog; QString name; + int categorie; DrumMap* drumMap; - void read(QDomNode, bool); + + void read(QDomNode, bool, MidiInstrument*); + void write(Xml& xml); Patch(); ~Patch(); @@ -56,7 +65,7 @@ typedef PatchList::const_iterator ciPatch; struct PatchGroup { QString name; PatchList patches; - void read(QDomNode); + void read(QDomNode, MidiInstrument*); }; struct SysEx { @@ -79,6 +88,7 @@ class MidiInstrument { void init(); protected: + QList<QString> _categories; EventList* _midiInit; EventList* _midiReset; EventList* _midiState; @@ -116,10 +126,12 @@ class MidiInstrument { virtual void populatePatchPopup(QMenu*, int); void read(QDomNode); + void write(Xml& xml); std::vector<SysEx>* sysexList() { return &sysex; } MidiController* midiController(int num) const; - std::vector<PatchGroup>* groups() { return &pg; } + std::vector<PatchGroup>* groups() { return &pg; } + const QList<QString>& categories() const { return _categories; } }; //--------------------------------------------------------- diff --git a/muse/muse/midictrl.cpp b/muse/muse/midictrl.cpp index fff81bf5..b9a629d5 100644 --- a/muse/muse/midictrl.cpp +++ b/muse/muse/midictrl.cpp @@ -240,7 +240,7 @@ void MidiController::write(Xml& xml) const int l = _num & 0x7f; QString sl; - if (_num & 0xff == 0xff) + if ((_num & 0xff) == 0xff) sl = "Pitch"; else sl.setNum(l); diff --git a/muse/muse/midiedit/drummap.cpp b/muse/muse/midiedit/drummap.cpp index c8d3dadb..2e15786b 100644 --- a/muse/muse/midiedit/drummap.cpp +++ b/muse/muse/midiedit/drummap.cpp @@ -116,35 +116,46 @@ void DrumMap::write(Xml& xml) xml.stag("drummap"); for (int i = 0; i < DRUM_MAPSIZE; ++i) { DrumMapEntry* dm = &map[i]; - xml.stag("entry"); - xml.tag("name", dm->name); - if (dm->quant != DEFAULT_QUANT) - xml.tag("quant", dm->quant); - if (dm->len != DEFAULT_LEN) - xml.tag("len", dm->len); - if (dm->channel != DEFAULT_CHANNEL) - xml.tag("channel", dm->channel); - if (dm->lv1 != DEFAULT_LV1) - xml.tag("lv1", dm->lv1); - if (dm->lv2 != DEFAULT_LV2) - xml.tag("lv2", dm->lv2); - if (dm->lv2 != DEFAULT_LV3) - xml.tag("lv3", dm->lv3); - if (dm->lv4 != DEFAULT_LV4) - xml.tag("lv4", dm->lv4); - xml.tag("enote", dm->enote); - xml.tag("anote", dm->anote); - xml.etag("entry"); + dm->write(xml); } xml.etag("drummap"); } //--------------------------------------------------------- +// write +//--------------------------------------------------------- + +void DrumMapEntry::write(Xml& xml) + { + xml.stag("entry"); + xml.tag("name", name); + if (quant != DEFAULT_QUANT) + xml.tag("quant", quant); + if (len != DEFAULT_LEN) + xml.tag("len", len); + if (channel != DEFAULT_CHANNEL) + xml.tag("channel", channel); + if (lv1 != DEFAULT_LV1) + xml.tag("lv1", lv1); + if (lv2 != DEFAULT_LV2) + xml.tag("lv2", lv2); + if (lv3 != DEFAULT_LV3) + xml.tag("lv3", lv3); + if (lv4 != DEFAULT_LV4) + xml.tag("lv4", lv4); + xml.tag("enote", enote); + if (anote != enote) + xml.tag("anote", anote); + xml.etag("entry"); + } + +//--------------------------------------------------------- // read //--------------------------------------------------------- void DrumMapEntry::read(QDomNode n) { + anote = -1; for (QDomNode node = n.firstChild(); !node.isNull(); node = node.nextSibling()) { QDomElement e = node.toElement(); QString tag(e.tagName()); @@ -176,6 +187,8 @@ void DrumMapEntry::read(QDomNode n) break; } } + if (anote = -1) + anote = enote; } //--------------------------------------------------------- diff --git a/muse/muse/midiedit/drummap.h b/muse/muse/midiedit/drummap.h index 66843a0c..0ec1d536 100644 --- a/muse/muse/midiedit/drummap.h +++ b/muse/muse/midiedit/drummap.h @@ -42,6 +42,7 @@ struct DrumMapEntry { bool mute; void read(QDomNode node); + void write(Xml& xml); }; //--------------------------------------------------------- |