Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@52: Sonic Visualiser Chris@52: An audio file viewer and annotation editor. Chris@52: Centre for Digital Music, Queen Mary, University of London. Chris@0: Chris@52: This program is free software; you can redistribute it and/or Chris@52: modify it under the terms of the GNU General Public License as Chris@52: published by the Free Software Foundation; either version 2 of the Chris@52: License, or (at your option) any later version. See the file Chris@52: COPYING included with this distribution for more information. Chris@0: */ Chris@0: Chris@0: /* Chris@0: This is a modified version of a source file from the Chris@0: Rosegarden MIDI and audio sequencer and notation editor. Chris@17: This file copyright 2000-2006 Chris Cannam. Chris@0: */ Chris@0: Chris@0: #ifndef _REALTIME_PLUGIN_INSTANCE_H_ Chris@0: #define _REALTIME_PLUGIN_INSTANCE_H_ Chris@0: Chris@66: #include "vamp-sdk/PluginBase.h" Chris@66: #include "vamp-sdk/RealTime.h" Chris@51: Chris@0: #include Chris@0: #include Chris@0: #include Chris@51: #include Chris@75: #include Chris@0: Chris@0: class RealTimePluginFactory; Chris@0: Chris@0: /** Chris@60: * RealTimePluginInstance is an interface that an audio process can Chris@60: * use to refer to an instance of a plugin without needing to know Chris@60: * what type of plugin it is. Chris@0: * Chris@0: * The audio code calls run() on an instance that has been passed to Chris@0: * it, and assumes that the passing code has already initialised the Chris@0: * plugin, connected its inputs and outputs and so on, and that there Chris@0: * is an understanding in place about the sizes of the buffers in use Chris@0: * by the plugin. All of this depends on the subclass implementation. Chris@51: * Chris@51: * The PluginInstance base class includes additional abstract methods Chris@51: * which the subclass of RealTimePluginInstance must implement. Chris@0: */ Chris@0: Chris@60: /* Chris@60: * N.B. RealTimePluginInstance, RealTimePluginFactory and their Chris@60: * subclasses are terrible code. They've been reused, cut and pasted Chris@60: * and mangled too many times to fit too many different uses, and Chris@60: * could do with a good tidy. Chris@60: */ Chris@60: Chris@0: // These names are taken from LADSPA, but the values are not Chris@0: // guaranteed to match Chris@0: Chris@0: namespace PortType { // ORable Chris@0: static const int Input = 1; Chris@0: static const int Output = 2; Chris@0: static const int Control = 4; Chris@0: static const int Audio = 8; Chris@0: } Chris@0: Chris@0: namespace PortHint { // ORable Chris@0: static const int NoHint = 0; Chris@0: static const int Toggled = 1; Chris@0: static const int Integer = 2; Chris@0: static const int Logarithmic = 4; Chris@0: static const int SampleRate = 8; Chris@0: } Chris@0: Chris@66: class RealTimePluginInstance : public Vamp::PluginBase Chris@0: { Chris@0: public: Chris@0: typedef float sample_t; Chris@0: Chris@0: virtual ~RealTimePluginInstance(); Chris@0: Chris@0: virtual bool isOK() const = 0; Chris@0: Chris@237: virtual QString getPluginIdentifier() const = 0; Chris@0: Chris@0: /** Chris@0: * Run for one block, starting at the given time. The start time Chris@0: * may be of interest to synths etc that may have queued events Chris@385: * waiting. Other plugins can ignore it. The count, if zero, Chris@385: * defaults to our fixed buffer size. Chris@0: */ Chris@385: virtual void run(const Vamp::RealTime &blockStartTime, Chris@385: size_t count = 0) = 0; Chris@0: Chris@0: virtual size_t getBufferSize() const = 0; Chris@0: Chris@0: virtual size_t getAudioInputCount() const = 0; Chris@0: virtual size_t getAudioOutputCount() const = 0; Chris@0: Chris@0: virtual sample_t **getAudioInputBuffers() = 0; Chris@0: virtual sample_t **getAudioOutputBuffers() = 0; Chris@0: Chris@60: // Control inputs are known as parameters here Chris@60: virtual size_t getControlOutputCount() const = 0; Chris@60: virtual float getControlOutputValue(size_t n) const = 0; Chris@60: Chris@51: // virtual QStringList getPrograms() const { return QStringList(); } Chris@51: // virtual QString getCurrentProgram() const { return QString(); } Chris@51: virtual std::string getProgram(int /* bank */, int /* program */) const { return std::string(); } Chris@51: // virtual unsigned long getProgram(QString /* name */) const { return 0; } // bank << 16 + program Chris@51: // virtual void selectProgram(QString) { } Chris@0: Chris@0: virtual unsigned int getParameterCount() const = 0; Chris@0: virtual void setParameterValue(unsigned int parameter, float value) = 0; Chris@0: virtual float getParameterValue(unsigned int parameter) const = 0; Chris@0: virtual float getParameterDefault(unsigned int parameter) const = 0; Chris@356: virtual int getParameterDisplayHint(unsigned int parameter) const = 0; Chris@0: Chris@51: virtual std::string configure(std::string /* key */, std::string /* value */) { return std::string(); } Chris@0: Chris@66: virtual void sendEvent(const Vamp::RealTime & /* eventTime */, Chris@0: const void * /* event */) { } Chris@10: virtual void clearEvents() { } Chris@0: Chris@0: virtual bool isBypassed() const = 0; Chris@0: virtual void setBypassed(bool value) = 0; Chris@0: Chris@0: // This should be called after setup, but while not actually playing. Chris@0: virtual size_t getLatency() = 0; Chris@0: Chris@0: virtual void silence() = 0; Chris@0: virtual void discardEvents() { } Chris@0: virtual void setIdealChannelCount(size_t channels) = 0; // must also silence(); may also re-instantiate Chris@0: Chris@0: void setFactory(RealTimePluginFactory *f) { m_factory = f; } // ew Chris@0: Chris@57: virtual std::string getType() const { return "Real-Time Plugin"; } Chris@57: Chris@332: typedef std::map ConfigurationPairMap; Chris@332: virtual ConfigurationPairMap getConfigurePairs() { Chris@75: return m_configurationData; Chris@75: } Chris@75: Chris@0: protected: Chris@0: RealTimePluginInstance(RealTimePluginFactory *factory, QString identifier) : Chris@0: m_factory(factory), m_identifier(identifier) { } Chris@0: Chris@0: RealTimePluginFactory *m_factory; Chris@0: QString m_identifier; Chris@0: Chris@332: ConfigurationPairMap m_configurationData; Chris@75: Chris@0: friend class PluginFactory; Chris@0: }; Chris@0: Chris@0: Chris@0: #endif