svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006-2007 Chris Cannam and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _TRANSFORM_FACTORY_H_ 00017 #define _TRANSFORM_FACTORY_H_ 00018 00019 #include "TransformDescription.h" 00020 00021 #include "base/TextMatcher.h" 00022 00023 #include <vamp-hostsdk/Plugin.h> 00024 00025 #include <QObject> 00026 #include <QStringList> 00027 #include <QThread> 00028 #include <QMutex> 00029 00030 #include <map> 00031 #include <set> 00032 00033 class TransformFactory : public QObject 00034 { 00035 Q_OBJECT 00036 00037 public: 00038 TransformFactory(); 00039 virtual ~TransformFactory(); 00040 00041 static TransformFactory *getInstance(); 00042 static void deleteInstance(); // only when exiting 00043 00054 void startPopulationThread(); 00055 00056 TransformList getAllTransformDescriptions(); 00057 TransformDescription getTransformDescription(TransformId id); 00058 bool haveInstalledTransforms(); 00059 00060 TransformList getUninstalledTransformDescriptions(); 00061 TransformDescription getUninstalledTransformDescription(TransformId id); 00062 bool haveUninstalledTransforms(bool waitForCheckToComplete = false); 00063 00064 typedef enum { 00065 TransformUnknown, 00066 TransformInstalled, 00067 TransformNotInstalled 00068 } TransformInstallStatus; 00069 00070 TransformInstallStatus getTransformInstallStatus(TransformId id); 00071 00072 std::vector<TransformDescription::Type> getAllTransformTypes(); 00073 std::vector<QString> getTransformCategories(TransformDescription::Type); 00074 std::vector<QString> getTransformMakers(TransformDescription::Type); 00075 QString getTransformTypeName(TransformDescription::Type) const; 00076 00077 typedef std::map<TransformId, TextMatcher::Match> SearchResults; 00078 SearchResults search(QString keyword); 00079 SearchResults search(QStringList keywords); 00080 00084 bool haveTransform(TransformId identifier); 00085 00091 Transform getDefaultTransformFor(TransformId identifier, int rate = 0); 00092 00096 QString getTransformName(TransformId identifier); 00097 00102 QString getTransformFriendlyName(TransformId identifier); 00103 00104 QString getTransformUnits(TransformId identifier); 00105 00106 QString getTransformInfoUrl(TransformId identifier); 00107 00108 Vamp::Plugin::InputDomain getTransformInputDomain(TransformId identifier); 00109 00115 bool isTransformConfigurable(TransformId identifier); 00116 00123 bool getTransformChannelRange(TransformId identifier, 00124 int &minChannels, int &maxChannels); 00125 00146 Vamp::PluginBase *instantiatePluginFor(const Transform &transform); 00147 00153 Vamp::Plugin *downcastVampPlugin(Vamp::PluginBase *); 00154 00161 void setParametersFromPlugin(Transform &transform, Vamp::PluginBase *plugin); 00162 00167 void setPluginParameters(const Transform &transform, Vamp::PluginBase *plugin); 00168 00174 void makeContextConsistentWithPlugin(Transform &transform, Vamp::PluginBase *plugin); 00175 00185 QString getPluginConfigurationXml(const Transform &transform); 00186 00196 void setParametersFromPluginConfigurationXml(Transform &transform, 00197 QString xml); 00198 00199 protected: 00200 typedef std::map<TransformId, TransformDescription> TransformDescriptionMap; 00201 00202 TransformDescriptionMap m_transforms; 00203 bool m_transformsPopulated; 00204 00205 TransformDescriptionMap m_uninstalledTransforms; 00206 bool m_uninstalledTransformsPopulated; 00207 00208 void populateTransforms(); 00209 void populateUninstalledTransforms(); 00210 void populateFeatureExtractionPlugins(TransformDescriptionMap &); 00211 void populateRealTimePlugins(TransformDescriptionMap &); 00212 00213 Vamp::PluginBase *instantiateDefaultPluginFor(TransformId id, int rate); 00214 QMutex m_transformsMutex; 00215 QMutex m_uninstalledTransformsMutex; 00216 00217 class UninstalledTransformsPopulateThread : public QThread 00218 { 00219 public: 00220 UninstalledTransformsPopulateThread(TransformFactory *factory) : 00221 m_factory(factory) { 00222 } 00223 virtual void run(); 00224 TransformFactory *m_factory; 00225 }; 00226 00227 UninstalledTransformsPopulateThread *m_thread; 00228 bool m_exiting; 00229 bool m_populatingSlowly; 00230 00231 static TransformFactory *m_instance; 00232 }; 00233 00234 00235 #endif