1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 3 /* 4 Sonic Visualiser 5 An audio file viewer and annotation editor. 6 Centre for Digital Music, Queen Mary, University of London. 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License as 10 published by the Free Software Foundation; either version 2 of the 11 License, or (at your option) any later version. See the file 12 COPYING included with this distribution for more information. 13 */ 14 15 /* 16 This is a modified version of a source file from the 17 Rosegarden MIDI and audio sequencer and notation editor. 18 This file copyright 2000-2006 Chris Cannam. 19 */ 20 21 #ifndef SV_REALTIME_PLUGIN_INSTANCE_H 22 #define SV_REALTIME_PLUGIN_INSTANCE_H 23 24 #include <vamp-hostsdk/PluginBase.h> 25 26 #include "base/RealTime.h" 27 #include "base/AudioPlaySource.h" 28 29 #include <QString> 30 #include <QStringList> 31 #include <vector> 32 #include <string> 33 #include <map> 34 35 class RealTimePluginFactory; 36 37 /** 38 * RealTimePluginInstance is an interface that an audio process can 39 * use to refer to an instance of a plugin without needing to know 40 * what type of plugin it is. 41 * 42 * The audio code calls run() on an instance that has been passed to 43 * it, and assumes that the passing code has already initialised the 44 * plugin, connected its inputs and outputs and so on, and that there 45 * is an understanding in place about the sizes of the buffers in use 46 * by the plugin. All of this depends on the subclass implementation. 47 * 48 * The PluginInstance base class includes additional abstract methods 49 * which the subclass of RealTimePluginInstance must implement. 50 */ 51 52 /* 53 * N.B. RealTimePluginInstance, RealTimePluginFactory and their 54 * subclasses are terrible code. They've been reused, cut and pasted 55 * and mangled too many times to fit too many different uses, and 56 * could do with a good tidy. 57 */ 58 59 // These names are taken from LADSPA, but the values are not 60 // guaranteed to match 61 62 namespace PortType { // ORable 63 static const int Input = 1; 64 static const int Output = 2; 65 static const int Control = 4; 66 static const int Audio = 8; 67 } 68 69 namespace PortHint { // ORable 70 static const int NoHint = 0; 71 static const int Toggled = 1; 72 static const int Integer = 2; 73 static const int Logarithmic = 4; 74 static const int SampleRate = 8; 75 } 76 77 class RealTimePluginInstance : public Vamp::PluginBase, public Auditionable 78 { 79 public: 80 typedef float sample_t; 81 82 virtual ~RealTimePluginInstance(); 83 84 virtual bool isOK() const = 0; 85 86 virtual QString getPluginIdentifier() const = 0; 87 88 /** 89 * Run for one block, starting at the given time. The start time 90 * may be of interest to synths etc that may have queued events 91 * waiting. Other plugins can ignore it. The count, if zero, 92 * defaults to our fixed buffer size. 93 */ 94 virtual void run(const RealTime &blockStartTime, 95 int count = 0) = 0; 96 97 virtual int getBufferSize() const = 0; 98 99 virtual int getAudioInputCount() const = 0; 100 virtual int getAudioOutputCount() const = 0; 101 102 virtual sample_t **getAudioInputBuffers() = 0; 103 virtual sample_t **getAudioOutputBuffers() = 0; 104 105 // Control inputs are known as parameters here 106 virtual int getControlOutputCount() const = 0; 107 virtual float getControlOutputValue(int n) const = 0; 108 109 // virtual QStringList getPrograms() const { return QStringList(); } 110 // virtual QString getCurrentProgram() const { return QString(); } getProgram(int,int)111 virtual std::string getProgram(int /* bank */, int /* program */) const { return std::string(); } 112 // virtual int getProgram(QString /* name */) const { return 0; } // bank << 16 + program 113 // virtual void selectProgram(QString) { } 114 115 virtual int getParameterCount() const = 0; 116 virtual void setParameterValue(int parameter, float value) = 0; 117 virtual float getParameterValue(int parameter) const = 0; 118 virtual float getParameterDefault(int parameter) const = 0; 119 virtual int getParameterDisplayHint(int parameter) const = 0; 120 configure(std::string,std::string)121 virtual std::string configure(std::string /* key */, std::string /* value */) { return std::string(); } 122 sendEvent(const RealTime &,const void *)123 virtual void sendEvent(const RealTime & /* eventTime */, 124 const void * /* event */) { } clearEvents()125 virtual void clearEvents() { } 126 127 virtual bool isBypassed() const = 0; 128 virtual void setBypassed(bool value) = 0; 129 130 // This should be called after setup, but while not actually playing. 131 virtual sv_frame_t getLatency() = 0; 132 133 virtual void silence() = 0; discardEvents()134 virtual void discardEvents() { } 135 virtual void setIdealChannelCount(int channels) = 0; // must also silence(); may also re-instantiate 136 setFactory(RealTimePluginFactory * f)137 void setFactory(RealTimePluginFactory *f) { m_factory = f; } // ew 138 getType()139 std::string getType() const override { return "Real-Time Plugin"; } 140 141 typedef std::map<std::string, std::string> ConfigurationPairMap; getConfigurePairs()142 virtual ConfigurationPairMap getConfigurePairs() { 143 return m_configurationData; 144 } 145 146 protected: RealTimePluginInstance(RealTimePluginFactory * factory,QString identifier)147 RealTimePluginInstance(RealTimePluginFactory *factory, QString identifier) : 148 m_factory(factory), m_identifier(identifier) { } 149 150 RealTimePluginFactory *m_factory; 151 QString m_identifier; 152 153 ConfigurationPairMap m_configurationData; 154 155 friend class PluginFactory; 156 }; 157 158 159 #endif 160