MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / SortByLastUsed

Function SortByLastUsed

Source/VSTPlugin.cpp:261–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259 }
260
261 void SortByLastUsed(std::vector<juce::PluginDescription>& vsts)
262 {
263 std::map<std::string, double> lastUsedTimes;
264
265 if (juce::File(ofToDataPath("vst/recent_plugins.json")).existsAsFile())
266 {
267 ofxJSONElement root;
268 root.open(ofToDataPath("vst/recent_plugins.json"));
269 ofxJSONElement jsonList = root["vsts"];
270
271 for (auto it = jsonList.begin(); it != jsonList.end(); ++it)
272 {
273 try
274 {
275 std::string key = it.key().asString();
276 lastUsedTimes[key] = jsonList[key].asDouble();
277 }
278 catch (Json::LogicError& e)
279 {
280 TheSynth->LogEvent(__PRETTY_FUNCTION__ + std::string(" json error: ") + e.what(), kLogEventType_Error);
281 }
282 }
283 }
284
285 std::sort(vsts.begin(), vsts.end(), [lastUsedTimes](juce::PluginDescription a, juce::PluginDescription b)
286 {
287 auto itA = lastUsedTimes.find(a.createIdentifierString().toStdString());
288 auto itB = lastUsedTimes.find(b.createIdentifierString().toStdString());
289 double timeA = 0;
290 double timeB = 0;
291 if (itA != lastUsedTimes.end())
292 timeA = (*itA).second;
293 if (itB != lastUsedTimes.end())
294 timeB = (*itB).second;
295
296 if (timeA == timeB)
297 return a.name < b.name;
298
299 return timeA > timeB;
300 });
301 }
302}
303
304VSTPlugin::VSTPlugin()

Callers 1

GetSpawnableModulesMethod · 0.85

Calls 3

ofToDataPathFunction · 0.85
openMethod · 0.80
LogEventMethod · 0.80

Tested by

no test coverage detected