# HG changeset patch # User Chris Cannam # Date 1142862538 0 # Node ID c2913298cf947cf01472575a966e2e44fabf8bcc # Parent 080ad875395a8467424db457184353db65da5333 * Make RealTimePluginInstances also provide the PluginInstance interface diff -r 080ad875395a -r c2913298cf94 plugin/DSSIPluginInstance.cpp --- a/plugin/DSSIPluginInstance.cpp Mon Mar 20 12:04:06 2006 +0000 +++ b/plugin/DSSIPluginInstance.cpp Mon Mar 20 13:48:58 2006 +0000 @@ -92,51 +92,82 @@ } } -DSSIPluginInstance::DSSIPluginInstance(RealTimePluginFactory *factory, - int clientId, - QString identifier, - int position, - unsigned long sampleRate, - size_t blockSize, - sample_t **inputBuffers, - sample_t **outputBuffers, - const DSSI_Descriptor* descriptor) : - RealTimePluginInstance(factory, identifier), - m_client(clientId), - m_position(position), - m_descriptor(descriptor), - m_eventBuffer(EVENT_BUFFER_SIZE), - m_blockSize(blockSize), - m_inputBuffers(inputBuffers), - m_outputBuffers(outputBuffers), - m_ownBuffers(false), - m_idealChannelCount(0), - m_sampleRate(sampleRate), - m_latencyPort(0), - m_run(false), - m_bypassed(false), - m_grouped(false) +std::string +DSSIPluginInstance::getName() const { -#ifdef DEBUG_DSSI - std::cerr << "DSSIPluginInstance::DSSIPluginInstance[buffers supplied](" << identifier << ")" - << std::endl; -#endif - - init(); - - m_pending.lsb = m_pending.msb = m_pending.program = -1; - - instantiate(sampleRate); - if (isOK()) { - connectPorts(); - activate(); - if (m_descriptor->run_multiple_synths) { - m_grouped = true; - initialiseGroupMembership(); - } - } + return m_descriptor->LADSPA_Plugin->Label; } +std::string +DSSIPluginInstance::getDescription() const +{ + return m_descriptor->LADSPA_Plugin->Name; +} + +std::string +DSSIPluginInstance::getMaker() const +{ + return m_descriptor->LADSPA_Plugin->Maker; +} + +int +DSSIPluginInstance::getPluginVersion() const +{ + return 1; +} + +std::string +DSSIPluginInstance::getCopyright() const +{ + return m_descriptor->LADSPA_Plugin->Copyright; +} + +DSSIPluginInstance::ParameterList +DSSIPluginInstance::getParameterDescriptors() const +{ + ParameterList list; + LADSPAPluginFactory *f = dynamic_cast(m_factory); + + for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { + + ParameterDescriptor pd; + unsigned int pn = m_controlPortsIn[i].first; + + pd.name = m_descriptor->LADSPA_Plugin->PortNames[pn]; + pd.description = pd.name; + pd.minValue = f->getPortMinimum(m_descriptor->LADSPA_Plugin, pn); + pd.maxValue = f->getPortMaximum(m_descriptor->LADSPA_Plugin, pn); + pd.defaultValue = f->getPortDefault(m_descriptor->LADSPA_Plugin, pn); + pd.isQuantized = false; + + list.push_back(pd); + } + + return list; +} + +float +DSSIPluginInstance::getParameter(std::string name) const +{ + for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { + if (name == m_descriptor->LADSPA_Plugin->PortNames[m_controlPortsIn[i].first]) { + return getParameterValue(i); + } + } + + return 0.0; +} + +void +DSSIPluginInstance::setParameter(std::string name, float value) +{ + for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { + if (name == m_descriptor->LADSPA_Plugin->PortNames[m_controlPortsIn[i].first]) { + setParameterValue(i, value); + break; + } + } +} void DSSIPluginInstance::init() @@ -436,7 +467,6 @@ ProgramDescriptor d; d.bank = programDescriptor->Bank; d.program = programDescriptor->Program; -//!!! d.name = QString("%1. %2").arg(index).arg(programDescriptor->Name); d.name = programDescriptor->Name; m_cachedPrograms.push_back(d); } @@ -448,18 +478,18 @@ m_programCacheValid = true; } -QStringList +DSSIPluginInstance::ProgramList DSSIPluginInstance::getPrograms() const { #ifdef DEBUG_DSSI std::cerr << "DSSIPluginInstance::getPrograms" << std::endl; #endif - if (!m_descriptor) return QStringList(); + if (!m_descriptor) return ProgramList(); checkProgramCache(); - QStringList programs; + ProgramList programs; for (std::vector::iterator i = m_cachedPrograms.begin(); i != m_cachedPrograms.end(); ++i) { @@ -469,14 +499,14 @@ return programs; } -QString +std::string DSSIPluginInstance::getProgram(int bank, int program) const { #ifdef DEBUG_DSSI std::cerr << "DSSIPluginInstance::getProgram(" << bank << "," << program << ")" << std::endl; #endif - if (!m_descriptor) return QString(); + if (!m_descriptor) return std::string(); checkProgramCache(); @@ -485,11 +515,11 @@ if (i->bank == bank && i->program == program) return i->name; } - return QString(); + return std::string(); } unsigned long -DSSIPluginInstance::getProgram(QString name) const +DSSIPluginInstance::getProgram(std::string name) const { #ifdef DEBUG_DSSI std::cerr << "DSSIPluginInstance::getProgram(" << name << ")" << std::endl; @@ -513,20 +543,20 @@ return 0; } -QString +std::string DSSIPluginInstance::getCurrentProgram() const { return m_program; } void -DSSIPluginInstance::selectProgram(QString program) +DSSIPluginInstance::selectProgram(std::string program) { selectProgramAux(program, true); } void -DSSIPluginInstance::selectProgramAux(QString program, bool backupPortValues) +DSSIPluginInstance::selectProgramAux(std::string program, bool backupPortValues) { #ifdef DEBUG_DSSI std::cerr << "DSSIPluginInstance::selectProgram(" << program << ")" << std::endl; @@ -587,7 +617,7 @@ if (!m_descriptor || !m_descriptor->LADSPA_Plugin->activate) return; m_descriptor->LADSPA_Plugin->activate(m_instanceHandle); - if (!m_program.isEmpty()) { + if (m_program != "") { #ifdef DEBUG_DSSI std::cerr << "DSSIPluginInstance::activate: restoring program " << m_program << std::endl; #endif @@ -739,17 +769,17 @@ } } -QString -DSSIPluginInstance::configure(QString key, - QString value) +std::string +DSSIPluginInstance::configure(std::string key, + std::string value) { - if (!m_descriptor || !m_descriptor->configure) return QString(); + if (!m_descriptor || !m_descriptor->configure) return std::string(); - if (key == PluginIdentifier::RESERVED_PROJECT_DIRECTORY_KEY) { + if (key == PluginIdentifier::RESERVED_PROJECT_DIRECTORY_KEY.toStdString()) { #ifdef DSSI_PROJECT_DIRECTORY_KEY key = DSSI_PROJECT_DIRECTORY_KEY; #else - return QString(); + return std::string(); #endif } @@ -759,24 +789,24 @@ #endif char *message = m_descriptor->configure(m_instanceHandle, - key.toStdString().c_str(), - value.toStdString().c_str()); + key.c_str(), + value.c_str()); m_programCacheValid = false; - QString qm; + std::string qm; // Ignore return values from reserved key configuration calls such // as project directory #ifdef DSSI_RESERVED_CONFIGURE_PREFIX - if (key.startsWith(DSSI_RESERVED_CONFIGURE_PREFIX)) { + if (QString(key.c_str()).startsWith(DSSI_RESERVED_CONFIGURE_PREFIX)) { return qm; } #endif if (message) { if (m_descriptor->LADSPA_Plugin && m_descriptor->LADSPA_Plugin->Label) { - qm = QString(m_descriptor->LADSPA_Plugin->Label) + ": "; + qm = std::string(m_descriptor->LADSPA_Plugin->Label) + ": "; } qm = qm + message; free(message); diff -r 080ad875395a -r c2913298cf94 plugin/DSSIPluginInstance.h --- a/plugin/DSSIPluginInstance.h Mon Mar 20 12:04:06 2006 +0000 +++ b/plugin/DSSIPluginInstance.h Mon Mar 20 13:48:58 2006 +0000 @@ -42,13 +42,24 @@ virtual QString getIdentifier() const { return m_identifier; } int getPosition() const { return m_position; } + virtual std::string getName() const; + virtual std::string getDescription() const; + virtual std::string getMaker() const; + virtual int getPluginVersion() const; + virtual std::string getCopyright() const; + virtual void run(const RealTime &); virtual unsigned int getParameterCount() const; virtual void setParameterValue(unsigned int parameter, float value); virtual float getParameterValue(unsigned int parameter) const; virtual float getParameterDefault(unsigned int parameter) const; - virtual QString configure(QString key, QString value); + + virtual ParameterList getParameterDescriptors() const; + virtual float getParameter(std::string) const; + virtual void setParameter(std::string, float); + + virtual std::string configure(std::string key, std::string value); virtual void sendEvent(const RealTime &eventTime, const void *event); virtual void clearEvents(); @@ -59,11 +70,11 @@ virtual sample_t **getAudioInputBuffers() { return m_inputBuffers; } virtual sample_t **getAudioOutputBuffers() { return m_outputBuffers; } - virtual QStringList getPrograms() const; - virtual QString getCurrentProgram() const; - virtual QString getProgram(int bank, int program) const; - virtual unsigned long getProgram(QString name) const; - virtual void selectProgram(QString program); + virtual ProgramList getPrograms() const; + virtual std::string getCurrentProgram() const; + virtual std::string getProgram(int bank, int program) const; + virtual unsigned long getProgram(std::string name) const; + virtual void selectProgram(std::string program); virtual bool isBypassed() const { return m_bypassed; } virtual void setBypassed(bool bypassed) { m_bypassed = bypassed; } @@ -92,18 +103,6 @@ int idealChannelCount, const DSSI_Descriptor* descriptor); - // Constructor that uses shared buffers - // - DSSIPluginInstance(RealTimePluginFactory *factory, - int client, - QString identifier, - int position, - unsigned long sampleRate, - size_t blockSize, - sample_t **inputBuffers, - sample_t **outputBuffers, - const DSSI_Descriptor* descriptor); - void init(); void instantiate(unsigned long sampleRate); void cleanup(); @@ -113,7 +112,7 @@ bool handleController(snd_seq_event_t *ev); void setPortValueFromController(unsigned int portNumber, int controlValue); - void selectProgramAux(QString program, bool backupPortValues); + void selectProgramAux(std::string program, bool backupPortValues); void checkProgramCache() const; void initialiseGroupMembership(); @@ -154,7 +153,7 @@ struct ProgramDescriptor { int bank; int program; - QString name; + std::string name; }; mutable std::vector m_cachedPrograms; mutable bool m_programCacheValid; @@ -172,7 +171,7 @@ bool m_run; bool m_bypassed; - QString m_program; + std::string m_program; bool m_grouped; RealTime m_lastRunTime; diff -r 080ad875395a -r c2913298cf94 plugin/LADSPAPluginInstance.cpp --- a/plugin/LADSPAPluginInstance.cpp Mon Mar 20 12:04:06 2006 +0000 +++ b/plugin/LADSPAPluginInstance.cpp Mon Mar 20 13:48:58 2006 +0000 @@ -62,38 +62,82 @@ } } -LADSPAPluginInstance::LADSPAPluginInstance(RealTimePluginFactory *factory, - int clientId, - QString identifier, - int position, - unsigned long sampleRate, - size_t blockSize, - sample_t **inputBuffers, - sample_t **outputBuffers, - const LADSPA_Descriptor* descriptor) : - RealTimePluginInstance(factory, identifier), - m_client(clientId), - m_position(position), - m_instanceCount(0), - m_descriptor(descriptor), - m_blockSize(blockSize), - m_inputBuffers(inputBuffers), - m_outputBuffers(outputBuffers), - m_ownBuffers(false), - m_sampleRate(sampleRate), - m_latencyPort(0), - m_run(false), - m_bypassed(false) +std::string +LADSPAPluginInstance::getName() const { - init(); - - instantiate(sampleRate); - if (isOK()) { - connectPorts(); - activate(); - } + return m_descriptor->Label; } +std::string +LADSPAPluginInstance::getDescription() const +{ + return m_descriptor->Name; +} + +std::string +LADSPAPluginInstance::getMaker() const +{ + return m_descriptor->Maker; +} + +int +LADSPAPluginInstance::getPluginVersion() const +{ + return 1; +} + +std::string +LADSPAPluginInstance::getCopyright() const +{ + return m_descriptor->Copyright; +} + +LADSPAPluginInstance::ParameterList +LADSPAPluginInstance::getParameterDescriptors() const +{ + ParameterList list; + LADSPAPluginFactory *f = dynamic_cast(m_factory); + + for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { + + ParameterDescriptor pd; + unsigned int pn = m_controlPortsIn[i].first; + + pd.name = m_descriptor->PortNames[pn]; + pd.description = pd.name; + pd.minValue = f->getPortMinimum(m_descriptor, pn); + pd.maxValue = f->getPortMaximum(m_descriptor, pn); + pd.defaultValue = f->getPortDefault(m_descriptor, pn); + pd.isQuantized = false; + + list.push_back(pd); + } + + return list; +} + +float +LADSPAPluginInstance::getParameter(std::string name) const +{ + for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { + if (name == m_descriptor->PortNames[m_controlPortsIn[i].first]) { + return getParameterValue(i); + } + } + + return 0.0; +} + +void +LADSPAPluginInstance::setParameter(std::string name, float value) +{ + for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) { + if (name == m_descriptor->PortNames[m_controlPortsIn[i].first]) { + setParameterValue(i, value); + break; + } + } +} void LADSPAPluginInstance::init(int idealChannelCount) diff -r 080ad875395a -r c2913298cf94 plugin/LADSPAPluginInstance.h --- a/plugin/LADSPAPluginInstance.h Mon Mar 20 12:04:06 2006 +0000 +++ b/plugin/LADSPAPluginInstance.h Mon Mar 20 13:48:58 2006 +0000 @@ -38,12 +38,22 @@ virtual QString getIdentifier() const { return m_identifier; } int getPosition() const { return m_position; } + virtual std::string getName() const; + virtual std::string getDescription() const; + virtual std::string getMaker() const; + virtual int getPluginVersion() const; + virtual std::string getCopyright() const; + virtual void run(const RealTime &rt); virtual unsigned int getParameterCount() const; virtual void setParameterValue(unsigned int parameter, float value); virtual float getParameterValue(unsigned int parameter) const; virtual float getParameterDefault(unsigned int parameter) const; + + virtual ParameterList getParameterDescriptors() const; + virtual float getParameter(std::string) const; + virtual void setParameter(std::string, float); virtual size_t getBufferSize() const { return m_blockSize; } virtual size_t getAudioInputCount() const { return m_instanceCount * m_audioPortsIn.size(); } @@ -74,18 +84,6 @@ int idealChannelCount, const LADSPA_Descriptor* descriptor); - // Constructor that uses shared buffers - // - LADSPAPluginInstance(RealTimePluginFactory *factory, - int client, - QString identifier, - int position, - unsigned long sampleRate, - size_t blockSize, - sample_t **inputBuffers, - sample_t **outputBuffers, - const LADSPA_Descriptor* descriptor); - void init(int idealChannelCount = 0); void instantiate(unsigned long sampleRate); void cleanup(); diff -r 080ad875395a -r c2913298cf94 plugin/RealTimePluginInstance.cpp --- a/plugin/RealTimePluginInstance.cpp Mon Mar 20 12:04:06 2006 +0000 +++ b/plugin/RealTimePluginInstance.cpp Mon Mar 20 13:48:58 2006 +0000 @@ -30,4 +30,3 @@ } } - diff -r 080ad875395a -r c2913298cf94 plugin/RealTimePluginInstance.h --- a/plugin/RealTimePluginInstance.h Mon Mar 20 12:04:06 2006 +0000 +++ b/plugin/RealTimePluginInstance.h Mon Mar 20 13:48:58 2006 +0000 @@ -16,9 +16,12 @@ #ifndef _REALTIME_PLUGIN_INSTANCE_H_ #define _REALTIME_PLUGIN_INSTANCE_H_ +#include "PluginInstance.h" + #include #include #include +#include #include "base/RealTime.h" @@ -34,6 +37,9 @@ * plugin, connected its inputs and outputs and so on, and that there * is an understanding in place about the sizes of the buffers in use * by the plugin. All of this depends on the subclass implementation. + * + * The PluginInstance base class includes additional abstract methods + * which the subclass of RealTimePluginInstance must implement. */ // These names are taken from LADSPA, but the values are not @@ -54,7 +60,7 @@ static const int SampleRate = 8; } -class RealTimePluginInstance +class RealTimePluginInstance : public PluginInstance { public: typedef float sample_t; @@ -80,18 +86,18 @@ virtual sample_t **getAudioInputBuffers() = 0; virtual sample_t **getAudioOutputBuffers() = 0; - virtual QStringList getPrograms() const { return QStringList(); } - virtual QString getCurrentProgram() const { return QString(); } - virtual QString getProgram(int /* bank */, int /* program */) const { return QString(); } - virtual unsigned long getProgram(QString /* name */) const { return 0; } // bank << 16 + program - virtual void selectProgram(QString) { } +// virtual QStringList getPrograms() const { return QStringList(); } +// virtual QString getCurrentProgram() const { return QString(); } + virtual std::string getProgram(int /* bank */, int /* program */) const { return std::string(); } +// virtual unsigned long getProgram(QString /* name */) const { return 0; } // bank << 16 + program +// virtual void selectProgram(QString) { } virtual unsigned int getParameterCount() const = 0; virtual void setParameterValue(unsigned int parameter, float value) = 0; virtual float getParameterValue(unsigned int parameter) const = 0; virtual float getParameterDefault(unsigned int parameter) const = 0; - virtual QString configure(QString /* key */, QString /* value */) { return QString(); } + virtual std::string configure(std::string /* key */, std::string /* value */) { return std::string(); } virtual void sendEvent(const RealTime & /* eventTime */, const void * /* event */) { }