annotate transform/ModelTransformerFactory.h @ 1849:00405d2cf0d1

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