summaryrefslogtreecommitdiff
path: root/muse2/muse/instruments/minstrument.cpp
diff options
context:
space:
mode:
authorFlorian Jung <flo@windfisch.org>2012-02-29 15:25:27 +0000
committerFlorian Jung <flo@windfisch.org>2012-02-29 15:25:27 +0000
commita5ced1d15d584b2c4f7489f181224582c38da0f4 (patch)
tree98a7e3b8b664cf579a834bf2b2e2e1f25fc2cf90 /muse2/muse/instruments/minstrument.cpp
parent3a26b16556a49196800298ed4219decc134c7061 (diff)
changed custom column for "program" to display and edit real patches
instead of the raw values
Diffstat (limited to 'muse2/muse/instruments/minstrument.cpp')
-rw-r--r--muse2/muse/instruments/minstrument.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/muse2/muse/instruments/minstrument.cpp b/muse2/muse/instruments/minstrument.cpp
index 1349c9c9..bbb2a076 100644
--- a/muse2/muse/instruments/minstrument.cpp
+++ b/muse2/muse/instruments/minstrument.cpp
@@ -1103,6 +1103,125 @@ QString MidiInstrument::getPatchName(int channel, int prog, MType mode, bool dru
return "<unknown>";
}
+
+
+
+
+
+unsigned MidiInstrument::getNextPatch(int channel, unsigned patch, MType songType, bool drum)
+{
+ QList<dumb_patchlist_entry_t> haystack=getPatches(channel,songType,drum);
+ if (haystack.empty()) return MusECore::CTRL_VAL_UNKNOWN;
+
+ int prog=patch&0xFF;
+ int lbank=(patch>>8)&0xFF;
+ int hbank=(patch>>16)&0xFF;
+
+ dumb_patchlist_entry_t needle=dumb_patchlist_entry_t(prog, (lbank!=0xFF)?lbank:-1, (hbank!=0xFF)?hbank:-1);
+
+ QList<dumb_patchlist_entry_t>::iterator it;
+ for (it=haystack.begin(); it!=haystack.end(); it++)
+ if ((*it) == needle)
+ break;
+
+ if (it==haystack.end()) //not found? use first entry
+ it=haystack.begin();
+ else
+ {
+ for (;it!=haystack.end(); it++)
+ if ((*it)!=needle)
+ break;
+ if (it==haystack.end()) it=haystack.begin(); //wrap-over
+ }
+
+ return (it->prog&0xFF) |
+ ((((it->lbank==-1)?0xFF:it->lbank)<<8)&0xFF00) |
+ ((((it->hbank==-1)?0xFF:it->hbank)<<16)&0xFF0000);
+}
+
+unsigned MidiInstrument::getPrevPatch(int channel, unsigned patch, MType songType, bool drum)
+{
+ QList<dumb_patchlist_entry_t> haystack=getPatches(channel,songType,drum);
+ if (haystack.empty()) return MusECore::CTRL_VAL_UNKNOWN;
+
+ int prog=patch&0xFF;
+ int lbank=(patch>>8)&0xFF;
+ int hbank=(patch>>16)&0xFF;
+
+ dumb_patchlist_entry_t needle=dumb_patchlist_entry_t(prog, (lbank!=0xFF)?lbank:-1, (hbank!=0xFF)?hbank:-1);
+
+ QList<dumb_patchlist_entry_t>::iterator it;
+ for (it=haystack.begin(); it!=haystack.end(); it++)
+ if ((*it) == needle)
+ break;
+
+ if (it==haystack.end()) //not found? use first entry
+ it=haystack.begin();
+ else
+ {
+ if (it==haystack.begin()) it=haystack.end(); //wrap-over
+ it--;
+ }
+
+ return (it->prog&0xFF) |
+ ((((it->lbank==-1)?0xFF:it->lbank)<<8)&0xFF00) |
+ ((((it->hbank==-1)?0xFF:it->hbank)<<16)&0xFF0000);
+}
+
+QList<dumb_patchlist_entry_t> MidiInstrument::getPatches(int channel, MType mode, 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;
+ }
+
+
+ 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)) )
+ {
+ int prog = mp->prog;
+ int lbank = (mp->lbank==-1 || !lb) ? -1 : mp->lbank;
+ int hbank = (mp->hbank==-1 || !hb) ? -1 : mp->hbank;
+ tmp.push_back(dumb_patchlist_entry_t(prog,lbank,hbank));
+ }
+ }
+ }
+
+ return tmp;
+ }
+
+
//---------------------------------------------------------
// populatePatchPopup
//---------------------------------------------------------