comparison plugin/FeatureExtractionPluginFactory.cpp @ 249:d3ac9f953ebf

* Fix #1672407 confused by plugin-named files in cwd (or home?) * Fix #1491848 crash when loading new file while transform plugin runs * Fix #1502287 Background remains black after spectrogram layer deleted * Fix #1604477 Replacing the main audio file silences secondary audio file * Fix failure to initialise property box layout to last preference on startup * Fix resample/wrong-rate display in Pane, ensure that right rate is chosen if all current models have an acceptable rate even if previous main model had a different one * Fix "global zoom" broken in previous commit * Some fixes to spectrogram cache area updating (makes spectrogram appear more quickly, previously it had a tendency to refresh with empty space) * Fixes to colour 3d plot normalization
author Chris Cannam
date Thu, 08 Mar 2007 16:53:08 +0000
parents 2b40f83e7627
children db0dd744fa8d
comparison
equal deleted inserted replaced
248:084ae1c213ee 249:d3ac9f953ebf
26 #include <QFileInfo> 26 #include <QFileInfo>
27 #include <QTextStream> 27 #include <QTextStream>
28 28
29 #include <iostream> 29 #include <iostream>
30 30
31 //#define DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 1
32
31 static FeatureExtractionPluginFactory *_nativeInstance = 0; 33 static FeatureExtractionPluginFactory *_nativeInstance = 0;
32 34
33 FeatureExtractionPluginFactory * 35 FeatureExtractionPluginFactory *
34 FeatureExtractionPluginFactory::instance(QString pluginType) 36 FeatureExtractionPluginFactory::instance(QString pluginType)
35 { 37 {
88 std::vector<QString> rv; 90 std::vector<QString> rv;
89 std::vector<QString> path = getPluginPath(); 91 std::vector<QString> path = getPluginPath();
90 92
91 for (std::vector<QString>::iterator i = path.begin(); i != path.end(); ++i) { 93 for (std::vector<QString>::iterator i = path.begin(); i != path.end(); ++i) {
92 94
93 // std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: scanning directory " << i->toStdString() << std::endl; 95 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
96 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: scanning directory " << i->toStdString() << std::endl;
97 #endif
94 98
95 QDir pluginDir(*i, PLUGIN_GLOB, 99 QDir pluginDir(*i, PLUGIN_GLOB,
96 QDir::Name | QDir::IgnoreCase, 100 QDir::Name | QDir::IgnoreCase,
97 QDir::Files | QDir::Readable); 101 QDir::Files | QDir::Readable);
98 102
99 for (unsigned int j = 0; j < pluginDir.count(); ++j) { 103 for (unsigned int j = 0; j < pluginDir.count(); ++j) {
100 104
101 QString soname = pluginDir.filePath(pluginDir[j]); 105 QString soname = pluginDir.filePath(pluginDir[j]);
106
107 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
108 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: trying potential library " << soname.toStdString() << std::endl;
109 #endif
102 110
103 void *libraryHandle = DLOPEN(soname, RTLD_LAZY); 111 void *libraryHandle = DLOPEN(soname, RTLD_LAZY);
104 112
105 if (!libraryHandle) { 113 if (!libraryHandle) {
106 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to load library " << soname.toStdString() << ": " << DLERROR() << std::endl; 114 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to load library " << soname.toStdString() << ": " << DLERROR() << std::endl;
107 continue; 115 continue;
108 } 116 }
117
118 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
119 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: It's a library all right, checking for descriptor" << std::endl;
120 #endif
109 121
110 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) 122 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction)
111 DLSYM(libraryHandle, "vampGetPluginDescriptor"); 123 DLSYM(libraryHandle, "vampGetPluginDescriptor");
112 124
113 if (!fn) { 125 if (!fn) {
116 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to unload library " << soname.toStdString() << std::endl; 128 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to unload library " << soname.toStdString() << std::endl;
117 } 129 }
118 continue; 130 continue;
119 } 131 }
120 132
133 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
134 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: Vamp descriptor found" << std::endl;
135 #endif
136
121 const VampPluginDescriptor *descriptor = 0; 137 const VampPluginDescriptor *descriptor = 0;
122 int index = 0; 138 int index = 0;
123 139
124 while ((descriptor = fn(VAMP_API_VERSION, index))) { 140 while ((descriptor = fn(VAMP_API_VERSION, index))) {
125 QString id = PluginIdentifier::createIdentifier 141 QString id = PluginIdentifier::createIdentifier
126 ("vamp", soname, descriptor->identifier); 142 ("vamp", soname, descriptor->identifier);
127 rv.push_back(id); 143 rv.push_back(id);
128 // std::cerr << "Found id " << id.toStdString() << std::endl; 144 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
145 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: Found plugin id " << id.toStdString() << std::endl;
146 #endif
129 ++index; 147 ++index;
130 } 148 }
131 149
132 if (DLCLOSE(libraryHandle) != 0) { 150 if (DLCLOSE(libraryHandle) != 0) {
133 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to unload library " << soname.toStdString() << std::endl; 151 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to unload library " << soname.toStdString() << std::endl;
142 160
143 QString 161 QString
144 FeatureExtractionPluginFactory::findPluginFile(QString soname, QString inDir) 162 FeatureExtractionPluginFactory::findPluginFile(QString soname, QString inDir)
145 { 163 {
146 QString file = ""; 164 QString file = "";
165
166 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
167 std::cerr << "FeatureExtractionPluginFactory::findPluginFile(\""
168 << soname.toStdString() << "\", \"" << inDir.toStdString() << "\")"
169 << std::endl;
170 #endif
147 171
148 if (inDir != "") { 172 if (inDir != "") {
149 173
150 QDir dir(inDir, PLUGIN_GLOB, 174 QDir dir(inDir, PLUGIN_GLOB,
151 QDir::Name | QDir::IgnoreCase, 175 QDir::Name | QDir::IgnoreCase,
152 QDir::Files | QDir::Readable); 176 QDir::Files | QDir::Readable);
153 if (!dir.exists()) return ""; 177 if (!dir.exists()) return "";
154 178
155 file = dir.filePath(QFileInfo(soname).fileName()); 179 file = dir.filePath(QFileInfo(soname).fileName());
156 if (QFileInfo(file).exists()) { 180
181 if (QFileInfo(file).exists() && QFileInfo(file).isFile()) {
182
183 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
184 std::cerr << "FeatureExtractionPluginFactory::findPluginFile: "
185 << "found trivially at " << file.toStdString() << std::endl;
186 #endif
187
157 return file; 188 return file;
158 } 189 }
159 190
160 for (unsigned int j = 0; j < dir.count(); ++j) { 191 for (unsigned int j = 0; j < dir.count(); ++j) {
161 file = dir.filePath(dir[j]); 192 file = dir.filePath(dir[j]);
162 if (QFileInfo(file).baseName() == QFileInfo(soname).baseName()) { 193 if (QFileInfo(file).baseName() == QFileInfo(soname).baseName()) {
194
195 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
196 std::cerr << "FeatureExtractionPluginFactory::findPluginFile: "
197 << "found at " << file.toStdString() << std::endl;
198 #endif
199
163 return file; 200 return file;
164 } 201 }
165 } 202 }
166 203
204 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
205 std::cerr << "FeatureExtractionPluginFactory::findPluginFile (with dir): "
206 << "not found" << std::endl;
207 #endif
208
167 return ""; 209 return "";
168 210
169 } else { 211 } else {
170 212
171 QFileInfo fi(soname); 213 QFileInfo fi(soname);
172 if (fi.exists()) return soname; 214
215 if (fi.isAbsolute() && fi.exists() && fi.isFile()) {
216 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
217 std::cerr << "FeatureExtractionPluginFactory::findPluginFile: "
218 << "found trivially at " << soname.toStdString() << std::endl;
219 #endif
220 return soname;
221 }
173 222
174 if (fi.isAbsolute() && fi.absolutePath() != "") { 223 if (fi.isAbsolute() && fi.absolutePath() != "") {
175 file = findPluginFile(soname, fi.absolutePath()); 224 file = findPluginFile(soname, fi.absolutePath());
176 if (file != "") return file; 225 if (file != "") return file;
177 } 226 }
183 file = findPluginFile(soname, *i); 232 file = findPluginFile(soname, *i);
184 if (file != "") return file; 233 if (file != "") return file;
185 } 234 }
186 } 235 }
187 236
237 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
238 std::cerr << "FeatureExtractionPluginFactory::findPluginFile: "
239 << "not found" << std::endl;
240 #endif
241
188 return ""; 242 return "";
189 } 243 }
190 } 244 }
191 245
192 Vamp::Plugin * 246 Vamp::Plugin *
209 263
210 if (found == "") { 264 if (found == "") {
211 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to find library file " << soname.toStdString() << std::endl; 265 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to find library file " << soname.toStdString() << std::endl;
212 return 0; 266 return 0;
213 } else if (found != soname) { 267 } else if (found != soname) {
214 // std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: WARNING: Given library name was " << soname.toStdString() << ", found at " << found.toStdString() << std::endl; 268
215 // std::cerr << soname.toStdString() << " -> " << found.toStdString() << std::endl; 269 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
216 } 270 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Given library name was " << soname.toStdString() << ", found at " << found.toStdString() << std::endl;
271 std::cerr << soname.toStdString() << " -> " << found.toStdString() << std::endl;
272 #endif
273
274 }
217 275
218 soname = found; 276 soname = found;
219 277
220 void *libraryHandle = DLOPEN(soname, RTLD_LAZY); 278 void *libraryHandle = DLOPEN(soname, RTLD_LAZY);
221 279