annotate transform/ModelTransformerFactory.h @ 923:defbe5bc47b7 tonioni

Add an experimental cancel button to view progress bars
author Chris Cannam
date Fri, 13 Jun 2014 17:39:01 +0100
parents a2689db084f4
children 85879408f665 06579b8ffb7b
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@653 50 size_t startFrame,
Chris@653 51 size_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@350 70 size_t startFrame = 0,
Chris@653 71 size_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@320 87 * output model's isReady completion status for more details.
Chris@320 88 *
Chris@320 89 * If the transform is unknown or the input model is not an
Chris@320 90 * appropriate type for the given transform, or if some other
Chris@361 91 * problem occurs, return 0. Set message if there is any error or
Chris@361 92 * warning to report.
Chris@320 93 *
Chris@877 94 * Some transforms may return additional models at the end of
Chris@877 95 * processing. (For example, a transform that splits an output
Chris@877 96 * into multiple one-per-bin models.) If an additionalModelHandler
Chris@877 97 * is provided here, its moreModelsAvailable method will be called
Chris@877 98 * when those models become available, and ownership of those
Chris@877 99 * models will be transferred to the handler. Otherwise (if the
Chris@877 100 * handler is null) any such models will be discarded.
Chris@877 101 *
Chris@320 102 * The returned model is owned by the caller and must be deleted
Chris@320 103 * when no longer needed.
Chris@320 104 */
Chris@848 105 Model *transform(const Transform &transform,
Chris@848 106 const ModelTransformer::Input &input,
Chris@877 107 QString &message,
Chris@877 108 AdditionalModelHandler *handler = 0);
Chris@848 109
Chris@848 110 /**
Chris@848 111 * Return the multiple output models resulting from applying the
Chris@848 112 * named transforms to the given input model. The transforms may
Chris@848 113 * differ only in output identifier for the plugin: they must all
Chris@848 114 * use the same plugin, parameters, and programs. The plugin will
Chris@848 115 * be run once only, but more than one output will be harvested
Chris@848 116 * (as appropriate). Models will be returned in the same order as
Chris@848 117 * the transforms were given. The plugin may still be working in
Chris@848 118 * the background when the model is returned; check the output
Chris@848 119 * models' isReady completion statuses for more details.
Chris@848 120 *
Chris@848 121 * If a transform is unknown or the transforms are insufficiently
Chris@848 122 * closely related or the input model is not an appropriate type
Chris@848 123 * for the given transform, or if some other problem occurs,
Chris@848 124 * return 0. Set message if there is any error or warning to
Chris@848 125 * report.
Chris@877 126 *
Chris@877 127 * Some transforms may return additional models at the end of
Chris@877 128 * processing. (For example, a transform that splits an output
Chris@877 129 * into multiple one-per-bin models.) If an additionalModelHandler
Chris@877 130 * is provided here, its moreModelsAvailable method will be called
Chris@877 131 * when those models become available, and ownership of those
Chris@877 132 * models will be transferred to the handler. Otherwise (if the
Chris@877 133 * handler is null) any such models will be discarded.
Chris@877 134 *
Chris@848 135 * The returned models are owned by the caller and must be deleted
Chris@848 136 * when no longer needed.
Chris@848 137 */
Chris@848 138 std::vector<Model *> transformMultiple(const Transforms &transform,
Chris@848 139 const ModelTransformer::Input &input,
Chris@877 140 QString &message,
Chris@877 141 AdditionalModelHandler *handler = 0);
Chris@320 142
Chris@320 143 protected slots:
Chris@331 144 void transformerFinished();
Chris@320 145
Chris@320 146 void modelAboutToBeDeleted(Model *);
Chris@320 147
Chris@320 148 protected:
Chris@850 149 ModelTransformer *createTransformer(const Transforms &transforms,
Chris@350 150 const ModelTransformer::Input &input);
Chris@320 151
Chris@329 152 typedef std::map<TransformId, QString> TransformerConfigurationMap;
Chris@328 153 TransformerConfigurationMap m_lastConfigurations;
Chris@320 154
Chris@331 155 typedef std::set<ModelTransformer *> TransformerSet;
Chris@328 156 TransformerSet m_runningTransformers;
Chris@320 157
Chris@877 158 typedef std::map<ModelTransformer *, AdditionalModelHandler *> HandlerMap;
Chris@877 159 HandlerMap m_handlers;
Chris@877 160
Chris@331 161 static ModelTransformerFactory *m_instance;
Chris@320 162 };
Chris@320 163
Chris@320 164
Chris@320 165 #endif