TransformFactory.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006-2007 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_TRANSFORM_FACTORY_H
17 #define SV_TRANSFORM_FACTORY_H
18 
19 #include "TransformDescription.h"
20 
21 #include "base/TextMatcher.h"
22 
23 #include <vamp-hostsdk/Plugin.h>
24 
25 #include <QObject>
26 #include <QStringList>
27 #include <QThread>
28 #include <QMutex>
29 
30 #include <map>
31 #include <set>
32 #include <memory>
33 
34 class TransformFactory : public QObject
35 {
36  Q_OBJECT
37 
38 public:
40  virtual ~TransformFactory();
41 
42  static TransformFactory *getInstance();
43  static void deleteInstance(); // only when exiting
44 
55  void startPopulationThread();
56 
60 
63  bool haveUninstalledTransforms(bool waitForCheckToComplete = false);
64 
65  typedef enum {
70 
71  TransformInstallStatus getTransformInstallStatus(TransformId id);
72 
73  std::vector<TransformDescription::Type> getAllTransformTypes();
75  std::vector<QString> getTransformMakers(TransformDescription::Type);
77 
78  typedef std::map<TransformId, TextMatcher::Match> SearchResults;
79  SearchResults search(QString keyword);
80  SearchResults search(QStringList keywords);
81 
87  bool havePopulated();
88 
92  bool haveTransform(TransformId identifier);
93 
100  sv_samplerate_t rate = 0);
101 
105  QString getTransformName(TransformId identifier);
106 
111  QString getTransformFriendlyName(TransformId identifier);
112 
113  QString getTransformUnits(TransformId identifier);
114 
116 
117  Vamp::Plugin::InputDomain getTransformInputDomain(TransformId identifier);
118 
124  bool isTransformConfigurable(TransformId identifier);
125 
132  bool getTransformChannelRange(TransformId identifier,
133  int &minChannels, int &maxChannels);
134 
152  std::shared_ptr<Vamp::PluginBase> instantiatePluginFor(const Transform &transform);
153 
160  void setParametersFromPlugin(Transform &transform, std::shared_ptr<Vamp::PluginBase> plugin);
161 
166  void setPluginParameters(const Transform &transform, std::shared_ptr<Vamp::PluginBase> plugin);
167 
173  void makeContextConsistentWithPlugin(Transform &transform, std::shared_ptr<Vamp::PluginBase> plugin);
174 
184  QString getPluginConfigurationXml(const Transform &transform);
185 
196  QString xml);
197 
198  QString getStartupFailureReport() const {
199  return m_errorString;
200  }
201 
202 signals:
203  void transformsPopulated();
205 
206 protected:
207  typedef std::map<TransformId, TransformDescription> TransformDescriptionMap;
208 
209  TransformDescriptionMap m_transforms;
211 
212  TransformDescriptionMap m_uninstalledTransforms;
214 
215  QString m_errorString;
216 
217  void populateTransforms();
219  void populateFeatureExtractionPlugins(TransformDescriptionMap &);
220  void populateRealTimePlugins(TransformDescriptionMap &);
221 
222  std::shared_ptr<Vamp::PluginBase> instantiateDefaultPluginFor(TransformId id, sv_samplerate_t rate);
225 
226  class UninstalledTransformsPopulateThread : public QThread
227  {
228  public:
230  m_factory(factory) {
231  }
232  void run() override;
234  };
235 
237  bool m_exiting;
239 
240  SearchResults searchUnadjusted(QStringList keywords);
241 
243 };
244 
245 
246 #endif
double sv_samplerate_t
Sample rate.
Definition: BaseTypes.h:51
TransformInstallStatus getTransformInstallStatus(TransformId id)
Transform getDefaultTransformFor(TransformId identifier, sv_samplerate_t rate=0)
A single transform ID can lead to many possible Transforms, with different parameters and execution c...
std::vector< QString > getTransformCategories(TransformDescription::Type)
QString getTransformTypeName(TransformDescription::Type) const
void setParametersFromPlugin(Transform &transform, std::shared_ptr< Vamp::PluginBase > plugin)
Set the plugin parameters, program and configuration strings on the given Transform object from the g...
TransformDescriptionMap m_transforms
TransformList getUninstalledTransformDescriptions()
void transformsPopulated()
void setPluginParameters(const Transform &transform, std::shared_ptr< Vamp::PluginBase > plugin)
Set the parameters, program and configuration strings on the given plugin from the given Transform ob...
QMutex m_uninstalledTransformsMutex
std::map< TransformId, TransformDescription > TransformDescriptionMap
TransformDescription getTransformDescription(TransformId id)
std::vector< TransformDescription > TransformList
Vamp::Plugin::InputDomain getTransformInputDomain(TransformId identifier)
bool haveTransform(TransformId identifier)
Return true if the given transform is known.
void uninstalledTransformsPopulated()
UninstalledTransformsPopulateThread * m_thread
std::shared_ptr< Vamp::PluginBase > instantiatePluginFor(const Transform &transform)
Load an appropriate plugin for the given transform and set the parameters, program and configuration ...
bool m_uninstalledTransformsPopulated
SearchResults search(QString keyword)
QString getTransformName(TransformId identifier)
Full name of a transform, suitable for putting on a menu.
QString getTransformFriendlyName(TransformId identifier)
Brief but friendly name of a transform, suitable for use as the name of the output layer...
static TransformFactory * getInstance()
bool getTransformChannelRange(TransformId identifier, int &minChannels, int &maxChannels)
If the transform has a prescribed number or range of channel inputs, return true and set minChannels ...
static TransformFactory * m_instance
TransformList getAllTransformDescriptions()
void populateUninstalledTransforms()
void populateFeatureExtractionPlugins(TransformDescriptionMap &)
QString getPluginConfigurationXml(const Transform &transform)
Retrieve a <plugin ...
std::shared_ptr< Vamp::PluginBase > instantiateDefaultPluginFor(TransformId id, sv_samplerate_t rate)
bool isTransformConfigurable(TransformId identifier)
Return true if the transform has any configurable parameters, i.e.
bool havePopulated()
Return true if the transforms have been populated, i.e.
Provider getTransformProvider(TransformId identifier)
std::vector< TransformDescription::Type > getAllTransformTypes()
std::vector< QString > getTransformMakers(TransformDescription::Type)
QString getStartupFailureReport() const
void setParametersFromPluginConfigurationXml(Transform &transform, QString xml)
Set the plugin parameters, program and configuration strings on the given Transform object from the g...
bool haveUninstalledTransforms(bool waitForCheckToComplete=false)
std::map< TransformId, TextMatcher::Match > SearchResults
QString getTransformUnits(TransformId identifier)
Metadata associated with a transform.
void populateRealTimePlugins(TransformDescriptionMap &)
void makeContextConsistentWithPlugin(Transform &transform, std::shared_ptr< Vamp::PluginBase > plugin)
If the given Transform object has no processing step and block sizes set, set them to appropriate def...
void startPopulationThread()
TransformFactory has a background thread that can populate uninstalled transforms from network RDF re...
static void deleteInstance()
virtual ~TransformFactory()
SearchResults searchUnadjusted(QStringList keywords)
TransformDescription getUninstalledTransformDescription(TransformId id)
TransformDescriptionMap m_uninstalledTransforms
QString TransformId
Definition: Transform.h:30