summaryrefslogtreecommitdiff
path: root/muse2/muse/instruments/minstrument.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'muse2/muse/instruments/minstrument.cpp')
-rw-r--r--muse2/muse/instruments/minstrument.cpp201
1 files changed, 74 insertions, 127 deletions
diff --git a/muse2/muse/instruments/minstrument.cpp b/muse2/muse/instruments/minstrument.cpp
index bbb2a076..5d578803 100644
--- a/muse2/muse/instruments/minstrument.cpp
+++ b/muse2/muse/instruments/minstrument.cpp
@@ -26,14 +26,13 @@
#include <QAction>
#include <QDir>
#include <QFileInfo>
-//#include <QMenu>
#include <QMessageBox>
#include "minstrument.h"
#include "midiport.h"
-#include "mididev.h" // p4.0.15
-#include "audio.h" // p4.0.15
-#include "midi.h" // p4.0.15
+#include "mididev.h"
+#include "audio.h"
+#include "midi.h"
#include "globals.h"
#include "xml.h"
#include "event.h"
@@ -153,7 +152,7 @@ static void readEventList(Xml& xml, EventList* el, const char* name)
static void loadIDF(QFileInfo* fi)
{
-/*
+/* DELETETHIS
QFile qf(fi->filePath());
if (!qf.open(IO_ReadOnly)) {
printf("cannot open file %s\n", fi->fileName().toLatin1());
@@ -282,7 +281,7 @@ void initMidiInstruments()
++it;
}
}
- //else
+ //else DELETETHIS
//{
// if(usrInstrumentsDir.mkdir(MusEGlobal::museUserInstruments))
// printf("Created user instrument directory: %s\n", MusEGlobal::museUserInstruments.toLatin1());
@@ -416,8 +415,7 @@ MidiInstrument::~MidiInstrument()
}
-
-/*
+/* DELETETHIS
//---------------------------------------------------------
// uniqueCopy
//---------------------------------------------------------
@@ -465,7 +463,6 @@ MidiInstrument& MidiInstrument::assign(const MidiInstrument& ins)
_nullvalue = ins._nullvalue;
// Assignment
- // *_controller = *(ins._controller);
for(ciMidiController i = ins._controller->begin(); i != ins._controller->end(); ++i)
{
MidiController* mc = i->second;
@@ -473,7 +470,7 @@ MidiInstrument& MidiInstrument::assign(const MidiInstrument& ins)
}
// pg.clear();
-// for(iPatchGroup ipg = pg.begin(); ipg != pg.end(); ++ipg)
+// for(iPatchGroup ipg = pg.begin(); ipg != pg.end(); ++ipg) DELETETHIS
// {
//ipg->patches.clear();
@@ -498,7 +495,6 @@ MidiInstrument& MidiInstrument::assign(const MidiInstrument& ins)
pg.clear();
// Assignment
-// pg = ins.pg;
for(ciPatchGroup g = ins.pg.begin(); g != ins.pg.end(); ++g)
{
PatchGroup* pgp = *g;
@@ -527,7 +523,7 @@ MidiInstrument& MidiInstrument::assign(const MidiInstrument& ins)
- // Hmm, dirty, yes? But init sets it to false...
+ // Hmm, dirty, yes? But init sets it to false... DELETETHIS
//_dirty = ins._dirty;
//_dirty = false;
//_dirty = true;
@@ -543,18 +539,13 @@ MidiInstrument& MidiInstrument::assign(const MidiInstrument& ins)
void MidiInstrument::reset(int portNo, MType)
{
MusECore::MidiPort* port = &MusEGlobal::midiPorts[portNo];
- //if (port == 0)
- // return;
if(port->device() == 0) // p4.0.15
- {
- //printf("MidiInstrument::reset port device is 0\n");
return;
- }
+
MusECore::MidiPlayEvent ev;
ev.setType(0x90);
ev.setPort(portNo);
ev.setTime(0); // p4.0.15
- //ev.setTime(audio->getFrameOffset() + audio->pos().frame());
for (int chan = 0; chan < MIDI_CHANNELS; ++chan)
{
@@ -563,15 +554,8 @@ void MidiInstrument::reset(int portNo, MType)
{
ev.setA(pitch);
ev.setB(0);
- //printf("MidiInstrument::reset adding event channel:%d pitch:%d\n", chan, pitch);
- //ev.dump();
port->sendEvent(ev);
- // Changed to use play events list instead of putEvent FIFO.
- // These loops send 2048 events, which is more than our FIFO (or Jack buffer) can handle! p4.0.15 Tim.
- // Nope, instead, increased FIFO sizes to accommodate.
- //port->device()->playEvents()->add(ev);
- //port->device()->addScheduledEvent(ev);
}
}
}
@@ -661,13 +645,6 @@ void Patch::read(Xml& xml)
void Patch::write(int level, Xml& xml)
{
- //if (drumMap == 0)
- //{
- //QString s = QString("Patch name=\"%1\"").arg(Xml::xmlString(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);
xml.nput(level, "<Patch name=\"%s\"", Xml::xmlString(name).toLatin1().constData());
if(typ != -1)
xml.nput(" mode=\"%d\"", typ);
@@ -680,24 +657,9 @@ void Patch::write(int level, Xml& xml)
xml.nput(" prog=\"%d\"", prog);
- //xml.nput(level, " hbank=\"%d\" lbank=\"%d\" prog=\"%d\"", hbank, lbank, prog);
if(drum)
- //xml.nput(level, " drum=\"%d\"", int(drum));
xml.nput(" drum=\"%d\"", int(drum));
- //xml.put(level, " />");
xml.put(" />");
-
- //return;
- //}
-
- //QString s = QString("drummap name=\"%1\"").arg(Xml::xmlString(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");
}
//---------------------------------------------------------
@@ -706,8 +668,6 @@ void Patch::write(int level, Xml& xml)
void MidiInstrument::readMidiState(Xml& xml)
{
- ///_midiState->read(xml, "midistate", true);
-
// p4.0.27 A kludge to support old midistates by wrapping them in the proper header.
_tmpMidiStateVersion = 1; // Assume old (unmarked) first version 1.
for (;;)
@@ -997,11 +957,8 @@ void MidiInstrument::read(Xml& xml)
void MidiInstrument::write(int level, Xml& xml)
{
xml.header();
- //xml.stag("muse version=\"2.1\"");
xml.tag(level, "muse version=\"1.0\"");
- //xml.stag(QString("MidiInstrument name=\"%1\"").arg(Xml::xmlString(iname())));
level++;
- //xml.tag(level, "MidiInstrument name=\"%s\"", Xml::xmlString(iname()).toLatin1().constData());
xml.nput(level, "<MidiInstrument name=\"%s\"", Xml::xmlString(iname()).toLatin1().constData());
if(_nullvalue != -1)
@@ -1016,10 +973,7 @@ void MidiInstrument::write(int level, Xml& xml)
// TODO: What about Init, Reset, State, and InitScript ?
// -------------
- //std::vector<PatchGroup>* pg = groups();
- //for (std::vector<PatchGroup>::iterator g = pg->begin(); g != pg->end(); ++g) {
level++;
- //for (std::vector<PatchGroup>::iterator g = pg.begin(); g != pg.end(); ++g) {
for (ciPatchGroup g = pg.begin(); g != pg.end(); ++g) {
PatchGroup* pgp = *g;
const PatchList& pl = pgp->patches;
@@ -1029,27 +983,86 @@ void MidiInstrument::write(int level, Xml& xml)
level++;
//for (iPatch p = g->patches.begin(); p != g->patches.end(); ++p)
for (ciPatch p = pl.begin(); p != pl.end(); ++p)
- //(*p)->write(xml);
- //p->write(level, xml);
(*p)->write(level, xml);
level--;
- //xml.etag("PatchGroup");
xml.etag(level, "PatchGroup");
}
for (iMidiController ic = _controller->begin(); ic != _controller->end(); ++ic)
- //(*ic)->write(xml);
ic->second->write(level, xml);
- //xml.etag("MidiInstrument");
writeDrummaps(level, xml);
level--;
xml.etag(level, "MidiInstrument");
- //xml.etag("muse");
level--;
xml.etag(level, "muse");
}
+
+//---------------------------------------------------------
+// populatePatchPopup
+//---------------------------------------------------------
+
+void MidiInstrument::populatePatchPopup(MusEGui::PopupMenu* menu, int chan, MType songType, 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;
+ }
+ 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]);
+ 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)) )
+ {
+ int id = ((mp->hbank & 0xff) << 16)
+ + ((mp->lbank & 0xff) << 8) + (mp->prog & 0xff);
+ QAction* act = pm->addAction(mp->name);
+ act->setData(id);
+ }
+
+ }
+ }
+ }
+ else if (pg.size() == 1 ){
+ // no groups
+ const PatchList& pl = pg.front()->patches;
+ for (ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl) {
+ const Patch* mp = *ipl;
+ 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);
+ }
+ }
+ }
+
+ }
+
+
+
//---------------------------------------------------------
// getPatchName
//---------------------------------------------------------
@@ -1222,72 +1235,6 @@ QList<dumb_patchlist_entry_t> MidiInstrument::getPatches(int channel, MType mode
}
-//---------------------------------------------------------
-// populatePatchPopup
-//---------------------------------------------------------
-
-void MidiInstrument::populatePatchPopup(MusEGui::PopupMenu* menu, int chan, MType songType, 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->setCheckable(true);
- act->setData(id);
- return;
- }
- mask = 1;
- break;
- case MT_UNKNOWN: mask = 7; break;
- }
- if (pg.size() > 1) {
- for (ciPatchGroup i = pg.begin(); i != pg.end(); ++i) {
- PatchGroup* pgp = *i;
- //QMenu* pm = menu->addMenu(pgp->name);
- 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]);
- 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)) )
- {
- int id = ((mp->hbank & 0xff) << 16)
- + ((mp->lbank & 0xff) << 8) + (mp->prog & 0xff);
- QAction* act = pm->addAction(mp->name);
- //act->setCheckable(true);
- act->setData(id);
- }
-
- }
- }
- }
- else if (pg.size() == 1 ){
- // no groups
- const PatchList& pl = pg.front()->patches;
- for (ciPatch ipl = pl.begin(); ipl != pl.end(); ++ipl) {
- const Patch* mp = *ipl;
- if (mp->typ & mask) {
- int id = ((mp->hbank & 0xff) << 16)
- + ((mp->lbank & 0xff) << 8) + (mp->prog & 0xff);
- QAction* act = menu->addAction(mp->name);
- //act->setCheckable(true);
- act->setData(id);
- }
- }
- }
-
- }
-
const DrumMap* MidiInstrument::drummap_for_patch(int patch) const
{
using std::list;