Chris@320: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@320: Chris@320: /* Chris@320: Sonic Visualiser Chris@320: An audio file viewer and annotation editor. Chris@320: Centre for Digital Music, Queen Mary, University of London. Chris@320: This file copyright 2006 Chris Cannam and QMUL. Chris@320: Chris@320: This program is free software; you can redistribute it and/or Chris@320: modify it under the terms of the GNU General Public License as Chris@320: published by the Free Software Foundation; either version 2 of the Chris@320: License, or (at your option) any later version. See the file Chris@320: COPYING included with this distribution for more information. Chris@320: */ Chris@320: Chris@1581: #ifndef SV_MODEL_TRANSFORMER_FACTORY_H Chris@1581: #define SV_MODEL_TRANSFORMER_FACTORY_H Chris@320: Chris@331: #include "Transform.h" Chris@329: #include "TransformDescription.h" gyorgyf@786: #include "FeatureExtractionModelTransformer.h" Chris@329: Chris@331: #include "ModelTransformer.h" Chris@331: Chris@486: #include Chris@486: Chris@653: #include Chris@1703: #include Chris@320: #include Chris@320: #include Chris@848: #include Chris@1830: #include Chris@320: Chris@389: class AudioPlaySource; Chris@320: Chris@331: class ModelTransformerFactory : public QObject Chris@320: { Chris@320: Q_OBJECT Chris@320: Chris@320: public: Chris@331: virtual ~ModelTransformerFactory(); Chris@320: Chris@331: static ModelTransformerFactory *getInstance(); Chris@320: Chris@653: class UserConfigurator { Chris@653: public: Chris@653: virtual bool configure(ModelTransformer::Input &input, Chris@653: Transform &transform, Chris@1830: std::shared_ptr plugin, Chris@1740: ModelId &inputModel, Chris@653: AudioPlaySource *source, Chris@1048: sv_frame_t startFrame, Chris@1048: sv_frame_t duration, Chris@1740: const QMap &modelMap, Chris@653: QStringList candidateModelNames, Chris@653: QString defaultModelName) = 0; Chris@653: }; Chris@653: Chris@320: /** Chris@653: * Fill out the configuration for the given transform (may include Chris@653: * asking the user by calling back on the UserConfigurator). Chris@653: * Returns the selected input model and channel if the transform Chris@1740: * is acceptable, or an input with no model if the operation Chris@653: * should be cancelled. Audio play source may be used to audition Chris@653: * effects plugins, if provided. Chris@320: */ Chris@350: ModelTransformer::Input Chris@350: getConfigurationForTransform(Transform &transform, Chris@1740: std::vector candidateInputModels, Chris@1740: ModelId defaultInputModel, Chris@389: AudioPlaySource *source = 0, Chris@1048: sv_frame_t startFrame = 0, Chris@1048: sv_frame_t duration = 0, Chris@653: UserConfigurator *configurator = 0); Chris@877: Chris@877: class AdditionalModelHandler { Chris@877: public: Chris@878: virtual ~AdditionalModelHandler() { } Chris@878: Chris@878: // Exactly one of these functions will be called Chris@1740: virtual void moreModelsAvailable(std::vector models) = 0; Chris@878: virtual void noMoreModelsAvailable() = 0; Chris@877: }; Chris@350: Chris@320: /** Chris@320: * Return the output model resulting from applying the named Chris@320: * transform to the given input model. The transform may still be Chris@320: * working in the background when the model is returned; check the Chris@924: * output model's isReady completion status for more details. To Chris@924: * cancel a background transform, call abandon() on its model. Chris@320: * Chris@320: * If the transform is unknown or the input model is not an Chris@320: * appropriate type for the given transform, or if some other Chris@361: * problem occurs, return 0. Set message if there is any error or Chris@361: * warning to report. Chris@320: * Chris@877: * Some transforms may return additional models at the end of Chris@877: * processing. (For example, a transform that splits an output Chris@877: * into multiple one-per-bin models.) If an additionalModelHandler Chris@877: * is provided here, its moreModelsAvailable method will be called Chris@877: * when those models become available, and ownership of those Chris@877: * models will be transferred to the handler. Otherwise (if the Chris@877: * handler is null) any such models will be discarded. Chris@877: * Chris@320: * The returned model is owned by the caller and must be deleted Chris@320: * when no longer needed. Chris@320: */ Chris@1740: ModelId transform(const Transform &transform, Chris@1740: const ModelTransformer::Input &input, Chris@1740: QString &message, Chris@1740: AdditionalModelHandler *handler = 0); Chris@848: Chris@848: /** Chris@848: * Return the multiple output models resulting from applying the Chris@848: * named transforms to the given input model. The transforms may Chris@848: * differ only in output identifier for the plugin: they must all Chris@848: * use the same plugin, parameters, and programs. The plugin will Chris@848: * be run once only, but more than one output will be harvested Chris@848: * (as appropriate). Models will be returned in the same order as Chris@848: * the transforms were given. The plugin may still be working in Chris@848: * the background when the model is returned; check the output Chris@924: * models' isReady completion statuses for more details. To cancel Chris@924: * a background transform, call abandon() on its model. Chris@848: * Chris@848: * If a transform is unknown or the transforms are insufficiently Chris@848: * closely related or the input model is not an appropriate type Chris@848: * for the given transform, or if some other problem occurs, Chris@848: * return 0. Set message if there is any error or warning to Chris@848: * report. Chris@877: * Chris@877: * Some transforms may return additional models at the end of Chris@877: * processing. (For example, a transform that splits an output Chris@877: * into multiple one-per-bin models.) If an additionalModelHandler Chris@877: * is provided here, its moreModelsAvailable method will be called Chris@877: * when those models become available, and ownership of those Chris@877: * models will be transferred to the handler. Otherwise (if the Chris@924: * handler is null) any such models will be discarded. Note that Chris@924: * calling abandon() on any one of the models returned by Chris@924: * transformMultiple is sufficient to cancel all background Chris@924: * transform activity associated with these output models. Chris@877: * Chris@848: * The returned models are owned by the caller and must be deleted Chris@848: * when no longer needed. Chris@848: */ Chris@1740: std::vector transformMultiple(const Transforms &transform, Chris@848: const ModelTransformer::Input &input, Chris@877: QString &message, Chris@877: AdditionalModelHandler *handler = 0); Chris@320: Chris@1703: bool haveRunningTransformers() const; Chris@1703: Chris@1079: signals: Chris@1079: void transformFailed(QString transformName, QString message); Chris@1079: Chris@320: protected slots: Chris@331: void transformerFinished(); Chris@320: Chris@320: protected: Chris@850: ModelTransformer *createTransformer(const Transforms &transforms, Chris@350: const ModelTransformer::Input &input); Chris@320: Chris@1703: mutable QMutex m_mutex; Chris@1703: Chris@329: typedef std::map TransformerConfigurationMap; Chris@328: TransformerConfigurationMap m_lastConfigurations; Chris@320: Chris@331: typedef std::set TransformerSet; Chris@328: TransformerSet m_runningTransformers; Chris@320: Chris@877: typedef std::map HandlerMap; Chris@877: HandlerMap m_handlers; Chris@877: Chris@331: static ModelTransformerFactory *m_instance; Chris@320: }; Chris@320: Chris@320: Chris@320: #endif