annotate plugin/RealTimePluginInstance.h @ 51:c2913298cf94

* Make RealTimePluginInstances also provide the PluginInstance interface
author Chris Cannam
date Mon, 20 Mar 2006 13:48:58 +0000
parents 39ae3dee27b9
children d397ea0a79f5
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 A waveform viewer and audio annotation editor.
Chris@2 5 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@0 6
Chris@0 7 This is experimental software. Not for distribution.
Chris@0 8 */
Chris@0 9
Chris@0 10 /*
Chris@0 11 This is a modified version of a source file from the
Chris@0 12 Rosegarden MIDI and audio sequencer and notation editor.
Chris@17 13 This file copyright 2000-2006 Chris Cannam.
Chris@0 14 */
Chris@0 15
Chris@0 16 #ifndef _REALTIME_PLUGIN_INSTANCE_H_
Chris@0 17 #define _REALTIME_PLUGIN_INSTANCE_H_
Chris@0 18
Chris@51 19 #include "PluginInstance.h"
Chris@51 20
Chris@0 21 #include <QString>
Chris@0 22 #include <QStringList>
Chris@0 23 #include <vector>
Chris@51 24 #include <string>
Chris@0 25
Chris@0 26 #include "base/RealTime.h"
Chris@0 27
Chris@0 28 class RealTimePluginFactory;
Chris@0 29
Chris@0 30 /**
Chris@0 31 * RealTimePluginInstance is a very trivial interface that an audio
Chris@0 32 * process can use to refer to an instance of a plugin without needing
Chris@0 33 * to know what type of plugin it is.
Chris@0 34 *
Chris@0 35 * The audio code calls run() on an instance that has been passed to
Chris@0 36 * it, and assumes that the passing code has already initialised the
Chris@0 37 * plugin, connected its inputs and outputs and so on, and that there
Chris@0 38 * is an understanding in place about the sizes of the buffers in use
Chris@0 39 * by the plugin. All of this depends on the subclass implementation.
Chris@51 40 *
Chris@51 41 * The PluginInstance base class includes additional abstract methods
Chris@51 42 * which the subclass of RealTimePluginInstance must implement.
Chris@0 43 */
Chris@0 44
Chris@0 45 // These names are taken from LADSPA, but the values are not
Chris@0 46 // guaranteed to match
Chris@0 47
Chris@0 48 namespace PortType { // ORable
Chris@0 49 static const int Input = 1;
Chris@0 50 static const int Output = 2;
Chris@0 51 static const int Control = 4;
Chris@0 52 static const int Audio = 8;
Chris@0 53 }
Chris@0 54
Chris@0 55 namespace PortHint { // ORable
Chris@0 56 static const int NoHint = 0;
Chris@0 57 static const int Toggled = 1;
Chris@0 58 static const int Integer = 2;
Chris@0 59 static const int Logarithmic = 4;
Chris@0 60 static const int SampleRate = 8;
Chris@0 61 }
Chris@0 62
Chris@51 63 class RealTimePluginInstance : public PluginInstance
Chris@0 64 {
Chris@0 65 public:
Chris@0 66 typedef float sample_t;
Chris@0 67
Chris@0 68 virtual ~RealTimePluginInstance();
Chris@0 69
Chris@0 70 virtual bool isOK() const = 0;
Chris@0 71
Chris@0 72 virtual QString getIdentifier() const = 0;
Chris@0 73
Chris@0 74 /**
Chris@0 75 * Run for one block, starting at the given time. The start time
Chris@0 76 * may be of interest to synths etc that may have queued events
Chris@0 77 * waiting. Other plugins can ignore it.
Chris@0 78 */
Chris@0 79 virtual void run(const RealTime &blockStartTime) = 0;
Chris@0 80
Chris@0 81 virtual size_t getBufferSize() const = 0;
Chris@0 82
Chris@0 83 virtual size_t getAudioInputCount() const = 0;
Chris@0 84 virtual size_t getAudioOutputCount() const = 0;
Chris@0 85
Chris@0 86 virtual sample_t **getAudioInputBuffers() = 0;
Chris@0 87 virtual sample_t **getAudioOutputBuffers() = 0;
Chris@0 88
Chris@51 89 // virtual QStringList getPrograms() const { return QStringList(); }
Chris@51 90 // virtual QString getCurrentProgram() const { return QString(); }
Chris@51 91 virtual std::string getProgram(int /* bank */, int /* program */) const { return std::string(); }
Chris@51 92 // virtual unsigned long getProgram(QString /* name */) const { return 0; } // bank << 16 + program
Chris@51 93 // virtual void selectProgram(QString) { }
Chris@0 94
Chris@0 95 virtual unsigned int getParameterCount() const = 0;
Chris@0 96 virtual void setParameterValue(unsigned int parameter, float value) = 0;
Chris@0 97 virtual float getParameterValue(unsigned int parameter) const = 0;
Chris@0 98 virtual float getParameterDefault(unsigned int parameter) const = 0;
Chris@0 99
Chris@51 100 virtual std::string configure(std::string /* key */, std::string /* value */) { return std::string(); }
Chris@0 101
Chris@0 102 virtual void sendEvent(const RealTime & /* eventTime */,
Chris@0 103 const void * /* event */) { }
Chris@10 104 virtual void clearEvents() { }
Chris@0 105
Chris@0 106 virtual bool isBypassed() const = 0;
Chris@0 107 virtual void setBypassed(bool value) = 0;
Chris@0 108
Chris@0 109 // This should be called after setup, but while not actually playing.
Chris@0 110 virtual size_t getLatency() = 0;
Chris@0 111
Chris@0 112 virtual void silence() = 0;
Chris@0 113 virtual void discardEvents() { }
Chris@0 114 virtual void setIdealChannelCount(size_t channels) = 0; // must also silence(); may also re-instantiate
Chris@0 115
Chris@0 116 void setFactory(RealTimePluginFactory *f) { m_factory = f; } // ew
Chris@0 117
Chris@0 118 protected:
Chris@0 119 RealTimePluginInstance(RealTimePluginFactory *factory, QString identifier) :
Chris@0 120 m_factory(factory), m_identifier(identifier) { }
Chris@0 121
Chris@0 122 RealTimePluginFactory *m_factory;
Chris@0 123 QString m_identifier;
Chris@0 124
Chris@0 125 friend class PluginFactory;
Chris@0 126 };
Chris@0 127
Chris@0 128
Chris@0 129 #endif