annotate plugin/RealTimePluginInstance.h @ 661:a4faa1840384

* If a FileSource URL won't convert at all in strict mode, try again in tolerant mode (necessary for e.g. filenames with square brackets in them)
author Chris Cannam
date Tue, 19 Oct 2010 21:47:55 +0100
parents a70dcfed59c1
children cc27f35aa75c
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@475 24 #include <vamp-hostsdk/PluginBase.h>
Chris@475 25 #include <vamp-hostsdk/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@389 33 #include "base/AudioPlaySource.h"
Chris@389 34
Chris@0 35 class RealTimePluginFactory;
Chris@0 36
Chris@0 37 /**
Chris@60 38 * RealTimePluginInstance is an interface that an audio process can
Chris@60 39 * use to refer to an instance of a plugin without needing to know
Chris@60 40 * what type of plugin it is.
Chris@0 41 *
Chris@0 42 * The audio code calls run() on an instance that has been passed to
Chris@0 43 * it, and assumes that the passing code has already initialised the
Chris@0 44 * plugin, connected its inputs and outputs and so on, and that there
Chris@0 45 * is an understanding in place about the sizes of the buffers in use
Chris@0 46 * by the plugin. All of this depends on the subclass implementation.
Chris@51 47 *
Chris@51 48 * The PluginInstance base class includes additional abstract methods
Chris@51 49 * which the subclass of RealTimePluginInstance must implement.
Chris@0 50 */
Chris@0 51
Chris@60 52 /*
Chris@60 53 * N.B. RealTimePluginInstance, RealTimePluginFactory and their
Chris@60 54 * subclasses are terrible code. They've been reused, cut and pasted
Chris@60 55 * and mangled too many times to fit too many different uses, and
Chris@60 56 * could do with a good tidy.
Chris@60 57 */
Chris@60 58
Chris@0 59 // These names are taken from LADSPA, but the values are not
Chris@0 60 // guaranteed to match
Chris@0 61
Chris@0 62 namespace PortType { // ORable
Chris@0 63 static const int Input = 1;
Chris@0 64 static const int Output = 2;
Chris@0 65 static const int Control = 4;
Chris@0 66 static const int Audio = 8;
Chris@0 67 }
Chris@0 68
Chris@0 69 namespace PortHint { // ORable
Chris@0 70 static const int NoHint = 0;
Chris@0 71 static const int Toggled = 1;
Chris@0 72 static const int Integer = 2;
Chris@0 73 static const int Logarithmic = 4;
Chris@0 74 static const int SampleRate = 8;
Chris@0 75 }
Chris@0 76
Chris@389 77 class RealTimePluginInstance : public Vamp::PluginBase, public Auditionable
Chris@0 78 {
Chris@0 79 public:
Chris@0 80 typedef float sample_t;
Chris@0 81
Chris@0 82 virtual ~RealTimePluginInstance();
Chris@0 83
Chris@0 84 virtual bool isOK() const = 0;
Chris@0 85
Chris@237 86 virtual QString getPluginIdentifier() const = 0;
Chris@0 87
Chris@0 88 /**
Chris@0 89 * Run for one block, starting at the given time. The start time
Chris@0 90 * may be of interest to synths etc that may have queued events
Chris@385 91 * waiting. Other plugins can ignore it. The count, if zero,
Chris@385 92 * defaults to our fixed buffer size.
Chris@0 93 */
Chris@385 94 virtual void run(const Vamp::RealTime &blockStartTime,
Chris@385 95 size_t count = 0) = 0;
Chris@0 96
Chris@0 97 virtual size_t getBufferSize() const = 0;
Chris@0 98
Chris@0 99 virtual size_t getAudioInputCount() const = 0;
Chris@0 100 virtual size_t getAudioOutputCount() const = 0;
Chris@0 101
Chris@0 102 virtual sample_t **getAudioInputBuffers() = 0;
Chris@0 103 virtual sample_t **getAudioOutputBuffers() = 0;
Chris@0 104
Chris@60 105 // Control inputs are known as parameters here
Chris@60 106 virtual size_t getControlOutputCount() const = 0;
Chris@60 107 virtual float getControlOutputValue(size_t n) const = 0;
Chris@60 108
Chris@51 109 // virtual QStringList getPrograms() const { return QStringList(); }
Chris@51 110 // virtual QString getCurrentProgram() const { return QString(); }
Chris@51 111 virtual std::string getProgram(int /* bank */, int /* program */) const { return std::string(); }
Chris@51 112 // virtual unsigned long getProgram(QString /* name */) const { return 0; } // bank << 16 + program
Chris@51 113 // virtual void selectProgram(QString) { }
Chris@0 114
Chris@0 115 virtual unsigned int getParameterCount() const = 0;
Chris@0 116 virtual void setParameterValue(unsigned int parameter, float value) = 0;
Chris@0 117 virtual float getParameterValue(unsigned int parameter) const = 0;
Chris@0 118 virtual float getParameterDefault(unsigned int parameter) const = 0;
Chris@356 119 virtual int getParameterDisplayHint(unsigned int parameter) const = 0;
Chris@0 120
Chris@51 121 virtual std::string configure(std::string /* key */, std::string /* value */) { return std::string(); }
Chris@0 122
Chris@66 123 virtual void sendEvent(const Vamp::RealTime & /* eventTime */,
Chris@0 124 const void * /* event */) { }
Chris@10 125 virtual void clearEvents() { }
Chris@0 126
Chris@0 127 virtual bool isBypassed() const = 0;
Chris@0 128 virtual void setBypassed(bool value) = 0;
Chris@0 129
Chris@0 130 // This should be called after setup, but while not actually playing.
Chris@0 131 virtual size_t getLatency() = 0;
Chris@0 132
Chris@0 133 virtual void silence() = 0;
Chris@0 134 virtual void discardEvents() { }
Chris@0 135 virtual void setIdealChannelCount(size_t channels) = 0; // must also silence(); may also re-instantiate
Chris@0 136
Chris@0 137 void setFactory(RealTimePluginFactory *f) { m_factory = f; } // ew
Chris@0 138
Chris@57 139 virtual std::string getType() const { return "Real-Time Plugin"; }
Chris@57 140
Chris@332 141 typedef std::map<std::string, std::string> ConfigurationPairMap;
Chris@332 142 virtual ConfigurationPairMap getConfigurePairs() {
Chris@75 143 return m_configurationData;
Chris@75 144 }
Chris@75 145
Chris@0 146 protected:
Chris@0 147 RealTimePluginInstance(RealTimePluginFactory *factory, QString identifier) :
Chris@0 148 m_factory(factory), m_identifier(identifier) { }
Chris@0 149
Chris@0 150 RealTimePluginFactory *m_factory;
Chris@0 151 QString m_identifier;
Chris@0 152
Chris@332 153 ConfigurationPairMap m_configurationData;
Chris@75 154
Chris@0 155 friend class PluginFactory;
Chris@0 156 };
Chris@0 157
Chris@0 158
Chris@0 159 #endif