annotate transform/ModelTransformerFactory.h @ 1207:d60f9715ba78 3.0-integration

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