Mercurial > hg > svcore
changeset 329:3179d8b29336
* Another incremental Transform update
author | Chris Cannam |
---|---|
date | Tue, 06 Nov 2007 17:08:11 +0000 |
parents | 21bd032ae791 |
children | 6e9dcf09b7fe |
files | plugin/transform/TransformDescription.h plugin/transform/Transformer.h plugin/transform/TransformerFactory.cpp plugin/transform/TransformerFactory.h |
diffstat | 4 files changed, 138 insertions(+), 97 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugin/transform/TransformDescription.h Tue Nov 06 17:08:11 2007 +0000 @@ -0,0 +1,71 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + This file copyright 2006-2007 Chris Cannam and QMUL. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef _TRANSFORM_DESCRIPTION_H_ +#define _TRANSFORM_DESCRIPTION_H_ + +#include "Transform.h" + +#include <QString> + +#include <vector> + +/** + * Metadata associated with a transform. + * + * The transform ID is the same as that used in the Transform class. + * It is intended to be computer-referenceable and unique within the + * application. + * + * The name is intended to be human readable. In principle it doesn't + * have to be unique, but the factory that creates these objects + * should add suffixes to ensure that it is, all the same (just to + * avoid user confusion). + * + * The friendly name is a shorter version of the name. + * + * The type is also intended to be user-readable, for use in menus. + */ + +struct TransformDescription +{ + TransformDescription() { } + TransformDescription(QString _type, QString _category, + TransformId _identifier, QString _name, + QString _friendlyName, QString _description, + QString _maker, QString _units, bool _configurable) : + type(_type), category(_category), + identifier(_identifier), name(_name), + friendlyName(_friendlyName), description(_description), + maker(_maker), units(_units), configurable(_configurable) { } + + QString type; // e.g. feature extraction plugin + QString category; // e.g. time > onsets + TransformId identifier; // e.g. vamp:vamp-aubio:aubioonset + QString name; // plugin's name if 1 output, else "name: output" + QString friendlyName; // short text for layer name + QString description; // sentence describing transform + QString maker; + QString units; + bool configurable; + + bool operator<(const TransformDescription &od) const { + return (name < od.name); + }; +}; + +typedef std::vector<TransformDescription> TransformList; + +#endif
--- a/plugin/transform/Transformer.h Mon Nov 05 15:31:06 2007 +0000 +++ b/plugin/transform/Transformer.h Tue Nov 06 17:08:11 2007 +0000 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _TRANSFORM_H_ -#define _TRANSFORM_H_ +#ifndef _TRANSFORMER_H_ +#define _TRANSFORMER_H_ #include "base/Thread.h"
--- a/plugin/transform/TransformerFactory.cpp Mon Nov 05 15:31:06 2007 +0000 +++ b/plugin/transform/TransformerFactory.cpp Tue Nov 06 17:08:11 2007 +0000 @@ -48,19 +48,19 @@ { } -TransformerFactory::TransformerList -TransformerFactory::getAllTransformers() +TransformList +TransformerFactory::getAllTransforms() { - if (m_transforms.empty()) populateTransformers(); + if (m_transforms.empty()) populateTransforms(); - std::set<TransformerDesc> dset; - for (TransformerDescriptionMap::const_iterator i = m_transforms.begin(); + std::set<TransformDescription> dset; + for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); i != m_transforms.end(); ++i) { dset.insert(i->second); } - TransformerList list; - for (std::set<TransformerDesc>::const_iterator i = dset.begin(); + TransformList list; + for (std::set<TransformDescription>::const_iterator i = dset.begin(); i != dset.end(); ++i) { list.push_back(*i); } @@ -71,10 +71,10 @@ std::vector<QString> TransformerFactory::getAllTransformerTypes() { - if (m_transforms.empty()) populateTransformers(); + if (m_transforms.empty()) populateTransforms(); std::set<QString> types; - for (TransformerDescriptionMap::const_iterator i = m_transforms.begin(); + for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); i != m_transforms.end(); ++i) { types.insert(i->second.type); } @@ -90,10 +90,10 @@ std::vector<QString> TransformerFactory::getTransformerCategories(QString transformType) { - if (m_transforms.empty()) populateTransformers(); + if (m_transforms.empty()) populateTransforms(); std::set<QString> categories; - for (TransformerDescriptionMap::const_iterator i = m_transforms.begin(); + for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); i != m_transforms.end(); ++i) { if (i->second.type == transformType) { categories.insert(i->second.category); @@ -117,10 +117,10 @@ std::vector<QString> TransformerFactory::getTransformerMakers(QString transformType) { - if (m_transforms.empty()) populateTransformers(); + if (m_transforms.empty()) populateTransforms(); std::set<QString> makers; - for (TransformerDescriptionMap::const_iterator i = m_transforms.begin(); + for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); i != m_transforms.end(); ++i) { if (i->second.type == transformType) { makers.insert(i->second.maker); @@ -142,9 +142,9 @@ } void -TransformerFactory::populateTransformers() +TransformerFactory::populateTransforms() { - TransformerDescriptionMap transforms; + TransformDescriptionMap transforms; populateFeatureExtractionPlugins(transforms); populateRealTimePlugins(transforms); @@ -155,10 +155,10 @@ std::map<QString, QString> pluginSources; std::map<QString, QString> pluginMakers; - for (TransformerDescriptionMap::iterator i = transforms.begin(); + for (TransformDescriptionMap::iterator i = transforms.begin(); i != transforms.end(); ++i) { - TransformerDesc desc = i->second; + TransformDescription desc = i->second; QString td = desc.name; QString tn = td.section(": ", 0, 0); @@ -178,10 +178,10 @@ std::map<QString, int> counts; m_transforms.clear(); - for (TransformerDescriptionMap::iterator i = transforms.begin(); + for (TransformDescriptionMap::iterator i = transforms.begin(); i != transforms.end(); ++i) { - TransformerDesc desc = i->second; + TransformDescription desc = i->second; QString identifier = desc.identifier; QString maker = desc.maker; @@ -205,7 +205,7 @@ } void -TransformerFactory::populateFeatureExtractionPlugins(TransformerDescriptionMap &transforms) +TransformerFactory::populateFeatureExtractionPlugins(TransformDescriptionMap &transforms) { std::vector<QString> plugs = FeatureExtractionPluginFactory::getAllPluginIdentifiers(); @@ -218,7 +218,7 @@ FeatureExtractionPluginFactory::instanceFor(pluginId); if (!factory) { - std::cerr << "WARNING: TransformerFactory::populateTransformers: No feature extraction plugin factory for instance " << pluginId.toLocal8Bit().data() << std::endl; + std::cerr << "WARNING: TransformerFactory::populateTransforms: No feature extraction plugin factory for instance " << pluginId.toLocal8Bit().data() << std::endl; continue; } @@ -226,7 +226,7 @@ factory->instantiatePlugin(pluginId, 48000); if (!plugin) { - std::cerr << "WARNING: TransformerFactory::populateTransformers: Failed to instantiate plugin " << pluginId.toLocal8Bit().data() << std::endl; + std::cerr << "WARNING: TransformerFactory::populateTransforms: Failed to instantiate plugin " << pluginId.toLocal8Bit().data() << std::endl; continue; } @@ -282,7 +282,7 @@ // std::cerr << "Feature extraction plugin transform: " << transformId.toStdString() << std::endl; transforms[transformId] = - TransformerDesc(tr("Analysis"), + TransformDescription(tr("Analysis"), category, transformId, userName, @@ -298,7 +298,7 @@ } void -TransformerFactory::populateRealTimePlugins(TransformerDescriptionMap &transforms) +TransformerFactory::populateRealTimePlugins(TransformDescriptionMap &transforms) { std::vector<QString> plugs = RealTimePluginFactory::getAllPluginIdentifiers(); @@ -313,7 +313,7 @@ RealTimePluginFactory::instanceFor(pluginId); if (!factory) { - std::cerr << "WARNING: TransformerFactory::populateTransformers: No real time plugin factory for instance " << pluginId.toLocal8Bit().data() << std::endl; + std::cerr << "WARNING: TransformerFactory::populateTransforms: No real time plugin factory for instance " << pluginId.toLocal8Bit().data() << std::endl; continue; } @@ -321,7 +321,7 @@ factory->getPluginDescriptor(pluginId); if (!descriptor) { - std::cerr << "WARNING: TransformerFactory::populateTransformers: Failed to query plugin " << pluginId.toLocal8Bit().data() << std::endl; + std::cerr << "WARNING: TransformerFactory::populateTransforms: Failed to query plugin " << pluginId.toLocal8Bit().data() << std::endl; continue; } @@ -384,7 +384,7 @@ } transforms[transformId] = - TransformerDesc(tr("Effects Data"), + TransformDescription(tr("Effects Data"), category, transformId, userName, @@ -415,7 +415,7 @@ } transforms[transformId] = - TransformerDesc(type, + TransformDescription(type, category, transformId, pluginName, @@ -430,13 +430,13 @@ } bool -TransformerFactory::haveTransformer(TransformerId identifier) +TransformerFactory::haveTransformer(TransformId identifier) { return (m_transforms.find(identifier) != m_transforms.end()); } QString -TransformerFactory::getTransformerName(TransformerId identifier) +TransformerFactory::getTransformerName(TransformId identifier) { if (m_transforms.find(identifier) != m_transforms.end()) { return m_transforms[identifier].name; @@ -444,7 +444,7 @@ } QString -TransformerFactory::getTransformerFriendlyName(TransformerId identifier) +TransformerFactory::getTransformerFriendlyName(TransformId identifier) { if (m_transforms.find(identifier) != m_transforms.end()) { return m_transforms[identifier].friendlyName; @@ -452,7 +452,7 @@ } QString -TransformerFactory::getTransformerUnits(TransformerId identifier) +TransformerFactory::getTransformerUnits(TransformId identifier) { if (m_transforms.find(identifier) != m_transforms.end()) { return m_transforms[identifier].units; @@ -460,7 +460,7 @@ } bool -TransformerFactory::isTransformerConfigurable(TransformerId identifier) +TransformerFactory::isTransformerConfigurable(TransformId identifier) { if (m_transforms.find(identifier) != m_transforms.end()) { return m_transforms[identifier].configurable; @@ -468,7 +468,7 @@ } bool -TransformerFactory::getTransformerChannelRange(TransformerId identifier, +TransformerFactory::getTransformerChannelRange(TransformId identifier, int &min, int &max) { QString id = identifier.section(':', 0, 2); @@ -503,7 +503,7 @@ } bool -TransformerFactory::getChannelRange(TransformerId identifier, Vamp::PluginBase *plugin, +TransformerFactory::getChannelRange(TransformId identifier, Vamp::PluginBase *plugin, int &minChannels, int &maxChannels) { Vamp::Plugin *vp = 0; @@ -518,7 +518,7 @@ } Model * -TransformerFactory::getConfigurationForTransformer(TransformerId identifier, +TransformerFactory::getConfigurationForTransformer(TransformId identifier, const std::vector<Model *> &candidateInputModels, PluginTransformer::ExecutionContext &context, QString &configurationXml, @@ -719,7 +719,7 @@ } PluginTransformer::ExecutionContext -TransformerFactory::getDefaultContextForTransformer(TransformerId identifier, +TransformerFactory::getDefaultContextForTransformer(TransformId identifier, Model *inputModel) { PluginTransformer::ExecutionContext context(-1); @@ -742,7 +742,7 @@ } Transformer * -TransformerFactory::createTransformer(TransformerId identifier, Model *inputModel, +TransformerFactory::createTransformer(TransformId identifier, Model *inputModel, const PluginTransformer::ExecutionContext &context, QString configurationXml) { @@ -776,7 +776,7 @@ } Model * -TransformerFactory::transform(TransformerId identifier, Model *inputModel, +TransformerFactory::transform(TransformId identifier, Model *inputModel, const PluginTransformer::ExecutionContext &context, QString configurationXml) {
--- a/plugin/transform/TransformerFactory.h Mon Nov 05 15:31:06 2007 +0000 +++ b/plugin/transform/TransformerFactory.h Tue Nov 06 17:08:11 2007 +0000 @@ -16,6 +16,8 @@ #ifndef _TRANSFORMER_FACTORY_H_ #define _TRANSFORMER_FACTORY_H_ +#include "TransformDescription.h" + #include "Transformer.h" #include "PluginTransformer.h" @@ -26,6 +28,10 @@ class AudioCallbackPlaySource; +//!!! split into TransformFactory (information about available +// transforms, create default Transform for each transform ID etc) and +// TransformerFactory (create Transformers to apply transforms) + class TransformerFactory : public QObject { Q_OBJECT @@ -35,43 +41,7 @@ static TransformerFactory *getInstance(); - // The identifier is intended to be computer-referenceable, and - // unique within the application. The name is intended to be - // human readable. In principle it doesn't have to be unique, but - // the factory will add suffixes to ensure that it is, all the - // same (just to avoid user confusion). The friendly name is a - // shorter version of the name. The type is also intended to be - // user-readable, for use in menus. - - struct TransformerDesc { - - TransformerDesc() { } - TransformerDesc(QString _type, QString _category, - TransformerId _identifier, QString _name, - QString _friendlyName, QString _description, - QString _maker, QString _units, bool _configurable) : - type(_type), category(_category), - identifier(_identifier), name(_name), - friendlyName(_friendlyName), description(_description), - maker(_maker), units(_units), configurable(_configurable) { } - - QString type; // e.g. feature extraction plugin - QString category; // e.g. time > onsets - TransformerId identifier; // e.g. vamp:vamp-aubio:aubioonset - QString name; // plugin's name if 1 output, else "name: output" - QString friendlyName; // short text for layer name - QString description; // sentence describing transform - QString maker; - QString units; - bool configurable; - - bool operator<(const TransformerDesc &od) const { - return (name < od.name); - }; - }; - typedef std::vector<TransformerDesc> TransformerList; - - TransformerList getAllTransformers(); + TransformList getAllTransforms(); std::vector<QString> getAllTransformerTypes(); @@ -85,7 +55,7 @@ * be cancelled. Audio callback play source may be used to * audition effects plugins, if provided. */ - Model *getConfigurationForTransformer(TransformerId identifier, + Model *getConfigurationForTransformer(TransformId identifier, const std::vector<Model *> &candidateInputModels, PluginTransformer::ExecutionContext &context, QString &configurationXml, @@ -97,7 +67,7 @@ * Get the default execution context for the given transform * and input model (if known). */ - PluginTransformer::ExecutionContext getDefaultContextForTransformer(TransformerId identifier, + PluginTransformer::ExecutionContext getDefaultContextForTransformer(TransformId identifier, Model *inputModel = 0); /** @@ -113,34 +83,34 @@ * The returned model is owned by the caller and must be deleted * when no longer needed. */ - Model *transform(TransformerId identifier, Model *inputModel, + Model *transform(TransformId identifier, Model *inputModel, const PluginTransformer::ExecutionContext &context, QString configurationXml = ""); /** * Return true if the given transform is known. */ - bool haveTransformer(TransformerId identifier); + bool haveTransformer(TransformId identifier); /** * Full name of a transform, suitable for putting on a menu. */ - QString getTransformerName(TransformerId identifier); + QString getTransformerName(TransformId identifier); /** * Brief but friendly name of a transform, suitable for use * as the name of the output layer. */ - QString getTransformerFriendlyName(TransformerId identifier); + QString getTransformerFriendlyName(TransformId identifier); - QString getTransformerUnits(TransformerId identifier); + QString getTransformerUnits(TransformId identifier); /** * Return true if the transform has any configurable parameters, * i.e. if getConfigurationForTransformer can ever return a non-trivial * (not equivalent to empty) configuration string. */ - bool isTransformerConfigurable(TransformerId identifier); + bool isTransformerConfigurable(TransformId identifier); /** * If the transform has a prescribed number or range of channel @@ -148,7 +118,7 @@ * minimum and maximum number of channel inputs the transform can * accept. Return false if it doesn't care. */ - bool getTransformerChannelRange(TransformerId identifier, + bool getTransformerChannelRange(TransformId identifier, int &minChannels, int &maxChannels); protected slots: @@ -157,30 +127,30 @@ void modelAboutToBeDeleted(Model *); protected: - Transformer *createTransformer(TransformerId identifier, Model *inputModel, + Transformer *createTransformer(TransformId identifier, Model *inputModel, const PluginTransformer::ExecutionContext &context, QString configurationXml); - struct TransformerIdent + struct TransformIdent { - TransformerId identifier; + TransformId identifier; QString configurationXml; }; - typedef std::map<TransformerId, QString> TransformerConfigurationMap; + typedef std::map<TransformId, QString> TransformerConfigurationMap; TransformerConfigurationMap m_lastConfigurations; - typedef std::map<TransformerId, TransformerDesc> TransformerDescriptionMap; - TransformerDescriptionMap m_transforms; + typedef std::map<TransformId, TransformDescription> TransformDescriptionMap; + TransformDescriptionMap m_transforms; typedef std::set<Transformer *> TransformerSet; TransformerSet m_runningTransformers; - void populateTransformers(); - void populateFeatureExtractionPlugins(TransformerDescriptionMap &); - void populateRealTimePlugins(TransformerDescriptionMap &); + void populateTransforms(); + void populateFeatureExtractionPlugins(TransformDescriptionMap &); + void populateRealTimePlugins(TransformDescriptionMap &); - bool getChannelRange(TransformerId identifier, + bool getChannelRange(TransformId identifier, Vamp::PluginBase *plugin, int &min, int &max); static TransformerFactory *m_instance;