annotate transform/TransformFactory.h @ 118:b4110b17bca8

* Fix #1672407 confused by plugin-named files in cwd (or home?) * Fix #1491848 crash when loading new file while transform plugin runs * Fix #1502287 Background remains black after spectrogram layer deleted * Fix #1604477 Replacing the main audio file silences secondary audio file * Fix failure to initialise property box layout to last preference on startup * Fix resample/wrong-rate display in Pane, ensure that right rate is chosen if all current models have an acceptable rate even if previous main model had a different one * Fix "global zoom" broken in previous commit * Some fixes to spectrogram cache area updating (makes spectrogram appear more quickly, previously it had a tendency to refresh with empty space) * Fixes to colour 3d plot normalization
author Chris Cannam
date Thu, 08 Mar 2007 16:53:08 +0000
parents 58f21cf235c7
children ebd906049fb6
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@77 7 This file copyright 2006 Chris Cannam and QMUL.
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@27 20 #include "PluginTransform.h"
Chris@0 21
Chris@0 22 #include <map>
Chris@118 23 #include <set>
Chris@0 24
Chris@0 25 namespace Vamp { class PluginBase; }
Chris@0 26
Chris@41 27 class AudioCallbackPlaySource;
Chris@41 28
Chris@0 29 class TransformFactory : public QObject
Chris@0 30 {
Chris@0 31 Q_OBJECT
Chris@0 32
Chris@0 33 public:
Chris@0 34 virtual ~TransformFactory();
Chris@0 35
Chris@0 36 static TransformFactory *getInstance();
Chris@0 37
Chris@107 38 // The identifier is intended to be computer-referenceable, and
Chris@107 39 // unique within the application. The name is intended to be
Chris@0 40 // human readable. In principle it doesn't have to be unique, but
Chris@0 41 // the factory will add suffixes to ensure that it is, all the
Chris@0 42 // same (just to avoid user confusion). The friendly name is a
Chris@107 43 // shorter version of the name. The type is also intended to be
Chris@107 44 // user-readable, for use in menus.
Chris@0 45
Chris@0 46 struct TransformDesc {
Chris@34 47
Chris@0 48 TransformDesc() { }
Chris@33 49 TransformDesc(QString _type, QString _category,
Chris@107 50 TransformId _identifier, QString _name,
Chris@108 51 QString _friendlyName, QString _description,
Chris@108 52 QString _maker, QString _units, bool _configurable) :
Chris@33 53 type(_type), category(_category),
Chris@107 54 identifier(_identifier), name(_name),
Chris@108 55 friendlyName(_friendlyName), description(_description),
Chris@0 56 maker(_maker), units(_units), configurable(_configurable) { }
Chris@34 57
Chris@80 58 QString type; // e.g. feature extraction plugin
Chris@80 59 QString category; // e.g. time > onsets
Chris@107 60 TransformId identifier; // e.g. vamp:vamp-aubio:aubioonset
Chris@107 61 QString name; // plugin's name if 1 output, else "name: output"
Chris@80 62 QString friendlyName; // short text for layer name
Chris@108 63 QString description; // sentence describing transform
Chris@0 64 QString maker;
Chris@0 65 QString units;
Chris@0 66 bool configurable;
Chris@34 67
Chris@34 68 bool operator<(const TransformDesc &od) const {
Chris@107 69 return (name < od.name);
Chris@34 70 };
Chris@0 71 };
Chris@0 72 typedef std::vector<TransformDesc> TransformList;
Chris@0 73
Chris@0 74 TransformList getAllTransforms();
Chris@0 75
Chris@0 76 std::vector<QString> getAllTransformTypes();
Chris@0 77
Chris@33 78 std::vector<QString> getTransformCategories(QString transformType);
Chris@33 79 std::vector<QString> getTransformMakers(QString transformType);
Chris@33 80
Chris@0 81 /**
Chris@0 82 * Get a configuration XML string for the given transform (by
Chris@53 83 * asking the user, most likely). Returns the selected input
Chris@53 84 * model if the transform is acceptable, 0 if the operation should
Chris@53 85 * be cancelled. Audio callback play source may be used to
Chris@53 86 * audition effects plugins, if provided.
Chris@0 87 */
Chris@107 88 Model *getConfigurationForTransform(TransformId identifier,
Chris@53 89 const std::vector<Model *> &candidateInputModels,
Chris@53 90 PluginTransform::ExecutionContext &context,
Chris@53 91 QString &configurationXml,
Chris@53 92 AudioCallbackPlaySource *source = 0);
Chris@0 93
Chris@0 94 /**
Chris@73 95 * Get the default execution context for the given transform
Chris@73 96 * and input model (if known).
Chris@73 97 */
Chris@107 98 PluginTransform::ExecutionContext getDefaultContextForTransform(TransformId identifier,
Chris@73 99 Model *inputModel = 0);
Chris@73 100
Chris@73 101 /**
Chris@0 102 * Return the output model resulting from applying the named
Chris@0 103 * transform to the given input model. The transform may still be
Chris@0 104 * working in the background when the model is returned; check the
Chris@0 105 * output model's isReady completion status for more details.
Chris@0 106 *
Chris@0 107 * If the transform is unknown or the input model is not an
Chris@0 108 * appropriate type for the given transform, or if some other
Chris@0 109 * problem occurs, return 0.
Chris@0 110 *
Chris@0 111 * The returned model is owned by the caller and must be deleted
Chris@0 112 * when no longer needed.
Chris@0 113 */
Chris@107 114 Model *transform(TransformId identifier, Model *inputModel,
Chris@27 115 const PluginTransform::ExecutionContext &context,
Chris@27 116 QString configurationXml = "");
Chris@0 117
Chris@0 118 /**
Chris@107 119 * Full name of a transform, suitable for putting on a menu.
Chris@0 120 */
Chris@107 121 QString getTransformName(TransformId identifier);
Chris@0 122
Chris@0 123 /**
Chris@107 124 * Brief but friendly name of a transform, suitable for use
Chris@0 125 * as the name of the output layer.
Chris@0 126 */
Chris@107 127 QString getTransformFriendlyName(TransformId identifier);
Chris@0 128
Chris@107 129 QString getTransformUnits(TransformId identifier);
Chris@0 130
Chris@0 131 /**
Chris@0 132 * Return true if the transform has any configurable parameters,
Chris@0 133 * i.e. if getConfigurationForTransform can ever return a non-trivial
Chris@0 134 * (not equivalent to empty) configuration string.
Chris@0 135 */
Chris@107 136 bool isTransformConfigurable(TransformId identifier);
Chris@0 137
Chris@0 138 /**
Chris@0 139 * If the transform has a prescribed number or range of channel
Chris@0 140 * inputs, return true and set minChannels and maxChannels to the
Chris@0 141 * minimum and maximum number of channel inputs the transform can
Chris@34 142 * accept. Return false if it doesn't care.
Chris@0 143 */
Chris@107 144 bool getTransformChannelRange(TransformId identifier,
Chris@0 145 int &minChannels, int &maxChannels);
Chris@0 146
Chris@0 147 protected slots:
Chris@0 148 void transformFinished();
Chris@0 149
Chris@118 150 void modelAboutToBeDeleted(Model *);
Chris@118 151
Chris@0 152 protected:
Chris@107 153 Transform *createTransform(TransformId identifier, Model *inputModel,
Chris@27 154 const PluginTransform::ExecutionContext &context,
Chris@118 155 QString configurationXml);
Chris@0 156
Chris@0 157 struct TransformIdent
Chris@0 158 {
Chris@107 159 TransformId identifier;
Chris@0 160 QString configurationXml;
Chris@0 161 };
Chris@0 162
Chris@107 163 typedef std::map<TransformId, QString> TransformConfigurationMap;
Chris@0 164 TransformConfigurationMap m_lastConfigurations;
Chris@0 165
Chris@107 166 typedef std::map<TransformId, TransformDesc> TransformDescriptionMap;
Chris@0 167 TransformDescriptionMap m_transforms;
Chris@0 168
Chris@118 169 typedef std::set<Transform *> TransformSet;
Chris@118 170 TransformSet m_runningTransforms;
Chris@118 171
Chris@0 172 void populateTransforms();
Chris@0 173 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
Chris@0 174 void populateRealTimePlugins(TransformDescriptionMap &);
Chris@0 175
Chris@107 176 bool getChannelRange(TransformId identifier,
Chris@0 177 Vamp::PluginBase *plugin, int &min, int &max);
Chris@0 178
Chris@0 179 static TransformFactory *m_instance;
Chris@0 180 };
Chris@0 181
Chris@0 182
Chris@0 183 #endif