From: werner s. <wsc...@us...> - 2005-05-12 06:56:32
|
Update of /cvsroot/lmuse/muse/muse In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14284/muse Added Files: midiplugin.cpp midiplugin.h Log Message: added missing files --- NEW FILE: midiplugin.h --- //========================================================= // MusE // Linux Music Editor // $Id: midiplugin.h,v 1.1 2005/05/12 06:56:22 wschweer Exp $ // // (C) Copyright 2000-2004 Werner Schweer (ws...@se...) //========================================================= #ifndef __MIDIPLUGIN_H__ #define __MIDIPLUGIN_H__ #include "globals.h" #include "midiplugins/libmidiplugin/mempi.h" namespace AL { class Xml; }; using AL::Xml; class MidiPluginIF; class MidiPluginGui; class MidiPluginI; class MidiTrackBase; class Ctrl; class MPEventList; class MidiTrackBase; typedef const MEMPI* (*MEMPI_Function)(); //--------------------------------------------------------- // MidiPlugin //--------------------------------------------------------- class MidiPlugin { MEMPI_Function mempi; const MEMPI* plugin; protected: int _instances; QFileInfo fi; public: MidiPlugin(const QFileInfo* f, const MEMPI_Function, const MEMPI* d); virtual ~MidiPlugin() {} int instances() const { return _instances; } virtual void incInstances(int val) { _instances += val; } QString lib() const { return fi.baseName(); } QString path() const { return fi.dirPath(); } QString name() const { return QString(plugin->name); } QString description() const { return QString(plugin->description); } QString version() const { return QString(plugin->version); } MidiPluginI* instantiate(MidiTrackBase*); }; //--------------------------------------------------------- // MidiPluginList //--------------------------------------------------------- typedef std::list<MidiPlugin*>::iterator iMidiPlugin; class MidiPluginList : public std::list<MidiPlugin*> { public: MidiPlugin* find(const QString&, const QString&); MidiPluginList() {} }; //--------------------------------------------------------- // MidiPluginI // plugin instance //--------------------------------------------------------- class MidiPluginI { MidiPlugin* _plugin; Mempi* mempi; MidiTrackBase* _track; bool _on; public: MidiPluginI(MidiPlugin*, MidiTrackBase*, Mempi*); ~MidiPluginI(); MidiPlugin* plugin() const { return _plugin; } bool on() const { return _on; } void setOn(bool val) { _on = val; } void apply(MPEventList*, MPEventList*); void activate(); void deactivate(); QString name() const { return QString(mempi->name()); } QString lib() const { return _plugin->lib(); } MidiTrackBase* track() const { return _track; } void writeConfiguration(Xml& xml); bool readConfiguration(QDomNode); void showGui(); void showGui(bool); bool guiVisible() const; }; //--------------------------------------------------------- // Pipeline // chain of connected efx inserts //--------------------------------------------------------- const int MidiPipelineDepth = 4; class MidiPipeline : public std::vector<MidiPluginI*> { public: MidiPipeline(); void insert(MidiPluginI* p, int index); bool isOn(int idx) const; void setOn(int, bool); QString name(int idx) const; void showGui(int, bool); bool guiVisible(int); void apply(MPEventList*, MPEventList*); void move(int idx, bool up); bool empty(int idx) const; MidiPluginI* plugin(int idx) { return (*this)[idx]; } }; typedef MidiPipeline::iterator iMidiPluginI; typedef MidiPipeline::const_iterator ciMidiPluginI; //--------------------------------------------------------- // MidiPluginDialog //--------------------------------------------------------- class MidiPluginDialog : public QDialog { QListView* pList; Q_OBJECT public: MidiPluginDialog(QWidget* parent=0, const char* name=0, bool modal=true); static MidiPlugin* getPlugin(QWidget* parent); MidiPlugin* value(); public slots: void fillPlugs(); }; extern void initMidiPlugins(); extern MidiPluginList midiPlugins; #endif --- NEW FILE: midiplugin.cpp --- //========================================================= // MusE // Linux Music Editor // $Id: midiplugin.cpp,v 1.1 2005/05/12 06:56:22 wschweer Exp $ // // (C) Copyright 2005 Werner Schweer (ws...@se...) //========================================================= #include <dlfcn.h> #include "al/al.h" #include "midiplugin.h" #include "al/xml.h" #include "ctrl.h" #include "midiplugins/libmidiplugin/mempi.h" MidiPluginList midiPlugins; //--------------------------------------------------------- // MidiPlugin //--------------------------------------------------------- MidiPlugin::MidiPlugin(const QFileInfo* f, const MEMPI_Function mf, const MEMPI* d) : fi(*f) { mempi = mf; plugin = d; _instances = 0; } //--------------------------------------------------------- // instantiate //--------------------------------------------------------- MidiPluginI* MidiPlugin::instantiate(MidiTrackBase* t) { if (plugin == 0) { printf("initMidiPluginInstance: zero plugin\n"); return 0; } ++_instances; QString inst("-" + QString::number(_instances)); QString s = name() + inst; Mempi* m = plugin->instantiate(s.latin1()); if (m->init()) { delete m; return 0; } MidiPluginI* mp = new MidiPluginI(this,t, m); return mp; } //--------------------------------------------------------- // MidiPluginI //--------------------------------------------------------- MidiPluginI::MidiPluginI(MidiPlugin* p, MidiTrackBase* t, Mempi* m) { _track = t; _plugin = p; mempi = m; _on = true; } //--------------------------------------------------------- // MidiPluginI //--------------------------------------------------------- MidiPluginI::~MidiPluginI() { if (_plugin) deactivate(); } //--------------------------------------------------------- // loadMidiPlugin //--------------------------------------------------------- static void loadMidiPlugin(QFileInfo* fi) { void* handle = dlopen(fi->filePath().ascii(), RTLD_NOW); if (handle == 0) { fprintf(stderr, "loadMidiPlugin::dlopen(%s) failed: %s\n", fi->filePath().ascii(), dlerror()); return; } MEMPI_Function mempi = (MEMPI_Function)dlsym(handle, "mempi_descriptor"); if (!mempi) { const char *txt = dlerror(); if (txt) { fprintf(stderr, "Unable to find mempi_descriptor() function in plugin " "library file \"%s\": %s.\n" "Are you sure this is a MEMPI plugin file?\n", fi->filePath().ascii(), txt); exit(1); } } const MEMPI* descr = mempi(); if (descr == 0) { fprintf(stderr, "Mempi::instantiate: no MEMPI descr found\n"); undoSetuid(); return; } printf("add midi plugin %s\n", fi->filePath().ascii()); midiPlugins.push_back(new MidiPlugin(fi, mempi, descr)); } //--------------------------------------------------------- // loadMidiPluginDir //--------------------------------------------------------- static void loadMidiPluginDir(const QString& s) { if (debugMsg) printf("scan midi plugin dir <%s>\n", s.latin1()); QDir pluginDir(s, QString("*.so"), QDir::Files); if (pluginDir.exists()) { const QFileInfoList* list = pluginDir.entryInfoList(); QFileInfoListIterator it(*list); QFileInfo* fi; while((fi = it.current())) { loadMidiPlugin(fi); ++it; } } } //--------------------------------------------------------- // initMidiPlugins // search for midi MEPI plugins //--------------------------------------------------------- void initMidiPlugins() { loadMidiPluginDir(museGlobalLib + QString("/midiplugins")); } //--------------------------------------------------------- // find //--------------------------------------------------------- MidiPlugin* MidiPluginList::find(const QString& /*file*/, const QString& name) { for (iMidiPlugin i = begin(); i != end(); ++i) { if (name == (*i)->name()) return *i; } printf("MidiPlugin <%s> not found\n", name.latin1()); return 0; } //--------------------------------------------------------- // Pipeline //--------------------------------------------------------- MidiPipeline::MidiPipeline() : std::vector<MidiPluginI*>() { for (int i = 0; i < MidiPipelineDepth; ++i) push_back(0); } //--------------------------------------------------------- // insert // give ownership of object plugin to Pipeline //--------------------------------------------------------- void MidiPipeline::insert(MidiPluginI* plugin, int index) { (*this)[index] = plugin; } //--------------------------------------------------------- // isOn //--------------------------------------------------------- bool MidiPipeline::isOn(int idx) const { MidiPluginI* p = (*this)[idx]; if (p) return p->on(); return false; } //--------------------------------------------------------- // setOn //--------------------------------------------------------- void MidiPipeline::setOn(int idx, bool flag) { MidiPluginI* p = (*this)[idx]; if (p) { p->setOn(flag); // if (p->gui()) // p->gui()->setOn(flag); } } //--------------------------------------------------------- // name //--------------------------------------------------------- QString MidiPipeline::name(int idx) const { MidiPluginI* p = (*this)[idx]; if (p) return p->name(); return QString("empty"); } //--------------------------------------------------------- // empty //--------------------------------------------------------- bool MidiPipeline::empty(int idx) const { MidiPluginI* p = (*this)[idx]; return p == 0; } //--------------------------------------------------------- // move //--------------------------------------------------------- void MidiPipeline::move(int idx, bool up) { MidiPluginI* p1 = (*this)[idx]; if (up) { (*this)[idx] = (*this)[idx-1]; (*this)[idx-1] = p1; } else { (*this)[idx] = (*this)[idx+1]; (*this)[idx+1] = p1; } } //--------------------------------------------------------- // showGui //--------------------------------------------------------- void MidiPipeline::showGui(int idx, bool flag) { MidiPluginI* p = (*this)[idx]; if (p) p->showGui(flag); } //--------------------------------------------------------- // guiVisible //--------------------------------------------------------- bool MidiPipeline::guiVisible(int idx) { MidiPluginI* p = (*this)[idx]; if (p) return p->guiVisible(); return false; } //--------------------------------------------------------- // apply //--------------------------------------------------------- void MidiPipeline::apply(MPEventList* il, MPEventList* ol) { bool swap = true; for (iMidiPluginI i = begin(); i != end(); ++i) { MidiPluginI* p = *i; if (p == 0 || !p->on()) continue; if (swap) { ol->clear(); p->apply(il, ol); } else { il->clear(); p->apply(ol, il); } swap = !swap; } if (swap) { ol->clear(); *ol = *il; } } //--------------------------------------------------------- // apply //--------------------------------------------------------- void MidiPluginI::apply(MPEventList* il, MPEventList* ol) { mempi->process(il, ol); } //--------------------------------------------------------- // saveConfiguration //--------------------------------------------------------- void MidiPluginI::writeConfiguration(Xml& xml) { xml.tag("midiPlugin file=\"%s\" name=\"%s\"", _plugin->lib().latin1(), _plugin->name().latin1()); if (_on == false) xml.intTag("on", _on); if (guiVisible()) { xml.intTag("gui", 1); // TODO xml.geometryTag("geometry", _gui); } xml.etag("midiPlugin"); } //--------------------------------------------------------- // readConfiguration // return true on error //--------------------------------------------------------- bool MidiPluginI::readConfiguration(QDomNode node) { #if 0 QDomElement e = node.toElement(); QString file = e.attribute("file"); QString label = e.attribute("name"); if (_plugin == 0) { _plugin = midiPlugins.find(file, label); if (_plugin == 0) return true; if (initPluginInstance(_plugin)) return true; } node = node.firstChild(); while (!node.isNull()) { e = node.toElement(); int i = e.text().toInt(); QString tag(e.tagName()); if (tag == "on") { bool flag = i; _on = flag; } else if (tag == "gui") { bool flag = i; showGui(flag); } else if (tag == "geometry") { QRect r(AL::readGeometry(node)); if (_gui) { _gui->resize(r.size()); _gui->move(r.topLeft()); } } else printf("MusE:PluginI: unknown tag %s\n", e.tagName().latin1()); node = node.nextSibling(); } if (_gui) _gui->updateValues(); #endif return false; } //--------------------------------------------------------- // showGui //--------------------------------------------------------- void MidiPluginI::showGui() { mempi->showGui(!mempi->guiVisible()); } void MidiPluginI::showGui(bool flag) { mempi->showGui(flag); } //--------------------------------------------------------- // guiVisible //--------------------------------------------------------- bool MidiPluginI::guiVisible() const { return mempi->guiVisible(); } //--------------------------------------------------------- // deactivate //--------------------------------------------------------- void MidiPluginI::deactivate() { } //--------------------------------------------------------- // activate //--------------------------------------------------------- void MidiPluginI::activate() { // pif->activate(); } //--------------------------------------------------------- // MidiPluginDialog //--------------------------------------------------------- MidiPluginDialog::MidiPluginDialog(QWidget* parent, const char* name, bool modal) : QDialog(parent, name, modal) { setCaption(tr("MusE: select plugin")); QVBoxLayout* layout = new QVBoxLayout(this); pList = new QListView(this); pList->setAllColumnsShowFocus(true); pList->addColumn(tr("File"), 110); pList->addColumn(tr("Name"), 110); pList->addColumn(tr("Version"), 100); pList->addColumn(tr("Description"), 300); pList->setColumnWidthMode(0, QListView::Maximum); fillPlugs(); layout->addWidget(pList); //--------------------------------------------------- // Ok/Cancel Buttons //--------------------------------------------------- QBoxLayout* w5 = new QHBoxLayout; layout->addLayout(w5); QPushButton* okB = new QPushButton(tr("Ok"), this); okB->setDefault(true); QPushButton* cancelB = new QPushButton(tr("Cancel"), this); okB->setFixedWidth(80); cancelB->setFixedWidth(80); w5->addWidget(okB); w5->addSpacing(12); w5->addWidget(cancelB); connect(pList, SIGNAL(doubleClicked(QListViewItem*)), SLOT(accept())); connect(cancelB, SIGNAL(clicked()), SLOT(reject())); connect(okB, SIGNAL(clicked()), SLOT(accept())); } MidiPlugin* MidiPluginDialog::getPlugin(QWidget* parent) { MidiPluginDialog* dialog = new MidiPluginDialog(parent); if (dialog->exec()) return dialog->value(); return 0; } MidiPlugin* MidiPluginDialog::value() { QListViewItem* item = pList->selectedItem(); if (item) return midiPlugins.find(item->text(0), item->text(1)); return 0; } void MidiPluginDialog::fillPlugs() { pList->clear(); for (iMidiPlugin i = midiPlugins.begin(); i != midiPlugins.end(); ++i) { QListViewItem* item = new QListViewItem(pList, (*i)->lib(), (*i)->name(), (*i)->version(), (*i)->description() ); } } |