annotate transform/ModelTransformerFactory.h @ 1800:705ea8699d49

OK, that didn't work because of scoping/overload rules. Try this
author Chris Cannam
date Thu, 10 Oct 2019 09:18:37 +0100
parents fe3f7f8df3a3
children 5f8fbbde08ff
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@1581 16 #ifndef SV_MODEL_TRANSFORMER_FACTORY_H
Chris@1581 17 #define SV_MODEL_TRANSFORMER_FACTORY_H
Chris@320 18
Chris@331 19 #include "Transform.h"
Chris@329 20 #include "TransformDescription.h"
gyorgyf@786 21 #include "FeatureExtractionModelTransformer.h"
Chris@329 22
Chris@331 23 #include "ModelTransformer.h"
Chris@331 24
Chris@486 25 #include <vamp-hostsdk/PluginBase.h>
Chris@486 26
Chris@653 27 #include <QMap>
Chris@1703 28 #include <QMutex>
Chris@320 29 #include <map>
Chris@320 30 #include <set>
Chris@848 31 #include <vector>
Chris@320 32
Chris@389 33 class AudioPlaySource;
Chris@320 34
Chris@331 35 class ModelTransformerFactory : public QObject
Chris@320 36 {
Chris@320 37 Q_OBJECT
Chris@320 38
Chris@320 39 public:
Chris@331 40 virtual ~ModelTransformerFactory();
Chris@320 41
Chris@331 42 static ModelTransformerFactory *getInstance();
Chris@320 43
Chris@653 44 class UserConfigurator {
Chris@653 45 public:
Chris@653 46 virtual bool configure(ModelTransformer::Input &input,
Chris@653 47 Transform &transform,
Chris@653 48 Vamp::PluginBase *plugin,
Chris@1740 49 ModelId &inputModel,
Chris@653 50 AudioPlaySource *source,
Chris@1048 51 sv_frame_t startFrame,
Chris@1048 52 sv_frame_t duration,
Chris@1740 53 const QMap<QString, ModelId> &modelMap,
Chris@653 54 QStringList candidateModelNames,
Chris@653 55 QString defaultModelName) = 0;
Chris@653 56 };
Chris@653 57
Chris@320 58 /**
Chris@653 59 * Fill out the configuration for the given transform (may include
Chris@653 60 * asking the user by calling back on the UserConfigurator).
Chris@653 61 * Returns the selected input model and channel if the transform
Chris@1740 62 * is acceptable, or an input with no model if the operation
Chris@653 63 * should be cancelled. Audio play source may be used to audition
Chris@653 64 * effects plugins, if provided.
Chris@320 65 */
Chris@350 66 ModelTransformer::Input
Chris@350 67 getConfigurationForTransform(Transform &transform,
Chris@1740 68 std::vector<ModelId> candidateInputModels,
Chris@1740 69 ModelId defaultInputModel,
Chris@389 70 AudioPlaySource *source = 0,
Chris@1048 71 sv_frame_t startFrame = 0,
Chris@1048 72 sv_frame_t duration = 0,
Chris@653 73 UserConfigurator *configurator = 0);
Chris@877 74
Chris@877 75 class AdditionalModelHandler {
Chris@877 76 public:
Chris@878 77 virtual ~AdditionalModelHandler() { }
Chris@878 78
Chris@878 79 // Exactly one of these functions will be called
Chris@1740 80 virtual void moreModelsAvailable(std::vector<ModelId> models) = 0;
Chris@878 81 virtual void noMoreModelsAvailable() = 0;
Chris@877 82 };
Chris@350 83
Chris@320 84 /**
Chris@320 85 * Return the output model resulting from applying the named
Chris@320 86 * transform to the given input model. The transform may still be
Chris@320 87 * working in the background when the model is returned; check the
Chris@924 88 * output model's isReady completion status for more details. To
Chris@924 89 * cancel a background transform, call abandon() on its model.
Chris@320 90 *
Chris@320 91 * If the transform is unknown or the input model is not an
Chris@320 92 * appropriate type for the given transform, or if some other
Chris@361 93 * problem occurs, return 0. Set message if there is any error or
Chris@361 94 * warning to report.
Chris@320 95 *
Chris@877 96 * Some transforms may return additional models at the end of
Chris@877 97 * processing. (For example, a transform that splits an output
Chris@877 98 * into multiple one-per-bin models.) If an additionalModelHandler
Chris@877 99 * is provided here, its moreModelsAvailable method will be called
Chris@877 100 * when those models become available, and ownership of those
Chris@877 101 * models will be transferred to the handler. Otherwise (if the
Chris@877 102 * handler is null) any such models will be discarded.
Chris@877 103 *
Chris@320 104 * The returned model is owned by the caller and must be deleted
Chris@320 105 * when no longer needed.
Chris@320 106 */
Chris@1740 107 ModelId transform(const Transform &transform,
Chris@1740 108 const ModelTransformer::Input &input,
Chris@1740 109 QString &message,
Chris@1740 110 AdditionalModelHandler *handler = 0);
Chris@848 111
Chris@848 112 /**
Chris@848 113 * Return the multiple output models resulting from applying the
Chris@848 114 * named transforms to the given input model. The transforms may
Chris@848 115 * differ only in output identifier for the plugin: they must all
Chris@848 116 * use the same plugin, parameters, and programs. The plugin will
Chris@848 117 * be run once only, but more than one output will be harvested
Chris@848 118 * (as appropriate). Models will be returned in the same order as
Chris@848 119 * the transforms were given. The plugin may still be working in
Chris@848 120 * the background when the model is returned; check the output
Chris@924 121 * models' isReady completion statuses for more details. To cancel
Chris@924 122 * a background transform, call abandon() on its model.
Chris@848 123 *
Chris@848 124 * If a transform is unknown or the transforms are insufficiently
Chris@848 125 * closely related or the input model is not an appropriate type
Chris@848 126 * for the given transform, or if some other problem occurs,
Chris@848 127 * return 0. Set message if there is any error or warning to
Chris@848 128 * report.
Chris@877 129 *
Chris@877 130 * Some transforms may return additional models at the end of
Chris@877 131 * processing. (For example, a transform that splits an output
Chris@877 132 * into multiple one-per-bin models.) If an additionalModelHandler
Chris@877 133 * is provided here, its moreModelsAvailable method will be called
Chris@877 134 * when those models become available, and ownership of those
Chris@877 135 * models will be transferred to the handler. Otherwise (if the
Chris@924 136 * handler is null) any such models will be discarded. Note that
Chris@924 137 * calling abandon() on any one of the models returned by
Chris@924 138 * transformMultiple is sufficient to cancel all background
Chris@924 139 * transform activity associated with these output models.
Chris@877 140 *
Chris@848 141 * The returned models are owned by the caller and must be deleted
Chris@848 142 * when no longer needed.
Chris@848 143 */
Chris@1740 144 std::vector<ModelId> transformMultiple(const Transforms &transform,
Chris@848 145 const ModelTransformer::Input &input,
Chris@877 146 QString &message,
Chris@877 147 AdditionalModelHandler *handler = 0);
Chris@320 148
Chris@1703 149 bool haveRunningTransformers() const;
Chris@1703 150
Chris@1079 151 signals:
Chris@1079 152 void transformFailed(QString transformName, QString message);
Chris@1079 153
Chris@320 154 protected slots:
Chris@331 155 void transformerFinished();
Chris@320 156
Chris@320 157 protected:
Chris@850 158 ModelTransformer *createTransformer(const Transforms &transforms,
Chris@350 159 const ModelTransformer::Input &input);
Chris@320 160
Chris@1703 161 mutable QMutex m_mutex;
Chris@1703 162
Chris@329 163 typedef std::map<TransformId, QString> TransformerConfigurationMap;
Chris@328 164 TransformerConfigurationMap m_lastConfigurations;
Chris@320 165
Chris@331 166 typedef std::set<ModelTransformer *> TransformerSet;
Chris@328 167 TransformerSet m_runningTransformers;
Chris@320 168
Chris@877 169 typedef std::map<ModelTransformer *, AdditionalModelHandler *> HandlerMap;
Chris@877 170 HandlerMap m_handlers;
Chris@877 171
Chris@331 172 static ModelTransformerFactory *m_instance;
Chris@320 173 };
Chris@320 174
Chris@320 175
Chris@320 176 #endif