annotate transform/TransformFactory.h @ 26:d88d117e0c34

* Add mono timestretch toggle button; some more work on getting blocksize etc parameters through to plugins
author Chris Cannam
date Mon, 18 Sep 2006 16:43:17 +0000
parents cd5d7ff8ef38
children 61259228d029
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Visualiser
Chris@0 5 An audio file viewer and annotation editor.
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #ifndef _TRANSFORM_FACTORY_H_
Chris@0 17 #define _TRANSFORM_FACTORY_H_
Chris@0 18
Chris@0 19 #include "Transform.h"
Chris@0 20
Chris@0 21 #include <map>
Chris@0 22
Chris@0 23 namespace Vamp { class PluginBase; }
Chris@0 24
Chris@0 25 class TransformFactory : public QObject
Chris@0 26 {
Chris@0 27 Q_OBJECT
Chris@0 28
Chris@0 29 public:
Chris@0 30 virtual ~TransformFactory();
Chris@0 31
Chris@0 32 static TransformFactory *getInstance();
Chris@0 33
Chris@0 34 // The name is intended to be computer-referenceable, and unique
Chris@0 35 // within the application. The description is intended to be
Chris@0 36 // human readable. In principle it doesn't have to be unique, but
Chris@0 37 // the factory will add suffixes to ensure that it is, all the
Chris@0 38 // same (just to avoid user confusion). The friendly name is a
Chris@0 39 // shorter version of the description. The type is also intended
Chris@0 40 // to be user-readable, for use in menus.
Chris@0 41
Chris@0 42 struct TransformDesc {
Chris@0 43 TransformDesc() { }
Chris@0 44 TransformDesc(QString _type, TransformName _name, QString _description,
Chris@0 45 QString _friendlyName, QString _maker,
Chris@0 46 QString _units, bool _configurable) :
Chris@0 47 type(_type), name(_name), description(_description),
Chris@0 48 friendlyName(_friendlyName),
Chris@0 49 maker(_maker), units(_units), configurable(_configurable) { }
Chris@0 50 QString type;
Chris@0 51 TransformName name;
Chris@0 52 QString description;
Chris@0 53 QString friendlyName;
Chris@0 54 QString maker;
Chris@0 55 QString units;
Chris@0 56 bool configurable;
Chris@0 57 };
Chris@0 58 typedef std::vector<TransformDesc> TransformList;
Chris@0 59
Chris@0 60 TransformList getAllTransforms();
Chris@0 61
Chris@0 62 std::vector<QString> getAllTransformTypes();
Chris@0 63
Chris@0 64 /**
Chris@0 65 * Get a configuration XML string for the given transform (by
Chris@0 66 * asking the user, most likely). Returns true if the transform
Chris@0 67 * is acceptable, false if the operation should be cancelled.
Chris@0 68 */
Chris@26 69 bool getConfigurationForTransform(TransformName name,
Chris@26 70 Model *inputModel,
Chris@0 71 int &channel,
Chris@0 72 QString &configurationXml);
Chris@0 73
Chris@0 74 /**
Chris@0 75 * Return the output model resulting from applying the named
Chris@0 76 * transform to the given input model. The transform may still be
Chris@0 77 * working in the background when the model is returned; check the
Chris@0 78 * output model's isReady completion status for more details.
Chris@0 79 *
Chris@0 80 * If the transform is unknown or the input model is not an
Chris@0 81 * appropriate type for the given transform, or if some other
Chris@0 82 * problem occurs, return 0.
Chris@0 83 *
Chris@0 84 * The returned model is owned by the caller and must be deleted
Chris@0 85 * when no longer needed.
Chris@0 86 */
Chris@0 87 Model *transform(TransformName name, Model *inputModel,
Chris@0 88 int channel, QString configurationXml = "");
Chris@0 89
Chris@0 90 /**
Chris@0 91 * Full description of a transform, suitable for putting on a menu.
Chris@0 92 */
Chris@0 93 QString getTransformDescription(TransformName name);
Chris@0 94
Chris@0 95 /**
Chris@0 96 * Brief but friendly description of a transform, suitable for use
Chris@0 97 * as the name of the output layer.
Chris@0 98 */
Chris@0 99 QString getTransformFriendlyName(TransformName name);
Chris@0 100
Chris@0 101 QString getTransformUnits(TransformName name);
Chris@0 102
Chris@0 103 /**
Chris@0 104 * Return true if the transform has any configurable parameters,
Chris@0 105 * i.e. if getConfigurationForTransform can ever return a non-trivial
Chris@0 106 * (not equivalent to empty) configuration string.
Chris@0 107 */
Chris@0 108 bool isTransformConfigurable(TransformName name);
Chris@0 109
Chris@0 110 /**
Chris@0 111 * If the transform has a prescribed number or range of channel
Chris@0 112 * inputs, return true and set minChannels and maxChannels to the
Chris@0 113 * minimum and maximum number of channel inputs the transform can
Chris@0 114 * accept.
Chris@0 115 */
Chris@0 116 bool getTransformChannelRange(TransformName name,
Chris@0 117 int &minChannels, int &maxChannels);
Chris@0 118
Chris@0 119 //!!! Need some way to indicate that the input model has changed /
Chris@0 120 //been deleted so as not to blow up backgrounded transform! -- Or
Chris@0 121 //indeed, if the output model has been deleted -- could equally
Chris@0 122 //well happen!
Chris@0 123
Chris@0 124 //!!! Need transform category!
Chris@0 125
Chris@0 126 protected slots:
Chris@0 127 void transformFinished();
Chris@0 128
Chris@0 129 protected:
Chris@0 130 Transform *createTransform(TransformName name, Model *inputModel,
Chris@0 131 int channel, QString configurationXml, bool start);
Chris@0 132
Chris@0 133 struct TransformIdent
Chris@0 134 {
Chris@0 135 TransformName name;
Chris@0 136 QString configurationXml;
Chris@0 137 };
Chris@0 138
Chris@0 139 typedef std::map<TransformName, QString> TransformConfigurationMap;
Chris@0 140 TransformConfigurationMap m_lastConfigurations;
Chris@0 141
Chris@0 142 typedef std::map<TransformName, TransformDesc> TransformDescriptionMap;
Chris@0 143 TransformDescriptionMap m_transforms;
Chris@0 144
Chris@0 145 void populateTransforms();
Chris@0 146 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
Chris@0 147 void populateRealTimePlugins(TransformDescriptionMap &);
Chris@0 148
Chris@0 149 bool getChannelRange(TransformName name,
Chris@0 150 Vamp::PluginBase *plugin, int &min, int &max);
Chris@0 151
Chris@0 152 static TransformFactory *m_instance;
Chris@0 153 };
Chris@0 154
Chris@0 155
Chris@0 156 #endif