annotate plugin/RealTimePluginInstance.h @ 385:9b35a1731c3d

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