annotate plugin/transform/TransformerFactory.h @ 328:21bd032ae791

* Introduce new Transform class which contains data necessary to describe the context for a plugin -- the plugin's name and output, the step/block size etc (formerly spread across ExecutionContext and TransformFactory). Other code hasn't been updated to use this yet. * Rename existing Transform stuff to Transformers (because they run Transforms) I'm still not 100% sure about this change, don't rely on it.
author Chris Cannam
date Mon, 05 Nov 2007 15:31:06 +0000
parents plugin/transform/TransformFactory.h@bb6e4c46e202
children 3179d8b29336
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@328 16 #ifndef _TRANSFORMER_FACTORY_H_
Chris@328 17 #define _TRANSFORMER_FACTORY_H_
Chris@320 18
Chris@328 19 #include "Transformer.h"
Chris@328 20 #include "PluginTransformer.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@328 29 class TransformerFactory : public QObject
Chris@320 30 {
Chris@320 31 Q_OBJECT
Chris@320 32
Chris@320 33 public:
Chris@328 34 virtual ~TransformerFactory();
Chris@320 35
Chris@328 36 static TransformerFactory *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@328 46 struct TransformerDesc {
Chris@320 47
Chris@328 48 TransformerDesc() { }
Chris@328 49 TransformerDesc(QString _type, QString _category,
Chris@328 50 TransformerId _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@328 60 TransformerId 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@328 68 bool operator<(const TransformerDesc &od) const {
Chris@320 69 return (name < od.name);
Chris@320 70 };
Chris@320 71 };
Chris@328 72 typedef std::vector<TransformerDesc> TransformerList;
Chris@320 73
Chris@328 74 TransformerList getAllTransformers();
Chris@320 75
Chris@328 76 std::vector<QString> getAllTransformerTypes();
Chris@320 77
Chris@328 78 std::vector<QString> getTransformerCategories(QString transformType);
Chris@328 79 std::vector<QString> getTransformerMakers(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@328 88 Model *getConfigurationForTransformer(TransformerId identifier,
Chris@320 89 const std::vector<Model *> &candidateInputModels,
Chris@328 90 PluginTransformer::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@328 100 PluginTransformer::ExecutionContext getDefaultContextForTransformer(TransformerId 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@328 116 Model *transform(TransformerId identifier, Model *inputModel,
Chris@328 117 const PluginTransformer::ExecutionContext &context,
Chris@320 118 QString configurationXml = "");
Chris@320 119
Chris@320 120 /**
Chris@326 121 * Return true if the given transform is known.
Chris@326 122 */
Chris@328 123 bool haveTransformer(TransformerId identifier);
Chris@326 124
Chris@326 125 /**
Chris@320 126 * Full name of a transform, suitable for putting on a menu.
Chris@320 127 */
Chris@328 128 QString getTransformerName(TransformerId identifier);
Chris@320 129
Chris@320 130 /**
Chris@320 131 * Brief but friendly name of a transform, suitable for use
Chris@320 132 * as the name of the output layer.
Chris@320 133 */
Chris@328 134 QString getTransformerFriendlyName(TransformerId identifier);
Chris@320 135
Chris@328 136 QString getTransformerUnits(TransformerId identifier);
Chris@320 137
Chris@320 138 /**
Chris@320 139 * Return true if the transform has any configurable parameters,
Chris@328 140 * i.e. if getConfigurationForTransformer can ever return a non-trivial
Chris@320 141 * (not equivalent to empty) configuration string.
Chris@320 142 */
Chris@328 143 bool isTransformerConfigurable(TransformerId identifier);
Chris@320 144
Chris@320 145 /**
Chris@320 146 * If the transform has a prescribed number or range of channel
Chris@320 147 * inputs, return true and set minChannels and maxChannels to the
Chris@320 148 * minimum and maximum number of channel inputs the transform can
Chris@320 149 * accept. Return false if it doesn't care.
Chris@320 150 */
Chris@328 151 bool getTransformerChannelRange(TransformerId identifier,
Chris@320 152 int &minChannels, int &maxChannels);
Chris@320 153
Chris@320 154 protected slots:
Chris@320 155 void transformFinished();
Chris@320 156
Chris@320 157 void modelAboutToBeDeleted(Model *);
Chris@320 158
Chris@320 159 protected:
Chris@328 160 Transformer *createTransformer(TransformerId identifier, Model *inputModel,
Chris@328 161 const PluginTransformer::ExecutionContext &context,
Chris@320 162 QString configurationXml);
Chris@320 163
Chris@328 164 struct TransformerIdent
Chris@320 165 {
Chris@328 166 TransformerId identifier;
Chris@320 167 QString configurationXml;
Chris@320 168 };
Chris@320 169
Chris@328 170 typedef std::map<TransformerId, QString> TransformerConfigurationMap;
Chris@328 171 TransformerConfigurationMap m_lastConfigurations;
Chris@320 172
Chris@328 173 typedef std::map<TransformerId, TransformerDesc> TransformerDescriptionMap;
Chris@328 174 TransformerDescriptionMap m_transforms;
Chris@320 175
Chris@328 176 typedef std::set<Transformer *> TransformerSet;
Chris@328 177 TransformerSet m_runningTransformers;
Chris@320 178
Chris@328 179 void populateTransformers();
Chris@328 180 void populateFeatureExtractionPlugins(TransformerDescriptionMap &);
Chris@328 181 void populateRealTimePlugins(TransformerDescriptionMap &);
Chris@320 182
Chris@328 183 bool getChannelRange(TransformerId identifier,
Chris@320 184 Vamp::PluginBase *plugin, int &min, int &max);
Chris@320 185
Chris@328 186 static TransformerFactory *m_instance;
Chris@320 187 };
Chris@320 188
Chris@320 189
Chris@320 190 #endif