annotate plugin/transform/TransformFactory.h @ 325:82a2d3161e14

* Document FileSource
author Chris Cannam
date Thu, 01 Nov 2007 12:34:17 +0000
parents 32e50b620a6c
children bb6e4c46e202
rev   line source
Chris@320 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@320 2
Chris@320 3 /*
Chris@320 4 Sonic Visualiser
Chris@320 5 An audio file viewer and annotation editor.
Chris@320 6 Centre for Digital Music, Queen Mary, University of London.
Chris@320 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@320 8
Chris@320 9 This program is free software; you can redistribute it and/or
Chris@320 10 modify it under the terms of the GNU General Public License as
Chris@320 11 published by the Free Software Foundation; either version 2 of the
Chris@320 12 License, or (at your option) any later version. See the file
Chris@320 13 COPYING included with this distribution for more information.
Chris@320 14 */
Chris@320 15
Chris@320 16 #ifndef _TRANSFORM_FACTORY_H_
Chris@320 17 #define _TRANSFORM_FACTORY_H_
Chris@320 18
Chris@320 19 #include "Transform.h"
Chris@320 20 #include "PluginTransform.h"
Chris@320 21
Chris@320 22 #include <map>
Chris@320 23 #include <set>
Chris@320 24
Chris@320 25 namespace Vamp { class PluginBase; }
Chris@320 26
Chris@320 27 class AudioCallbackPlaySource;
Chris@320 28
Chris@320 29 class TransformFactory : public QObject
Chris@320 30 {
Chris@320 31 Q_OBJECT
Chris@320 32
Chris@320 33 public:
Chris@320 34 virtual ~TransformFactory();
Chris@320 35
Chris@320 36 static TransformFactory *getInstance();
Chris@320 37
Chris@320 38 // The identifier is intended to be computer-referenceable, and
Chris@320 39 // unique within the application. The name is intended to be
Chris@320 40 // human readable. In principle it doesn't have to be unique, but
Chris@320 41 // the factory will add suffixes to ensure that it is, all the
Chris@320 42 // same (just to avoid user confusion). The friendly name is a
Chris@320 43 // shorter version of the name. The type is also intended to be
Chris@320 44 // user-readable, for use in menus.
Chris@320 45
Chris@320 46 struct TransformDesc {
Chris@320 47
Chris@320 48 TransformDesc() { }
Chris@320 49 TransformDesc(QString _type, QString _category,
Chris@320 50 TransformId _identifier, QString _name,
Chris@320 51 QString _friendlyName, QString _description,
Chris@320 52 QString _maker, QString _units, bool _configurable) :
Chris@320 53 type(_type), category(_category),
Chris@320 54 identifier(_identifier), name(_name),
Chris@320 55 friendlyName(_friendlyName), description(_description),
Chris@320 56 maker(_maker), units(_units), configurable(_configurable) { }
Chris@320 57
Chris@320 58 QString type; // e.g. feature extraction plugin
Chris@320 59 QString category; // e.g. time > onsets
Chris@320 60 TransformId identifier; // e.g. vamp:vamp-aubio:aubioonset
Chris@320 61 QString name; // plugin's name if 1 output, else "name: output"
Chris@320 62 QString friendlyName; // short text for layer name
Chris@320 63 QString description; // sentence describing transform
Chris@320 64 QString maker;
Chris@320 65 QString units;
Chris@320 66 bool configurable;
Chris@320 67
Chris@320 68 bool operator<(const TransformDesc &od) const {
Chris@320 69 return (name < od.name);
Chris@320 70 };
Chris@320 71 };
Chris@320 72 typedef std::vector<TransformDesc> TransformList;
Chris@320 73
Chris@320 74 TransformList getAllTransforms();
Chris@320 75
Chris@320 76 std::vector<QString> getAllTransformTypes();
Chris@320 77
Chris@320 78 std::vector<QString> getTransformCategories(QString transformType);
Chris@320 79 std::vector<QString> getTransformMakers(QString transformType);
Chris@320 80
Chris@320 81 /**
Chris@320 82 * Get a configuration XML string for the given transform (by
Chris@320 83 * asking the user, most likely). Returns the selected input
Chris@320 84 * model if the transform is acceptable, 0 if the operation should
Chris@320 85 * be cancelled. Audio callback play source may be used to
Chris@320 86 * audition effects plugins, if provided.
Chris@320 87 */
Chris@320 88 Model *getConfigurationForTransform(TransformId identifier,
Chris@320 89 const std::vector<Model *> &candidateInputModels,
Chris@320 90 PluginTransform::ExecutionContext &context,
Chris@320 91 QString &configurationXml,
Chris@320 92 AudioCallbackPlaySource *source = 0,
Chris@320 93 size_t startFrame = 0,
Chris@320 94 size_t duration = 0);
Chris@320 95
Chris@320 96 /**
Chris@320 97 * Get the default execution context for the given transform
Chris@320 98 * and input model (if known).
Chris@320 99 */
Chris@320 100 PluginTransform::ExecutionContext getDefaultContextForTransform(TransformId identifier,
Chris@320 101 Model *inputModel = 0);
Chris@320 102
Chris@320 103 /**
Chris@320 104 * Return the output model resulting from applying the named
Chris@320 105 * transform to the given input model. The transform may still be
Chris@320 106 * working in the background when the model is returned; check the
Chris@320 107 * output model's isReady completion status for more details.
Chris@320 108 *
Chris@320 109 * If the transform is unknown or the input model is not an
Chris@320 110 * appropriate type for the given transform, or if some other
Chris@320 111 * problem occurs, return 0.
Chris@320 112 *
Chris@320 113 * The returned model is owned by the caller and must be deleted
Chris@320 114 * when no longer needed.
Chris@320 115 */
Chris@320 116 Model *transform(TransformId identifier, Model *inputModel,
Chris@320 117 const PluginTransform::ExecutionContext &context,
Chris@320 118 QString configurationXml = "");
Chris@320 119
Chris@320 120 /**
Chris@320 121 * Full name of a transform, suitable for putting on a menu.
Chris@320 122 */
Chris@320 123 QString getTransformName(TransformId identifier);
Chris@320 124
Chris@320 125 /**
Chris@320 126 * Brief but friendly name of a transform, suitable for use
Chris@320 127 * as the name of the output layer.
Chris@320 128 */
Chris@320 129 QString getTransformFriendlyName(TransformId identifier);
Chris@320 130
Chris@320 131 QString getTransformUnits(TransformId identifier);
Chris@320 132
Chris@320 133 /**
Chris@320 134 * Return true if the transform has any configurable parameters,
Chris@320 135 * i.e. if getConfigurationForTransform can ever return a non-trivial
Chris@320 136 * (not equivalent to empty) configuration string.
Chris@320 137 */
Chris@320 138 bool isTransformConfigurable(TransformId identifier);
Chris@320 139
Chris@320 140 /**
Chris@320 141 * If the transform has a prescribed number or range of channel
Chris@320 142 * inputs, return true and set minChannels and maxChannels to the
Chris@320 143 * minimum and maximum number of channel inputs the transform can
Chris@320 144 * accept. Return false if it doesn't care.
Chris@320 145 */
Chris@320 146 bool getTransformChannelRange(TransformId identifier,
Chris@320 147 int &minChannels, int &maxChannels);
Chris@320 148
Chris@320 149 protected slots:
Chris@320 150 void transformFinished();
Chris@320 151
Chris@320 152 void modelAboutToBeDeleted(Model *);
Chris@320 153
Chris@320 154 protected:
Chris@320 155 Transform *createTransform(TransformId identifier, Model *inputModel,
Chris@320 156 const PluginTransform::ExecutionContext &context,
Chris@320 157 QString configurationXml);
Chris@320 158
Chris@320 159 struct TransformIdent
Chris@320 160 {
Chris@320 161 TransformId identifier;
Chris@320 162 QString configurationXml;
Chris@320 163 };
Chris@320 164
Chris@320 165 typedef std::map<TransformId, QString> TransformConfigurationMap;
Chris@320 166 TransformConfigurationMap m_lastConfigurations;
Chris@320 167
Chris@320 168 typedef std::map<TransformId, TransformDesc> TransformDescriptionMap;
Chris@320 169 TransformDescriptionMap m_transforms;
Chris@320 170
Chris@320 171 typedef std::set<Transform *> TransformSet;
Chris@320 172 TransformSet m_runningTransforms;
Chris@320 173
Chris@320 174 void populateTransforms();
Chris@320 175 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
Chris@320 176 void populateRealTimePlugins(TransformDescriptionMap &);
Chris@320 177
Chris@320 178 bool getChannelRange(TransformId identifier,
Chris@320 179 Vamp::PluginBase *plugin, int &min, int &max);
Chris@320 180
Chris@320 181 static TransformFactory *m_instance;
Chris@320 182 };
Chris@320 183
Chris@320 184
Chris@320 185 #endif