diff options
author | Tim E. Real <termtech@rogers.com> | 2012-10-09 20:04:43 +0000 |
---|---|---|
committer | Tim E. Real <termtech@rogers.com> | 2012-10-09 20:04:43 +0000 |
commit | 0368494d2ba85b24da193512972ccfeada99cf52 (patch) | |
tree | fff25f5a6aecdd722c98a938fa9b03f1fec9febc /muse2/muse/instruments | |
parent | c5e6b8cfa9d8615a32ce2aad28f4d091482be91d (diff) |
!!! Song type is now removed !!! : See ChangeLog
Diffstat (limited to 'muse2/muse/instruments')
-rw-r--r-- | muse2/muse/instruments/editinstrument.cpp | 89 | ||||
-rw-r--r-- | muse2/muse/instruments/minstrument.cpp | 186 | ||||
-rw-r--r-- | muse2/muse/instruments/minstrument.h | 16 |
3 files changed, 131 insertions, 160 deletions
diff --git a/muse2/muse/instruments/editinstrument.cpp b/muse2/muse/instruments/editinstrument.cpp index 8378bd68..57c466b8 100644 --- a/muse2/muse/instruments/editinstrument.cpp +++ b/muse2/muse/instruments/editinstrument.cpp @@ -79,6 +79,14 @@ EditInstrument::EditInstrument(QWidget* parent, Qt::WFlags fl) toolBar->addAction(QWhatsThis::createAction(this)); Help->addAction(QWhatsThis::createAction(this)); + // REMOVE Tim. OBSOLETE. When gui boxes are finally removed. + checkBoxGM->setEnabled(false); + checkBoxGS->setEnabled(false); + checkBoxXG->setEnabled(false); + checkBoxGM->setVisible(false); + checkBoxGS->setVisible(false); + checkBoxXG->setVisible(false); + // populate instrument list // Populate common controller list. for(int i = 0; i < 128; ++i) @@ -1405,9 +1413,10 @@ void EditInstrument::patchChanged() spinBoxLBank->setEnabled(false); spinBoxProgram->setEnabled(false); checkBoxDrum->setEnabled(false); - checkBoxGM->setEnabled(false); - checkBoxGS->setEnabled(false); - checkBoxXG->setEnabled(false); + // REMOVE Tim. OBSOLETE. When gui boxes are finally removed. + //checkBoxGM->setEnabled(false); + //checkBoxGS->setEnabled(false); + //checkBoxXG->setEnabled(false); return; } @@ -1420,9 +1429,10 @@ void EditInstrument::patchChanged() spinBoxLBank->setEnabled(true); spinBoxProgram->setEnabled(true); checkBoxDrum->setEnabled(true); - checkBoxGM->setEnabled(true); - checkBoxGS->setEnabled(true); - checkBoxXG->setEnabled(true); + // REMOVE Tim. OBSOLETE. When gui boxes are finally removed. + //checkBoxGM->setEnabled(true); + //checkBoxGS->setEnabled(true); + //checkBoxXG->setEnabled(true); int hb = ((p->hbank + 1) & 0xff); int lb = ((p->lbank + 1) & 0xff); @@ -1431,9 +1441,10 @@ void EditInstrument::patchChanged() spinBoxLBank->setValue(lb); spinBoxProgram->setValue(pr); checkBoxDrum->setChecked(p->drum); - checkBoxGM->setChecked(p->typ & 1); - checkBoxGS->setChecked(p->typ & 2); - checkBoxXG->setChecked(p->typ & 4); + // REMOVE Tim. OBSOLETE. When gui boxes are finally removed. + //checkBoxGM->setChecked(p->typ & 1); + //checkBoxGS->setChecked(p->typ & 2); + //checkBoxXG->setChecked(p->typ & 4); } else // The item is a patch group item. @@ -1443,9 +1454,10 @@ void EditInstrument::patchChanged() spinBoxLBank->setEnabled(false); spinBoxProgram->setEnabled(false); checkBoxDrum->setEnabled(false); - checkBoxGM->setEnabled(false); - checkBoxGS->setEnabled(false); - checkBoxXG->setEnabled(false); + // REMOVE Tim. OBSOLETE. When gui boxes are finally removed. + //checkBoxGM->setEnabled(false); + //checkBoxGS->setEnabled(false); + //checkBoxXG->setEnabled(false); } } @@ -2550,7 +2562,7 @@ void EditInstrument::newPatchClicked() patch->hbank = hb; patch->lbank = lb; patch->prog = prg; - patch->typ = -1; + //patch->typ = -1; patch->drum = false; if(selpatch) @@ -2558,7 +2570,7 @@ void EditInstrument::newPatchClicked() hb = selpatch->hbank; lb = selpatch->lbank; prg = selpatch->prog; - patch->typ = selpatch->typ; + //patch->typ = selpatch->typ; patch->drum = selpatch->drum; } @@ -2638,9 +2650,10 @@ void EditInstrument::newPatchClicked() spinBoxLBank->setEnabled(true); spinBoxProgram->setEnabled(true); checkBoxDrum->setEnabled(true); - checkBoxGM->setEnabled(true); - checkBoxGS->setEnabled(true); - checkBoxXG->setEnabled(true); + // REMOVE Tim. OBSOLETE. When gui boxes are finally removed. + //checkBoxGM->setEnabled(true); + //checkBoxGS->setEnabled(true); + //checkBoxXG->setEnabled(true); oldPatchItem = 0; patchChanged(); @@ -2706,9 +2719,10 @@ void EditInstrument::newGroupClicked() spinBoxLBank->setEnabled(false); spinBoxProgram->setEnabled(false); checkBoxDrum->setEnabled(false); - checkBoxGM->setEnabled(false); - checkBoxGS->setEnabled(false); - checkBoxXG->setEnabled(false); + // REMOVE Tim. OBSOLETE. When gui boxes are finally removed. + //checkBoxGM->setEnabled(false); + //checkBoxGS->setEnabled(false); + //checkBoxXG->setEnabled(false); workingInstrument.setDirty(true); } @@ -2957,23 +2971,24 @@ void EditInstrument::updatePatch(MusECore::MidiInstrument* instrument, MusECore: } // there is no logical xor in c++ - bool a = p->typ & 1; - bool b = p->typ & 2; - bool c = p->typ & 4; - bool aa = checkBoxGM->isChecked(); - bool bb = checkBoxGS->isChecked(); - bool cc = checkBoxXG->isChecked(); - if ((a ^ aa) || (b ^ bb) || (c ^ cc)) { - int value = 0; - if (checkBoxGM->isChecked()) - value |= 1; - if (checkBoxGS->isChecked()) - value |= 2; - if (checkBoxXG->isChecked()) - value |= 4; - p->typ = value; - instrument->setDirty(true); - } +// REMOVE Tim. OBSOLETE. When gui boxes are finally removed. +// bool a = p->typ & 1; +// bool b = p->typ & 2; +// bool c = p->typ & 4; +// bool aa = checkBoxGM->isChecked(); +// bool bb = checkBoxGS->isChecked(); +// bool cc = checkBoxXG->isChecked(); +// if ((a ^ aa) || (b ^ bb) || (c ^ cc)) { +// int value = 0; +// if (checkBoxGM->isChecked()) +// value |= 1; +// if (checkBoxGS->isChecked()) +// value |= 2; +// if (checkBoxXG->isChecked()) +// value |= 4; +// p->typ = value; +// instrument->setDirty(true); +// } } //--------------------------------------------------------- diff --git a/muse2/muse/instruments/minstrument.cpp b/muse2/muse/instruments/minstrument.cpp index 196ce513..e2477e60 100644 --- a/muse2/muse/instruments/minstrument.cpp +++ b/muse2/muse/instruments/minstrument.cpp @@ -49,8 +49,6 @@ namespace MusECore { MidiInstrumentList midiInstruments; MidiInstrument* genericMidiInstrument; -static const char* gmdrumname = "GM-drums"; - //--------------------------------------------------------- // string2sysex // Return -1 if cannot be converted. @@ -369,7 +367,7 @@ MidiInstrument::~MidiInstrument() MidiInstrument& MidiInstrument::assign(const MidiInstrument& ins) { //--------------------------------------------------------- - // TODO: Copy the _initScript, and _midiInit, _midiReset, and _midiState lists. + // TODO: Copy the _initScript (if and when it is ever used) //--------------------------------------------------------- for(iMidiController i = _controller->begin(); i != _controller->end(); ++i) @@ -399,6 +397,10 @@ MidiInstrument& MidiInstrument::assign(const MidiInstrument& ins) _sysex.append(new MusECore::SysEx(*(ins.sysex().at(i)))); } + *(_midiInit) = *(ins._midiInit); + *(_midiReset) = *(ins._midiReset); + *(_midiState) = *(ins._midiState); + for (ciPatchGroup g = pg.begin(); g != pg.end(); ++g) { PatchGroup* pgp = *g; @@ -424,7 +426,7 @@ MidiInstrument& MidiInstrument::assign(const MidiInstrument& ins) { Patch* pp = *p; Patch* np = new Patch; - np->typ = pp->typ; + //np->typ = pp->typ; np->hbank = pp->hbank; np->lbank = pp->lbank; np->prog = pp->prog; @@ -448,11 +450,26 @@ MidiInstrument& MidiInstrument::assign(const MidiInstrument& ins) } //--------------------------------------------------------- +// midiType +//--------------------------------------------------------- + +MType MidiInstrument::midiType() const +{ + if(_name == "GM") + return MT_GM; + if(_name == "GS") + return MT_GS; + if(_name == "XG") + return MT_XG; + return MT_UNKNOWN; +} + +//--------------------------------------------------------- // reset // send note off to all channels //--------------------------------------------------------- -void MidiInstrument::reset(int portNo, MType) +void MidiInstrument::reset(int portNo) { MusECore::MidiPort* port = &MusEGlobal::midiPorts[portNo]; if(port->device() == 0) // p4.0.15 @@ -517,7 +534,7 @@ void PatchGroup::read(Xml& xml) void Patch::read(Xml& xml) { - typ = -1; + //typ = -1; hbank = -1; lbank = -1; prog = 0; @@ -535,8 +552,11 @@ void Patch::read(Xml& xml) case Xml::Attribut: if (tag == "name") name = xml.s2(); - else if (tag == "mode") - typ = xml.s2().toInt(); + else if (tag == "mode") // Obsolete + { + //typ = xml.s2().toInt(); + xml.s2().toInt(); + } else if (tag == "hbank") hbank = xml.s2().toInt(); else if (tag == "lbank") @@ -562,8 +582,8 @@ void Patch::read(Xml& xml) void Patch::write(int level, Xml& xml) { xml.nput(level, "<Patch name=\"%s\"", Xml::xmlString(name).toLatin1().constData()); - if(typ != -1) - xml.nput(" mode=\"%d\"", typ); + //if(typ != -1) + // xml.nput(" mode=\"%d\"", typ); // Obsolete if(hbank != -1) xml.nput(" hbank=\"%d\"", hbank); @@ -982,10 +1002,6 @@ void MidiInstrument::write(int level, Xml& xml) } xml.put(">"); - // ------------- - // TODO: What about Init, Reset, State, and InitScript ? - // ------------- - level++; for (ciPatchGroup g = pg.begin(); g != pg.end(); ++g) { PatchGroup* pgp = *g; @@ -1006,6 +1022,15 @@ void MidiInstrument::write(int level, Xml& xml) _sysex.at(i)->write(level, xml); } + xml.tag(level++, "Init"); + for(ciEvent ev=_midiInit->begin(); ev != _midiInit->end(); ++ev) + ev->second.write(level, xml, MusECore::Pos(0, true)); + xml.etag(--level, "Init"); + + // ------------- + // TODO: What about _midiReset, _midiState, and _initScript ? + // ------------- + writeDrummaps(level, xml); level--; @@ -1019,45 +1044,30 @@ void MidiInstrument::write(int level, Xml& xml) // populatePatchPopup //--------------------------------------------------------- -void MidiInstrument::populatePatchPopup(MusEGui::PopupMenu* menu, int chan, MType songType, bool drum) +void MidiInstrument::populatePatchPopup(MusEGui::PopupMenu* menu, int /*chan*/, bool drum) { menu->clear(); - int mask = 0; - bool drumchan = chan == 9; - switch (songType) { - case MT_XG: mask = 4; break; - case MT_GS: mask = 2; break; - case MT_GM: - if(drumchan) - { - int id = (0xff << 16) + (0xff << 8) + 0x00; // First patch - QAction* act = menu->addAction(gmdrumname); - act->setData(id); - return; - } - mask = 1; - break; - case MT_UNKNOWN: mask = 7; break; - } + //int mask = 7; + if (pg.size() > 1) { for (ciPatchGroup i = pg.begin(); i != pg.end(); ++i) { PatchGroup* pgp = *i; - MusEGui::PopupMenu* pm = new MusEGui::PopupMenu(pgp->name, menu, menu->stayOpen()); // Use the parent stayOpen here. - menu->addMenu(pm); - pm->setFont(MusEGlobal::config.fonts[0]); + MusEGui::PopupMenu* pm = 0; const PatchList& pl = pgp->patches; for (ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl) { const Patch* mp = *ipl; - if ((mp->typ & mask) && - ((drum && songType != MT_GM) || - (mp->drum == drumchan)) ) - { + if (//(mp->typ & mask) && + (mp->drum == drum)) { + if(!pm) { + pm = new MusEGui::PopupMenu(pgp->name, menu, menu->stayOpen()); // Use the parent stayOpen here. + menu->addMenu(pm); + pm->setFont(MusEGlobal::config.fonts[0]); + } int id = ((mp->hbank & 0xff) << 16) + ((mp->lbank & 0xff) << 8) + (mp->prog & 0xff); QAction* act = pm->addAction(mp->name); act->setData(id); } - } } } @@ -1066,12 +1076,12 @@ void MidiInstrument::populatePatchPopup(MusEGui::PopupMenu* menu, int chan, MTyp const PatchList& pl = pg.front()->patches; for (ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl) { const Patch* mp = *ipl; - if (mp->typ & mask) { + //if (mp->typ & mask) { int id = ((mp->hbank & 0xff) << 16) + ((mp->lbank & 0xff) << 8) + (mp->prog & 0xff); QAction* act = menu->addAction(mp->name); act->setData(id); - } + //} } } @@ -1083,7 +1093,7 @@ void MidiInstrument::populatePatchPopup(MusEGui::PopupMenu* menu, int chan, MTyp // getPatchName //--------------------------------------------------------- -QString MidiInstrument::getPatchName(int channel, int prog, MType mode, bool drum) +QString MidiInstrument::getPatchName(int /*channel*/, int prog, bool drum) { int pr = prog & 0xff; if(prog == CTRL_VAL_UNKNOWN || pr == 0xff) @@ -1091,38 +1101,17 @@ QString MidiInstrument::getPatchName(int channel, int prog, MType mode, bool dru int hbank = (prog >> 16) & 0xff; int lbank = (prog >> 8) & 0xff; - int tmask = 1; - bool drumchan = channel == 9; - bool hb = false; - bool lb = false; - switch (mode) { - case MT_GS: - tmask = 2; - hb = true; - break; - case MT_XG: - hb = true; - lb = true; - tmask = 4; - break; - case MT_GM: - if(drumchan) - return gmdrumname; - tmask = 1; - break; - default: - hb = true; // MSB bank matters - lb = true; // LSB bank matters - break; - } + //int tmask = 1; + + bool hb = hbank != 0xff; + bool lb = lbank != 0xff; for (ciPatchGroup i = pg.begin(); i != pg.end(); ++i) { const PatchList& pl = (*i)->patches; for (ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl) { const Patch* mp = *ipl; - if ((mp->typ & tmask) - && (pr == mp->prog) - && ((drum && mode != MT_GM) || - (mp->drum == drumchan)) + if (//(mp->typ & tmask) && + (pr == mp->prog) + && (mp->drum == drum) && (hbank == mp->hbank || !hb || mp->hbank == -1) && (lbank == mp->lbank || !lb || mp->lbank == -1)) @@ -1132,14 +1121,9 @@ QString MidiInstrument::getPatchName(int channel, int prog, MType mode, bool dru return "<unknown>"; } - - - - - -unsigned MidiInstrument::getNextPatch(int channel, unsigned patch, MType songType, bool drum) +unsigned MidiInstrument::getNextPatch(int channel, unsigned patch, bool drum) { - QList<dumb_patchlist_entry_t> haystack=getPatches(channel,songType,drum); + QList<dumb_patchlist_entry_t> haystack=getPatches(channel,drum); if (haystack.empty()) return MusECore::CTRL_VAL_UNKNOWN; int prog=patch&0xFF; @@ -1168,9 +1152,9 @@ unsigned MidiInstrument::getNextPatch(int channel, unsigned patch, MType songTyp ((((it->hbank==-1)?0xFF:it->hbank)<<16)&0xFF0000); } -unsigned MidiInstrument::getPrevPatch(int channel, unsigned patch, MType songType, bool drum) +unsigned MidiInstrument::getPrevPatch(int channel, unsigned patch, bool drum) { - QList<dumb_patchlist_entry_t> haystack=getPatches(channel,songType,drum); + QList<dumb_patchlist_entry_t> haystack=getPatches(channel,drum); if (haystack.empty()) return MusECore::CTRL_VAL_UNKNOWN; int prog=patch&0xFF; @@ -1197,51 +1181,21 @@ unsigned MidiInstrument::getPrevPatch(int channel, unsigned patch, MType songTyp ((((it->hbank==-1)?0xFF:it->hbank)<<16)&0xFF0000); } -QList<dumb_patchlist_entry_t> MidiInstrument::getPatches(int channel, MType mode, bool drum) +QList<dumb_patchlist_entry_t> MidiInstrument::getPatches(int /*channel*/, bool drum) { - int tmask = 1; - bool drumchan = channel == 9; - bool hb = false; - bool lb = false; - switch (mode) { - case MT_GS: - tmask = 2; - hb = true; - break; - case MT_XG: - hb = true; - lb = true; - tmask = 4; - break; - case MT_GM: - if(drumchan) - { - QList<dumb_patchlist_entry_t> tmp; - tmp.push_back(dumb_patchlist_entry_t(0,-1,-1)); - } - else - tmask = 1; - break; - default: - hb = true; // MSB bank matters - lb = true; // LSB bank matters - break; - } - - + //int tmask = 1; QList<dumb_patchlist_entry_t> tmp; for (ciPatchGroup i = pg.begin(); i != pg.end(); ++i) { const PatchList& pl = (*i)->patches; for (ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl) { const Patch* mp = *ipl; - if ((mp->typ & tmask) && - ((drum && mode != MT_GM) || - (mp->drum == drumchan)) ) + if (//(mp->typ & tmask) && + (mp->drum == drum)) { int prog = mp->prog; - int lbank = (mp->lbank==-1 || !lb) ? -1 : mp->lbank; - int hbank = (mp->hbank==-1 || !hb) ? -1 : mp->hbank; + int lbank = mp->lbank; + int hbank = mp->hbank; tmp.push_back(dumb_patchlist_entry_t(prog,lbank,hbank)); } } diff --git a/muse2/muse/instruments/minstrument.h b/muse2/muse/instruments/minstrument.h index 6b534672..7ff6f7d8 100644 --- a/muse2/muse/instruments/minstrument.h +++ b/muse2/muse/instruments/minstrument.h @@ -47,7 +47,8 @@ class DrumMap; //--------------------------------------------------------- struct Patch { - signed char typ; // 1 - GM 2 - GS 4 - XG + // REMOVE Tim. OBSOLETE. + //signed char typ; // 1 - GM 2 - GS 4 - XG signed char hbank, lbank, prog; QString name; bool drum; @@ -200,6 +201,7 @@ class MidiInstrument { MidiInstrument(const QString& txt); const QString& iname() const { return _name; } void setIName(const QString& txt) { _name = txt; } + MType midiType() const; //MidiInstrument& uniqueCopy(const MidiInstrument&); // Assign will 'delete' all existing patches and groups from the instrument. @@ -214,9 +216,9 @@ class MidiInstrument { void addSysex(SysEx* sysex) { _sysex.append(sysex); } const DrumMap* drummap_for_patch(int patch) const; - QList<dumb_patchlist_entry_t> getPatches(int channel, MType songType, bool drum); - unsigned getNextPatch(int channel, unsigned patch, MType songType, bool drum); - unsigned getPrevPatch(int channel, unsigned patch, MType songType, bool drum); + QList<dumb_patchlist_entry_t> getPatches(int channel, bool drum); + unsigned getNextPatch(int channel, unsigned patch, bool drum); + unsigned getPrevPatch(int channel, unsigned patch, bool drum); EventList* midiInit() const { return _midiInit; } EventList* midiReset() const { return _midiReset; } @@ -235,9 +237,9 @@ class MidiInstrument { virtual bool hasNativeGui() const { return false; } virtual void writeToGui(const MidiPlayEvent&) {} - virtual void reset(int, MType); - virtual QString getPatchName(int,int,MType,bool); - virtual void populatePatchPopup(MusEGui::PopupMenu*, int, MType, bool); + virtual void reset(int); + virtual QString getPatchName(int,int,bool); + virtual void populatePatchPopup(MusEGui::PopupMenu*, int, bool); void read(Xml&); void write(int level, Xml&); |