annotate plugin/transform/ModelTransformerFactory.h @ 331:f620ce48c950

* Further naming change: Transformer -> ModelTransformer. The Transform class now describes a thing that can be done, and the ModelTransformer does it to a Model.
author Chris Cannam
date Wed, 07 Nov 2007 12:59:01 +0000
parents plugin/transform/TransformerFactory.h@3179d8b29336
children 13e5870040e6
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@331 16 #ifndef _MODEL_TRANSFORMER_FACTORY_H_
Chris@331 17 #define _MODEL_TRANSFORMER_FACTORY_H_
Chris@320 18
Chris@331 19 #include "Transform.h"
Chris@329 20 #include "TransformDescription.h"
Chris@329 21
Chris@331 22 #include "ModelTransformer.h"
Chris@331 23
Chris@328 24 #include "PluginTransformer.h"
Chris@320 25
Chris@320 26 #include <map>
Chris@320 27 #include <set>
Chris@320 28
Chris@320 29 namespace Vamp { class PluginBase; }
Chris@320 30
Chris@320 31 class AudioCallbackPlaySource;
Chris@320 32
Chris@329 33 //!!! split into TransformFactory (information about available
Chris@329 34 // transforms, create default Transform for each transform ID etc) and
Chris@329 35 // TransformerFactory (create Transformers to apply transforms)
Chris@329 36
Chris@331 37 class ModelTransformerFactory : public QObject
Chris@320 38 {
Chris@320 39 Q_OBJECT
Chris@320 40
Chris@320 41 public:
Chris@331 42 virtual ~ModelTransformerFactory();
Chris@320 43
Chris@331 44 static ModelTransformerFactory *getInstance();
Chris@320 45
Chris@329 46 TransformList getAllTransforms();
Chris@320 47
Chris@328 48 std::vector<QString> getAllTransformerTypes();
Chris@320 49
Chris@328 50 std::vector<QString> getTransformerCategories(QString transformType);
Chris@328 51 std::vector<QString> getTransformerMakers(QString transformType);
Chris@320 52
Chris@320 53 /**
Chris@320 54 * Get a configuration XML string for the given transform (by
Chris@320 55 * asking the user, most likely). Returns the selected input
Chris@320 56 * model if the transform is acceptable, 0 if the operation should
Chris@320 57 * be cancelled. Audio callback play source may be used to
Chris@320 58 * audition effects plugins, if provided.
Chris@320 59 */
Chris@329 60 Model *getConfigurationForTransformer(TransformId identifier,
Chris@320 61 const std::vector<Model *> &candidateInputModels,
Chris@328 62 PluginTransformer::ExecutionContext &context,
Chris@320 63 QString &configurationXml,
Chris@320 64 AudioCallbackPlaySource *source = 0,
Chris@320 65 size_t startFrame = 0,
Chris@320 66 size_t duration = 0);
Chris@320 67
Chris@320 68 /**
Chris@320 69 * Get the default execution context for the given transform
Chris@320 70 * and input model (if known).
Chris@320 71 */
Chris@329 72 PluginTransformer::ExecutionContext getDefaultContextForTransformer(TransformId identifier,
Chris@320 73 Model *inputModel = 0);
Chris@320 74
Chris@320 75 /**
Chris@320 76 * Return the output model resulting from applying the named
Chris@320 77 * transform to the given input model. The transform may still be
Chris@320 78 * working in the background when the model is returned; check the
Chris@320 79 * output model's isReady completion status for more details.
Chris@320 80 *
Chris@320 81 * If the transform is unknown or the input model is not an
Chris@320 82 * appropriate type for the given transform, or if some other
Chris@320 83 * problem occurs, return 0.
Chris@320 84 *
Chris@320 85 * The returned model is owned by the caller and must be deleted
Chris@320 86 * when no longer needed.
Chris@320 87 */
Chris@329 88 Model *transform(TransformId identifier, Model *inputModel,
Chris@328 89 const PluginTransformer::ExecutionContext &context,
Chris@320 90 QString configurationXml = "");
Chris@320 91
Chris@320 92 /**
Chris@326 93 * Return true if the given transform is known.
Chris@326 94 */
Chris@329 95 bool haveTransformer(TransformId identifier);
Chris@326 96
Chris@326 97 /**
Chris@320 98 * Full name of a transform, suitable for putting on a menu.
Chris@320 99 */
Chris@329 100 QString getTransformerName(TransformId identifier);
Chris@320 101
Chris@320 102 /**
Chris@320 103 * Brief but friendly name of a transform, suitable for use
Chris@320 104 * as the name of the output layer.
Chris@320 105 */
Chris@329 106 QString getTransformerFriendlyName(TransformId identifier);
Chris@320 107
Chris@329 108 QString getTransformerUnits(TransformId identifier);
Chris@320 109
Chris@320 110 /**
Chris@320 111 * Return true if the transform has any configurable parameters,
Chris@328 112 * i.e. if getConfigurationForTransformer can ever return a non-trivial
Chris@320 113 * (not equivalent to empty) configuration string.
Chris@320 114 */
Chris@329 115 bool isTransformerConfigurable(TransformId identifier);
Chris@320 116
Chris@320 117 /**
Chris@320 118 * If the transform has a prescribed number or range of channel
Chris@320 119 * inputs, return true and set minChannels and maxChannels to the
Chris@320 120 * minimum and maximum number of channel inputs the transform can
Chris@320 121 * accept. Return false if it doesn't care.
Chris@320 122 */
Chris@329 123 bool getTransformerChannelRange(TransformId identifier,
Chris@320 124 int &minChannels, int &maxChannels);
Chris@320 125
Chris@320 126 protected slots:
Chris@331 127 void transformerFinished();
Chris@320 128
Chris@320 129 void modelAboutToBeDeleted(Model *);
Chris@320 130
Chris@320 131 protected:
Chris@331 132 ModelTransformer *createTransformer(TransformId identifier, Model *inputModel,
Chris@331 133 const PluginTransformer::ExecutionContext &context,
Chris@331 134 QString configurationXml);
Chris@320 135
Chris@329 136 typedef std::map<TransformId, QString> TransformerConfigurationMap;
Chris@328 137 TransformerConfigurationMap m_lastConfigurations;
Chris@320 138
Chris@329 139 typedef std::map<TransformId, TransformDescription> TransformDescriptionMap;
Chris@329 140 TransformDescriptionMap m_transforms;
Chris@320 141
Chris@331 142 typedef std::set<ModelTransformer *> TransformerSet;
Chris@328 143 TransformerSet m_runningTransformers;
Chris@320 144
Chris@329 145 void populateTransforms();
Chris@329 146 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
Chris@329 147 void populateRealTimePlugins(TransformDescriptionMap &);
Chris@320 148
Chris@329 149 bool getChannelRange(TransformId identifier,
Chris@320 150 Vamp::PluginBase *plugin, int &min, int &max);
Chris@320 151
Chris@331 152 static ModelTransformerFactory *m_instance;
Chris@320 153 };
Chris@320 154
Chris@320 155
Chris@320 156 #endif