comparison transform/ModelTransformerFactory.cpp @ 1830:5f8fbbde08ff audio-source-refactor

Use shared_ptr for plugin instances throughout
author Chris Cannam
date Fri, 20 Mar 2020 16:30:33 +0000
parents fe3f7f8df3a3
children
comparison
equal deleted inserted replaced
1829:51fd27fbce9a 1830:5f8fbbde08ff
38 #include <QMutexLocker> 38 #include <QMutexLocker>
39 39
40 using std::vector; 40 using std::vector;
41 using std::set; 41 using std::set;
42 using std::map; 42 using std::map;
43 using std::shared_ptr;
44 using std::make_shared;
43 45
44 ModelTransformerFactory * 46 ModelTransformerFactory *
45 ModelTransformerFactory::m_instance = new ModelTransformerFactory; 47 ModelTransformerFactory::m_instance = new ModelTransformerFactory;
46 48
47 ModelTransformerFactory * 49 ModelTransformerFactory *
108 bool ok = true; 110 bool ok = true;
109 QString configurationXml = m_lastConfigurations[transform.getIdentifier()]; 111 QString configurationXml = m_lastConfigurations[transform.getIdentifier()];
110 112
111 SVDEBUG << "ModelTransformer: last configuration for identifier " << transform.getIdentifier() << ": " << configurationXml << endl; 113 SVDEBUG << "ModelTransformer: last configuration for identifier " << transform.getIdentifier() << ": " << configurationXml << endl;
112 114
113 Vamp::PluginBase *plugin = nullptr; 115 shared_ptr<Vamp::PluginBase> plugin;
114 116
115 if (RealTimePluginFactory::instanceFor(id)) { 117 if (RealTimePluginFactory::instanceFor(id)) {
116 118
117 SVDEBUG << "ModelTransformerFactory::getConfigurationForTransform: instantiating real-time plugin" << endl; 119 SVDEBUG << "ModelTransformerFactory::getConfigurationForTransform: instantiating real-time plugin" << endl;
118 120
125 sampleRate = source->getSourceSampleRate(); 127 sampleRate = source->getSourceSampleRate();
126 blockSize = source->getTargetBlockSize(); 128 blockSize = source->getTargetBlockSize();
127 channels = source->getTargetChannelCount(); 129 channels = source->getTargetChannelCount();
128 } 130 }
129 131
130 RealTimePluginInstance *rtp = factory->instantiatePlugin 132 plugin = factory->instantiatePlugin
131 (id, 0, 0, sampleRate, blockSize, channels); 133 (id, 0, 0, sampleRate, blockSize, channels);
132 134
133 plugin = rtp;
134
135 } else { 135 } else {
136 136
137 SVDEBUG << "ModelTransformerFactory::getConfigurationForTransform: instantiating Vamp plugin" << endl; 137 SVDEBUG << "ModelTransformerFactory::getConfigurationForTransform: instantiating Vamp plugin" << endl;
138 138
139 Vamp::Plugin *vp = 139 plugin =
140 FeatureExtractionPluginFactory::instance()->instantiatePlugin 140 FeatureExtractionPluginFactory::instance()->instantiatePlugin
141 (id, float(defaultSampleRate)); 141 (id, float(defaultSampleRate));
142
143 plugin = vp;
144 } 142 }
145 143
146 if (plugin) { 144 if (plugin) {
147 145
148 // Ensure block size etc are valid 146 // Ensure block size etc are valid
170 168
171 TransformFactory::getInstance()-> 169 TransformFactory::getInstance()->
172 makeContextConsistentWithPlugin(transform, plugin); 170 makeContextConsistentWithPlugin(transform, plugin);
173 171
174 configurationXml = PluginXml(plugin).toXmlString(); 172 configurationXml = PluginXml(plugin).toXmlString();
175
176 SVDEBUG << "ModelTransformerFactory::getConfigurationForTransform: got configuration, deleting plugin" << endl;
177
178 delete plugin;
179 } 173 }
180 174
181 if (ok) { 175 if (ok) {
182 m_lastConfigurations[transform.getIdentifier()] = configurationXml; 176 m_lastConfigurations[transform.getIdentifier()] = configurationXml;
183 input.setModel(inputModel); 177 input.setModel(inputModel);