annotate transform/TransformFactory.h @ 1886:f803d3c33f76 tip

Switch off copious debug in soft synth driving
author Chris Cannam
date Fri, 14 Aug 2020 10:44:44 +0100
parents 7b6e18380e8f
children
rev   line source
Chris@330 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@330 2
Chris@330 3 /*
Chris@330 4 Sonic Visualiser
Chris@330 5 An audio file viewer and annotation editor.
Chris@330 6 Centre for Digital Music, Queen Mary, University of London.
Chris@330 7 This file copyright 2006-2007 Chris Cannam and QMUL.
Chris@330 8
Chris@330 9 This program is free software; you can redistribute it and/or
Chris@330 10 modify it under the terms of the GNU General Public License as
Chris@330 11 published by the Free Software Foundation; either version 2 of the
Chris@330 12 License, or (at your option) any later version. See the file
Chris@330 13 COPYING included with this distribution for more information.
Chris@330 14 */
Chris@330 15
Chris@1546 16 #ifndef SV_TRANSFORM_FACTORY_H
Chris@1546 17 #define SV_TRANSFORM_FACTORY_H
Chris@330 18
Chris@330 19 #include "TransformDescription.h"
Chris@330 20
Chris@457 21 #include "base/TextMatcher.h"
Chris@457 22
Chris@475 23 #include <vamp-hostsdk/Plugin.h>
Chris@350 24
Chris@387 25 #include <QObject>
Chris@443 26 #include <QStringList>
Chris@460 27 #include <QThread>
Chris@460 28 #include <QMutex>
Chris@387 29
Chris@330 30 #include <map>
Chris@330 31 #include <set>
Chris@1841 32 #include <memory>
Chris@330 33
Chris@330 34 class TransformFactory : public QObject
Chris@330 35 {
Chris@330 36 Q_OBJECT
Chris@330 37
Chris@330 38 public:
Chris@457 39 TransformFactory();
Chris@330 40 virtual ~TransformFactory();
Chris@330 41
Chris@330 42 static TransformFactory *getInstance();
Chris@574 43 static void deleteInstance(); // only when exiting
Chris@330 44
Chris@477 45 /**
Chris@477 46 * TransformFactory has a background thread that can populate
Chris@477 47 * uninstalled transforms from network RDF resources. It is not
Chris@477 48 * started by default, but it's a good idea to start it when the
Chris@477 49 * program starts up, if the uninstalled transforms may be of use
Chris@477 50 * later; otherwise there will be a bottleneck the first time
Chris@477 51 * they're requested.
Chris@477 52 *
Chris@477 53 * If this thread is not already running, start it now.
Chris@477 54 */
Chris@477 55 void startPopulationThread();
Chris@477 56
Chris@350 57 TransformList getAllTransformDescriptions();
Chris@350 58 TransformDescription getTransformDescription(TransformId id);
Chris@485 59 bool haveInstalledTransforms();
Chris@330 60
Chris@457 61 TransformList getUninstalledTransformDescriptions();
Chris@457 62 TransformDescription getUninstalledTransformDescription(TransformId id);
Chris@485 63 bool haveUninstalledTransforms(bool waitForCheckToComplete = false);
Chris@457 64
Chris@457 65 typedef enum {
Chris@457 66 TransformUnknown,
Chris@457 67 TransformInstalled,
Chris@457 68 TransformNotInstalled
Chris@457 69 } TransformInstallStatus;
Chris@457 70
Chris@457 71 TransformInstallStatus getTransformInstallStatus(TransformId id);
Chris@457 72
Chris@487 73 std::vector<TransformDescription::Type> getAllTransformTypes();
Chris@487 74 std::vector<QString> getTransformCategories(TransformDescription::Type);
Chris@487 75 std::vector<QString> getTransformMakers(TransformDescription::Type);
Chris@487 76 QString getTransformTypeName(TransformDescription::Type) const;
Chris@330 77
Chris@457 78 typedef std::map<TransformId, TextMatcher::Match> SearchResults;
Chris@443 79 SearchResults search(QString keyword);
Chris@443 80 SearchResults search(QStringList keywords);
Chris@1865 81
Chris@1865 82 /**
Chris@1865 83 * Return true if the transforms have been populated, i.e. a call
Chris@1865 84 * to something like haveTransform() will return without having to
Chris@1865 85 * do the work of scanning plugins
Chris@1865 86 */
Chris@1865 87 bool havePopulated();
Chris@443 88
Chris@330 89 /**
Chris@330 90 * Return true if the given transform is known.
Chris@330 91 */
Chris@330 92 bool haveTransform(TransformId identifier);
Chris@330 93
Chris@330 94 /**
Chris@350 95 * A single transform ID can lead to many possible Transforms,
Chris@350 96 * with different parameters and execution context settings.
Chris@350 97 * Return the default one for the given transform.
Chris@350 98 */
Chris@1830 99 Transform getDefaultTransformFor(TransformId identifier,
Chris@1830 100 sv_samplerate_t rate = 0);
Chris@350 101
Chris@350 102 /**
Chris@330 103 * Full name of a transform, suitable for putting on a menu.
Chris@330 104 */
Chris@330 105 QString getTransformName(TransformId identifier);
Chris@330 106
Chris@330 107 /**
Chris@330 108 * Brief but friendly name of a transform, suitable for use
Chris@330 109 * as the name of the output layer.
Chris@330 110 */
Chris@330 111 QString getTransformFriendlyName(TransformId identifier);
Chris@330 112
Chris@330 113 QString getTransformUnits(TransformId identifier);
Chris@330 114
Chris@1845 115 Provider getTransformProvider(TransformId identifier);
Chris@472 116
Chris@350 117 Vamp::Plugin::InputDomain getTransformInputDomain(TransformId identifier);
Chris@350 118
Chris@330 119 /**
Chris@330 120 * Return true if the transform has any configurable parameters,
Chris@330 121 * i.e. if getConfigurationForTransform can ever return a non-trivial
Chris@330 122 * (not equivalent to empty) configuration string.
Chris@330 123 */
Chris@330 124 bool isTransformConfigurable(TransformId identifier);
Chris@330 125
Chris@330 126 /**
Chris@330 127 * If the transform has a prescribed number or range of channel
Chris@330 128 * inputs, return true and set minChannels and maxChannels to the
Chris@330 129 * minimum and maximum number of channel inputs the transform can
Chris@330 130 * accept. Return false if it doesn't care.
Chris@330 131 */
Chris@330 132 bool getTransformChannelRange(TransformId identifier,
Chris@330 133 int &minChannels, int &maxChannels);
Chris@332 134
Chris@332 135 /**
Chris@351 136 * Load an appropriate plugin for the given transform and set the
Chris@351 137 * parameters, program and configuration strings on that plugin
Chris@351 138 * from the Transform object.
Chris@351 139 *
Chris@351 140 * Note that this requires that the transform has a meaningful
Chris@351 141 * sample rate set, as that is used as the rate for the plugin. A
Chris@351 142 * Transform can legitimately have rate set at zero (= "use the
Chris@351 143 * rate of the input source"), so the caller will need to test for
Chris@351 144 * this case.
Chris@351 145 *
Chris@351 146 * Returns the plugin thus loaded. This will be a
Chris@351 147 * Vamp::PluginBase, but not necessarily a Vamp::Plugin (only if
Chris@351 148 * the transform was a feature-extraction type -- call
Chris@351 149 * downcastVampPlugin if you only want Vamp::Plugins). Returns
Chris@1830 150 * nullptr if no suitable plugin was available.
Chris@351 151 */
Chris@1830 152 std::shared_ptr<Vamp::PluginBase> instantiatePluginFor(const Transform &transform);
Chris@351 153
Chris@351 154 /**
Chris@332 155 * Set the plugin parameters, program and configuration strings on
Chris@332 156 * the given Transform object from the given plugin instance.
Chris@332 157 * Note that no check is made whether the plugin is actually the
Chris@332 158 * "correct" one for the transform.
Chris@332 159 */
Chris@1830 160 void setParametersFromPlugin(Transform &transform, std::shared_ptr<Vamp::PluginBase> plugin);
Chris@332 161
Chris@332 162 /**
Chris@350 163 * Set the parameters, program and configuration strings on the
Chris@350 164 * given plugin from the given Transform object.
Chris@350 165 */
Chris@1830 166 void setPluginParameters(const Transform &transform, std::shared_ptr<Vamp::PluginBase> plugin);
Chris@350 167
Chris@350 168 /**
Chris@332 169 * If the given Transform object has no processing step and block
Chris@332 170 * sizes set, set them to appropriate defaults for the given
Chris@332 171 * plugin.
Chris@332 172 */
Chris@1830 173 void makeContextConsistentWithPlugin(Transform &transform, std::shared_ptr<Vamp::PluginBase> plugin);
Chris@332 174
Chris@332 175 /**
Chris@350 176 * Retrieve a <plugin ... /> XML fragment that describes the
Chris@350 177 * plugin parameters, program and configuration data for the given
Chris@350 178 * transform.
Chris@350 179 *
Chris@350 180 * This function is provided for backward compatibility only. Use
Chris@350 181 * Transform::toXml where compatibility with PluginXml
Chris@350 182 * descriptions of transforms is not required.
Chris@332 183 */
Chris@350 184 QString getPluginConfigurationXml(const Transform &transform);
Chris@350 185
Chris@350 186 /**
Chris@350 187 * Set the plugin parameters, program and configuration strings on
Chris@350 188 * the given Transform object from the given <plugin ... /> XML
Chris@350 189 * fragment.
Chris@350 190 *
Chris@350 191 * This function is provided for backward compatibility only. Use
Chris@350 192 * Transform(QString) where compatibility with PluginXml
Chris@350 193 * descriptions of transforms is not required.
Chris@350 194 */
Chris@350 195 void setParametersFromPluginConfigurationXml(Transform &transform,
Chris@350 196 QString xml);
Chris@1149 197
Chris@1227 198 QString getStartupFailureReport() const {
Chris@1227 199 return m_errorString;
Chris@1227 200 }
Chris@1865 201
Chris@1865 202 signals:
Chris@1865 203 void transformsPopulated();
Chris@1865 204 void uninstalledTransformsPopulated();
Chris@1227 205
Chris@330 206 protected:
Chris@330 207 typedef std::map<TransformId, TransformDescription> TransformDescriptionMap;
Chris@457 208
Chris@330 209 TransformDescriptionMap m_transforms;
Chris@457 210 bool m_transformsPopulated;
Chris@457 211
Chris@457 212 TransformDescriptionMap m_uninstalledTransforms;
Chris@457 213 bool m_uninstalledTransformsPopulated;
Chris@330 214
Chris@1227 215 QString m_errorString;
Chris@1227 216
Chris@330 217 void populateTransforms();
Chris@457 218 void populateUninstalledTransforms();
Chris@330 219 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
Chris@330 220 void populateRealTimePlugins(TransformDescriptionMap &);
Chris@330 221
Chris@1830 222 std::shared_ptr<Vamp::PluginBase> instantiateDefaultPluginFor(TransformId id, sv_samplerate_t rate);
Chris@460 223 QMutex m_transformsMutex;
Chris@460 224 QMutex m_uninstalledTransformsMutex;
Chris@460 225
Chris@460 226 class UninstalledTransformsPopulateThread : public QThread
Chris@460 227 {
Chris@460 228 public:
Chris@460 229 UninstalledTransformsPopulateThread(TransformFactory *factory) :
Chris@460 230 m_factory(factory) {
Chris@460 231 }
Chris@1580 232 void run() override;
Chris@460 233 TransformFactory *m_factory;
Chris@460 234 };
Chris@460 235
Chris@477 236 UninstalledTransformsPopulateThread *m_thread;
Chris@574 237 bool m_exiting;
Chris@479 238 bool m_populatingSlowly;
Chris@477 239
Chris@1842 240 SearchResults searchUnadjusted(QStringList keywords);
Chris@1842 241
Chris@330 242 static TransformFactory *m_instance;
Chris@330 243 };
Chris@330 244
Chris@330 245
Chris@330 246 #endif