comparison transform/TransformFactory.cpp @ 1546:9c14dee72329

Use locale-aware comparators for user-visible string sorting
author Chris Cannam
date Mon, 01 Oct 2018 14:37:30 +0100
parents 48e9f538e6e9
children 70e172e6cc59
comparison
equal deleted inserted replaced
1545:b89705af7a60 1546:9c14dee72329
30 30
31 #include "base/XmlExportable.h" 31 #include "base/XmlExportable.h"
32 32
33 #include <iostream> 33 #include <iostream>
34 #include <set> 34 #include <set>
35 #include <functional>
35 36
36 #include <QRegExp> 37 #include <QRegExp>
37 #include <QTextStream> 38 #include <QTextStream>
38 39
39 #include "base/Thread.h" 40 #include "base/Thread.h"
109 TransformFactory::getAllTransformDescriptions() 110 TransformFactory::getAllTransformDescriptions()
110 { 111 {
111 populateTransforms(); 112 populateTransforms();
112 113
113 std::set<TransformDescription> dset; 114 std::set<TransformDescription> dset;
114 for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); 115 for (auto i = m_transforms.begin(); i != m_transforms.end(); ++i) {
115 i != m_transforms.end(); ++i) {
116 #ifdef DEBUG_TRANSFORM_FACTORY 116 #ifdef DEBUG_TRANSFORM_FACTORY
117 cerr << "inserting transform into set: id = " << i->second.identifier << endl; 117 cerr << "inserting transform into set: id = " << i->second.identifier << " (" << i->second.name << ")" << endl;
118 #endif 118 #endif
119 dset.insert(i->second); 119 dset.insert(i->second);
120 } 120 }
121 121
122 TransformList list; 122 TransformList list;
123 for (std::set<TransformDescription>::const_iterator i = dset.begin(); 123 for (auto i = dset.begin(); i != dset.end(); ++i) {
124 i != dset.end(); ++i) {
125 #ifdef DEBUG_TRANSFORM_FACTORY 124 #ifdef DEBUG_TRANSFORM_FACTORY
126 cerr << "inserting transform into list: id = " << i->identifier << endl; 125 cerr << "inserting transform into list: id = " << i->identifier << " (" << i->name << ")" << endl;
127 #endif 126 #endif
128 list.push_back(*i); 127 list.push_back(*i);
129 } 128 }
130 129
131 return list; 130 return list;
155 { 154 {
156 m_populatingSlowly = false; 155 m_populatingSlowly = false;
157 populateUninstalledTransforms(); 156 populateUninstalledTransforms();
158 157
159 std::set<TransformDescription> dset; 158 std::set<TransformDescription> dset;
160 for (TransformDescriptionMap::const_iterator i = m_uninstalledTransforms.begin(); 159 for (auto i = m_uninstalledTransforms.begin();
161 i != m_uninstalledTransforms.end(); ++i) { 160 i != m_uninstalledTransforms.end(); ++i) {
162 #ifdef DEBUG_TRANSFORM_FACTORY 161 #ifdef DEBUG_TRANSFORM_FACTORY
163 cerr << "inserting transform into set: id = " << i->second.identifier << endl; 162 cerr << "inserting transform into set: id = " << i->second.identifier << endl;
164 #endif 163 #endif
165 dset.insert(i->second); 164 dset.insert(i->second);
166 } 165 }
167 166
168 TransformList list; 167 TransformList list;
169 for (std::set<TransformDescription>::const_iterator i = dset.begin(); 168 for (auto i = dset.begin(); i != dset.end(); ++i) {
170 i != dset.end(); ++i) {
171 #ifdef DEBUG_TRANSFORM_FACTORY 169 #ifdef DEBUG_TRANSFORM_FACTORY
172 cerr << "inserting transform into uninstalled list: id = " << i->identifier << endl; 170 cerr << "inserting transform into uninstalled list: id = " << i->identifier << endl;
173 #endif 171 #endif
174 list.push_back(*i); 172 list.push_back(*i);
175 } 173 }
245 TransformFactory::getAllTransformTypes() 243 TransformFactory::getAllTransformTypes()
246 { 244 {
247 populateTransforms(); 245 populateTransforms();
248 246
249 std::set<TransformDescription::Type> types; 247 std::set<TransformDescription::Type> types;
250 for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); 248 for (auto i = m_transforms.begin(); i != m_transforms.end(); ++i) {
251 i != m_transforms.end(); ++i) {
252 types.insert(i->second.type); 249 types.insert(i->second.type);
253 } 250 }
254 251
255 std::vector<TransformDescription::Type> rv; 252 std::vector<TransformDescription::Type> rv;
256 for (std::set<TransformDescription::Type>::iterator i = types.begin(); i != types.end(); ++i) { 253 for (auto i = types.begin(); i != types.end(); ++i) {
257 rv.push_back(*i); 254 rv.push_back(*i);
258 } 255 }
259 256
260 return rv; 257 return rv;
261 } 258 }
263 std::vector<QString> 260 std::vector<QString>
264 TransformFactory::getTransformCategories(TransformDescription::Type transformType) 261 TransformFactory::getTransformCategories(TransformDescription::Type transformType)
265 { 262 {
266 populateTransforms(); 263 populateTransforms();
267 264
268 std::set<QString> categories; 265 std::set<QString, std::function<bool(QString, QString)>>
269 for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); 266 categories(TransformDescription::compareUserStrings);
270 i != m_transforms.end(); ++i) { 267
268 for (auto i = m_transforms.begin(); i != m_transforms.end(); ++i) {
271 if (i->second.type == transformType) { 269 if (i->second.type == transformType) {
272 categories.insert(i->second.category); 270 categories.insert(i->second.category);
273 } 271 }
274 } 272 }
275 273
276 bool haveEmpty = false; 274 bool haveEmpty = false;
277 275
278 std::vector<QString> rv; 276 std::vector<QString> rv;
279 for (std::set<QString>::iterator i = categories.begin(); 277 for (auto i = categories.begin(); i != categories.end(); ++i) {
280 i != categories.end(); ++i) {
281 if (*i != "") rv.push_back(*i); 278 if (*i != "") rv.push_back(*i);
282 else haveEmpty = true; 279 else haveEmpty = true;
283 } 280 }
284 281
285 if (haveEmpty) rv.push_back(""); // make sure empty category sorts last 282 if (haveEmpty) rv.push_back(""); // make sure empty category sorts last
290 std::vector<QString> 287 std::vector<QString>
291 TransformFactory::getTransformMakers(TransformDescription::Type transformType) 288 TransformFactory::getTransformMakers(TransformDescription::Type transformType)
292 { 289 {
293 populateTransforms(); 290 populateTransforms();
294 291
295 std::set<QString> makers; 292 std::set<QString, std::function<bool(QString, QString)>>
296 for (TransformDescriptionMap::const_iterator i = m_transforms.begin(); 293 makers(TransformDescription::compareUserStrings);
297 i != m_transforms.end(); ++i) { 294
295 for (auto i = m_transforms.begin(); i != m_transforms.end(); ++i) {
298 if (i->second.type == transformType) { 296 if (i->second.type == transformType) {
299 makers.insert(i->second.maker); 297 makers.insert(i->second.maker);
300 } 298 }
301 } 299 }
302 300
303 bool haveEmpty = false; 301 bool haveEmpty = false;
304 302
305 std::vector<QString> rv; 303 std::vector<QString> rv;
306 for (std::set<QString>::iterator i = makers.begin(); 304 for (auto i = makers.begin(); i != makers.end(); ++i) {
307 i != makers.end(); ++i) {
308 if (*i != "") rv.push_back(*i); 305 if (*i != "") rv.push_back(*i);
309 else haveEmpty = true; 306 else haveEmpty = true;
310 } 307 }
311 308
312 if (haveEmpty) rv.push_back(""); // make sure empty category sorts last 309 if (haveEmpty) rv.push_back(""); // make sure empty category sorts last
412 m_errorString = tr("Failed to list Vamp plugins: %1").arg(errorMessage); 409 m_errorString = tr("Failed to list Vamp plugins: %1").arg(errorMessage);
413 } 410 }
414 411
415 if (m_exiting) return; 412 if (m_exiting) return;
416 413
417 for (int i = 0; i < (int)plugs.size(); ++i) { 414 for (int i = 0; in_range_for(plugs, i); ++i) {
418 415
419 QString pluginId = plugs[i]; 416 QString pluginId = plugs[i];
420 417
421 piper_vamp::PluginStaticData psd = factory->getPluginStaticData(pluginId); 418 piper_vamp::PluginStaticData psd = factory->getPluginStaticData(pluginId);
422 419
502 RealTimePluginFactory::getAllPluginIdentifiers(); 499 RealTimePluginFactory::getAllPluginIdentifiers();
503 if (m_exiting) return; 500 if (m_exiting) return;
504 501
505 static QRegExp unitRE("[\\[\\(]([A-Za-z0-9/]+)[\\)\\]]$"); 502 static QRegExp unitRE("[\\[\\(]([A-Za-z0-9/]+)[\\)\\]]$");
506 503
507 for (int i = 0; i < (int)plugs.size(); ++i) { 504 for (int i = 0; in_range_for(plugs, i); ++i) {
508 505
509 QString pluginId = plugs[i]; 506 QString pluginId = plugs[i];
510 507
511 RealTimePluginFactory *factory = 508 RealTimePluginFactory *factory =
512 RealTimePluginFactory::instanceFor(pluginId); 509 RealTimePluginFactory::instanceFor(pluginId);