PluginCatalog.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. #include "core/PluginCatalog.h"
  2. #include <algorithm>
  3. #include <cctype>
  4. #include <cstdlib>
  5. #include <functional>
  6. #include <sstream>
  7. namespace lynx::plugincatalog
  8. {
  9. namespace
  10. {
  11. std::string lower (std::string s)
  12. {
  13. std::transform (s.begin(), s.end(), s.begin(), [] (unsigned char c) { return (char) std::tolower (c); });
  14. return s;
  15. }
  16. bool has (const std::string& haystack, std::initializer_list<const char*> words)
  17. {
  18. return std::any_of (words.begin(), words.end(), [&haystack] (const char* w) { return haystack.find (w) != std::string::npos; });
  19. }
  20. // a short word as a whole token, or a token's start / end ("eq" in "Pro-EQ", "EQ8", not in "Frequency")
  21. bool hasToken (const std::string& text, std::initializer_list<const char*> words)
  22. {
  23. std::vector<std::string> tokens;
  24. std::string token;
  25. for (const auto c : text + " ")
  26. if (std::isalnum ((unsigned char) c))
  27. token += c;
  28. else if (! token.empty())
  29. {
  30. tokens.push_back (token);
  31. token.clear();
  32. }
  33. for (const auto* w : words)
  34. {
  35. const std::string word (w);
  36. for (const auto& t : tokens)
  37. if (t.size() >= word.size() && (t.compare (0, word.size(), word) == 0 || t.compare (t.size() - word.size(), word.size(), word) == 0))
  38. {
  39. // "eq8" / "proeq" yes; "equalis..." is matched by its own word, "sequencer" never (neither start nor end)
  40. return true;
  41. }
  42. }
  43. return false;
  44. }
  45. // LYNX's category names (the picker shows them translated)
  46. constexpr const char* synth = "Synth";
  47. constexpr const char* sampler = "Sampler";
  48. constexpr const char* drum = "Drum";
  49. constexpr const char* keys = "Piano & keys";
  50. constexpr const char* other = "Other";
  51. constexpr const char* delayReverb = "Delay & reverb";
  52. constexpr const char* distortion = "Distortion";
  53. constexpr const char* dynamics = "Dynamics";
  54. constexpr const char* eqFilter = "EQ & filter";
  55. constexpr const char* modulation = "Modulation";
  56. constexpr const char* pitch = "Pitch & vocal";
  57. constexpr const char* analyzer = "Analyzer";
  58. constexpr const char* visual = "Visual"; // FL's picker has a Visual group (Wave Candy, ZGameEditor Visualizer; round 164c)
  59. constexpr const char* utility = "Utility";
  60. std::string effectCategory (const std::string& declared, const std::string& name)
  61. {
  62. // what the plugin declares first (VST3 "Fx|Reverb", CLAP "audio-effect reverb"), then its name
  63. for (const auto* text : { &declared, &name })
  64. {
  65. const auto& t = *text;
  66. if (has (t, { "visualiz", "visualis", "video", "milkdrop", "projectm", "plugin dance", "big clock", "notebook" }) || hasToken (t, { "visual" }))
  67. return visual; // (round 165g: FL's Big Clock and HTML NoteBook sit in FL's Visual group)
  68. if (has (t, { "analy", "meter", "scope", "spectrum", "loudness", "tuner" }))
  69. return analyzer;
  70. if (has (t, { "reverb", "verb", "delay", "echo", "plate", "room", "hall", "spring" }))
  71. return delayReverb;
  72. if (has (t, { "pitch", "tune", "tuning", "vocal", "voice", "formant", "alterboy", "harmon" }))
  73. return pitch;
  74. if (has (t, { "compress", "limit", "dynamic", "gate", "expander", "de-ess", "deess", "transient", "clipper", "maxim", "leveler", "cla-2a",
  75. "la-2a", "1176" }) || hasToken (t, { "comp" }))
  76. return dynamics;
  77. if (has (t, { "filter", "equal", "channel strip", "channelstrip", "sslchannel", "pro-q" }) || hasToken (t, { "eq" }))
  78. return eqFilter;
  79. if (has (t, { "chorus", "flang", "phase", "modulat", "tremolo", "vibrato", "doubler", "ensemble", "rotary", "panman", "autopan", "wider", "stereo" }))
  80. return modulation;
  81. if (has (t, { "distort", "drive", "satur", "decapitator", "tube", "tape", "crush", "fuzz", "warm", "exciter", "fresh air" }) || hasToken (t, { "amp" }))
  82. return distortion;
  83. if (has (t, { "tools", "utility", "gain", "trim", "mono", "routing", "restoration", "noise", "spatial", "mute" }))
  84. return utility;
  85. }
  86. return other;
  87. }
  88. std::string instrumentCategory (const std::string& declared, const std::string& name)
  89. {
  90. for (const auto* text : { &declared, &name })
  91. {
  92. const auto& t = *text;
  93. if (has (t, { "drum", "beat", "kick", "808", "percussion" }))
  94. return drum;
  95. if (has (t, { "sampler", "sample", "rompler", "slicer" }))
  96. return sampler;
  97. if (has (t, { "piano", "keys", "organ", "rhodes", "e-piano" }))
  98. return keys;
  99. if (has (t, { "synth", "osc", "wavetable", "analog", "bass" }))
  100. return synth;
  101. }
  102. return other;
  103. }
  104. } // namespace
  105. std::string categoryOf (const Entry& entry)
  106. {
  107. auto declared = lower (entry.category);
  108. // the bare kind words say nothing about the category
  109. for (const auto* generic : { "instrument", "fx", "effect", "audio-effect", "synth|", "generator" })
  110. if (declared == generic)
  111. declared.clear();
  112. if (entry.instrument && (declared == "synth" || declared == "instrument|synth"))
  113. declared.clear(); // VST2's "Synth": all instruments say it; the name decides (a drum machine, a sampler)
  114. const auto name = lower (entry.name);
  115. return entry.instrument ? instrumentCategory (declared, name) : effectCategory (declared, name);
  116. }
  117. const std::vector<std::string>& categories (bool instruments)
  118. {
  119. static const std::vector<std::string> generators { synth, sampler, drum, keys, other };
  120. static const std::vector<std::string> effects { delayReverb, distortion, dynamics, eqFilter, modulation, pitch, analyzer, visual, utility, other };
  121. return instruments ? generators : effects;
  122. }
  123. std::vector<int> select (const std::vector<Entry>& entries, const std::set<std::string>& favourites, const Filter& filter)
  124. {
  125. std::vector<std::string> words;
  126. {
  127. std::string word;
  128. for (const auto c : lower (filter.query) + " ")
  129. if (c == ' ')
  130. {
  131. if (! word.empty())
  132. words.push_back (word);
  133. word.clear();
  134. }
  135. else
  136. word += c;
  137. }
  138. std::vector<int> shown;
  139. for (int i = 0; i < (int) entries.size(); ++i)
  140. {
  141. const auto& e = entries[(std::size_t) i];
  142. if (e.instrument != filter.instruments)
  143. continue;
  144. if (filter.favouritesOnly && favourites.count (e.id) == 0)
  145. continue;
  146. if (! filter.vendor.empty() && e.vendor != filter.vendor)
  147. continue;
  148. const auto category = categoryOf (e);
  149. if (! filter.category.empty() && category != filter.category)
  150. continue;
  151. if (! words.empty())
  152. {
  153. const auto text = lower (e.name + " " + e.renamed + " " + e.vendor + " " + e.format + " " + category);
  154. if (! std::all_of (words.begin(), words.end(), [&text] (const std::string& w) { return text.find (w) != std::string::npos; }))
  155. continue;
  156. }
  157. shown.push_back (i);
  158. }
  159. std::sort (shown.begin(), shown.end(), [&] (int a, int b) {
  160. const auto& x = entries[(std::size_t) a];
  161. const auto& y = entries[(std::size_t) b];
  162. if (filter.favouritesFirst)
  163. {
  164. const auto fx = favourites.count (x.id) > 0, fy = favourites.count (y.id) > 0;
  165. if (fx != fy)
  166. return fx;
  167. }
  168. const auto nx = lower (x.shownName()), ny = lower (y.shownName());
  169. if (nx != ny)
  170. return nx < ny;
  171. return x.format < y.format;
  172. });
  173. return shown;
  174. }
  175. std::vector<std::string> vendors (const std::vector<Entry>& entries, bool instruments)
  176. {
  177. std::vector<std::string> list;
  178. for (const auto& e : entries)
  179. if (e.instrument == instruments && ! e.vendor.empty() && std::find (list.begin(), list.end(), e.vendor) == list.end())
  180. list.push_back (e.vendor);
  181. std::sort (list.begin(), list.end(), [] (const std::string& a, const std::string& b) { return lower (a) < lower (b); });
  182. return list;
  183. }
  184. int countIn (const std::vector<Entry>& entries, bool instruments, const std::string& category)
  185. {
  186. return (int) std::count_if (entries.begin(), entries.end(),
  187. [&] (const Entry& e) { return e.instrument == instruments && (category.empty() || categoryOf (e) == category); });
  188. }
  189. // --- round 166f: the user's plugin folders ------------------------------------------------------------------------
  190. namespace
  191. {
  192. std::vector<std::string> splitPath (const std::string& path)
  193. {
  194. std::vector<std::string> parts;
  195. std::string part;
  196. auto flush = [&] {
  197. const auto a = part.find_first_not_of (" \t");
  198. if (a != std::string::npos) parts.push_back (part.substr (a, part.find_last_not_of (" \t") - a + 1));
  199. part.clear();
  200. };
  201. for (const auto c : path)
  202. if (c == '/' || c == '\\') flush();
  203. else if (c != '\t' && c != '\n' && c != '\r') part += c;
  204. flush();
  205. return parts;
  206. }
  207. bool within (const std::string& path, const std::string& folder) // path == folder or inside it
  208. {
  209. return path == folder || (path.size() > folder.size() && path.compare (0, folder.size(), folder) == 0 && path[folder.size()] == '/');
  210. }
  211. std::string nameKey (const std::string& s)
  212. {
  213. std::string k;
  214. for (const auto c : s)
  215. if (std::isalnum ((unsigned char) c)) k += (char) std::tolower ((unsigned char) c);
  216. return k;
  217. }
  218. // natural order ("EQ 2" before "EQ 10"), case-insensitive, by path parts
  219. int naturalCompare (const std::string& a, const std::string& b)
  220. {
  221. std::size_t i = 0, j = 0;
  222. while (i < a.size() && j < b.size())
  223. {
  224. if (std::isdigit ((unsigned char) a[i]) && std::isdigit ((unsigned char) b[j]))
  225. {
  226. std::size_t i2 = i, j2 = j;
  227. while (i2 < a.size() && std::isdigit ((unsigned char) a[i2])) ++i2;
  228. while (j2 < b.size() && std::isdigit ((unsigned char) b[j2])) ++j2;
  229. const auto na = std::stoull (a.substr (i, std::min<std::size_t> (18, i2 - i))), nb = std::stoull (b.substr (j, std::min<std::size_t> (18, j2 - j)));
  230. if (na != nb) return na < nb ? -1 : 1;
  231. i = i2; j = j2;
  232. continue;
  233. }
  234. // '/' sorts first so a parent comes right before its children
  235. const auto ca = a[i] == '/' ? (char) 1 : (char) std::tolower ((unsigned char) a[i]);
  236. const auto cb = b[j] == '/' ? (char) 1 : (char) std::tolower ((unsigned char) b[j]);
  237. if (ca != cb) return ca < cb ? -1 : 1;
  238. ++i; ++j;
  239. }
  240. return a.size() - i == b.size() - j ? 0 : (a.size() - i < b.size() - j ? -1 : 1);
  241. }
  242. } // namespace
  243. std::string cleanFolder (const std::string& path)
  244. {
  245. auto parts = splitPath (path);
  246. if ((int) parts.size() > maxFolderDepth) parts.resize ((std::size_t) maxFolderDepth);
  247. std::string out;
  248. for (const auto& p : parts) out += (out.empty() ? "" : "/") + p;
  249. return out;
  250. }
  251. std::string parentFolder (const std::string& path)
  252. {
  253. const auto slash = path.rfind ('/');
  254. return slash == std::string::npos ? std::string() : path.substr (0, slash);
  255. }
  256. std::string folderLeaf (const std::string& path)
  257. {
  258. const auto slash = path.rfind ('/');
  259. return slash == std::string::npos ? path : path.substr (slash + 1);
  260. }
  261. std::string addFolder (Folders& folders, bool instruments, const std::string& path)
  262. {
  263. const auto clean = cleanFolder (path);
  264. for (auto p = clean; ! p.empty(); p = parentFolder (p))
  265. folders.kind (instruments).insert (p);
  266. return clean;
  267. }
  268. Folders parseFolders (const std::string& text)
  269. {
  270. Folders f;
  271. std::istringstream in (text);
  272. std::string line;
  273. while (std::getline (in, line))
  274. {
  275. if (! line.empty() && line.back() == '\r') line.pop_back();
  276. const auto t1 = line.find ('\t');
  277. if (t1 == std::string::npos) continue;
  278. const auto tag = line.substr (0, t1);
  279. const auto rest = line.substr (t1 + 1);
  280. if (tag == "fx" || tag == "gen")
  281. addFolder (f, tag == "gen", rest);
  282. else if (tag == "view")
  283. f.view = std::clamp (std::atoi (rest.c_str()), 0, 2);
  284. else if (tag == "key")
  285. {
  286. const auto t2 = rest.rfind ('\t');
  287. if (t2 == std::string::npos || t2 == 0) continue;
  288. const auto key = rest.substr (0, t2);
  289. if (const auto path = cleanFolder (rest.substr (t2 + 1)); ! path.empty()) f.of[key] = path;
  290. }
  291. }
  292. return f;
  293. }
  294. std::string formatFolders (const Folders& folders)
  295. {
  296. std::string out;
  297. if (folders.view != 0) out += "view\t" + std::to_string (folders.view) + "\n";
  298. for (const auto* kind : { "fx", "gen" })
  299. for (const auto& path : folders.kind (std::string (kind) == "gen"))
  300. out += std::string (kind) + "\t" + path + "\n";
  301. for (const auto& [key, path] : folders.of)
  302. if (! key.empty() && key.find_first_of ("\t\n") == std::string::npos && ! path.empty())
  303. out += "key\t" + key + "\t" + path + "\n";
  304. return out;
  305. }
  306. bool renameFolder (Folders& folders, bool instruments, const std::string& from, const std::string& to)
  307. {
  308. const auto target = cleanFolder (to);
  309. auto& set = folders.kind (instruments);
  310. if (target.empty() || ! set.count (from) || within (target, from) || (target != from && set.count (target))) return target == from && ! target.empty();
  311. std::set<std::string> moved;
  312. for (auto it = set.begin(); it != set.end();)
  313. if (within (*it, from)) { moved.insert (target + it->substr (from.size())); it = set.erase (it); }
  314. else ++it;
  315. for (const auto& m : moved) addFolder (folders, instruments, m);
  316. for (auto& [key, path] : folders.of)
  317. if (within (path, from) && set.count (target + path.substr (from.size())))
  318. path = target + path.substr (from.size());
  319. return true;
  320. }
  321. void removeFolder (Folders& folders, bool instruments, const std::string& path, const std::vector<std::string>& keys)
  322. {
  323. auto& set = folders.kind (instruments);
  324. for (auto it = set.begin(); it != set.end();)
  325. it = within (*it, path) ? set.erase (it) : std::next (it);
  326. for (const auto& key : keys)
  327. if (const auto it = folders.of.find (key); it != folders.of.end() && within (it->second, path))
  328. folders.of.erase (it);
  329. }
  330. void moveToFolder (Folders& folders, bool instruments, const std::string& key, const std::string& path)
  331. {
  332. const auto clean = addFolder (folders, instruments, path);
  333. if (clean.empty()) folders.of.erase (key);
  334. else folders.of[key] = clean;
  335. folders.top.erase (key); // (a choice made in LYNX: no longer a root entry)
  336. }
  337. std::vector<MenuFolder> menuTree (const Folders& folders, bool instruments, const std::vector<std::string>& keys)
  338. {
  339. const auto& set = folders.kind (instruments);
  340. std::map<std::string, std::vector<int>> direct;
  341. for (int i = 0; i < (int) keys.size(); ++i)
  342. if (const auto it = folders.of.find (keys[(std::size_t) i]); it != folders.of.end() && set.count (it->second))
  343. direct[it->second].push_back (i);
  344. std::function<std::vector<MenuFolder> (const std::string&)> build = [&] (const std::string& parent) {
  345. std::vector<MenuFolder> out;
  346. for (const auto& path : set)
  347. if (parentFolder (path) == parent)
  348. {
  349. MenuFolder f;
  350. f.path = path;
  351. f.name = folderLeaf (path);
  352. f.sub = build (path);
  353. if (const auto it = direct.find (path); it != direct.end()) f.items = it->second;
  354. if (! f.items.empty() || ! f.sub.empty()) out.push_back (std::move (f));
  355. }
  356. std::sort (out.begin(), out.end(), [] (const MenuFolder& a, const MenuFolder& b) {
  357. const auto la = a.path == lynxCategory, lb = b.path == lynxCategory; // LYNX's own plugins first (round 170b)
  358. if (la != lb)
  359. return la;
  360. return naturalCompare (a.name, b.name) < 0;
  361. });
  362. return out;
  363. };
  364. return build ({});
  365. }
  366. std::vector<int> allItems (const std::vector<MenuFolder>& tree)
  367. {
  368. std::vector<int> out;
  369. for (const auto& f : tree)
  370. {
  371. const auto inner = allItems (f.sub);
  372. out.insert (out.end(), inner.begin(), inner.end());
  373. out.insert (out.end(), f.items.begin(), f.items.end());
  374. }
  375. return out;
  376. }
  377. std::vector<int> rootItems (const Folders& folders, bool instruments, const std::vector<std::string>& keys)
  378. {
  379. std::vector<int> out;
  380. const auto& set = folders.kind (instruments);
  381. for (int i = 0; i < (int) keys.size(); ++i)
  382. {
  383. const auto& key = keys[(std::size_t) i];
  384. if (! folders.top.count (key))
  385. continue;
  386. if (const auto it = folders.of.find (key); it != folders.of.end() && set.count (it->second))
  387. continue;
  388. out.push_back (i);
  389. }
  390. return out;
  391. }
  392. std::string groupHeading (const std::string& path)
  393. {
  394. std::string out;
  395. for (const auto c : path)
  396. out += c == '/' ? std::string (" \xe2\x80\xba ") : std::string (1, c); // " › "
  397. return out;
  398. }
  399. int importFlFolders (Folders& folders, bool instruments, const std::vector<std::string>& files,
  400. const std::vector<std::pair<std::string, std::string>>& keyAndName)
  401. {
  402. std::map<std::string, std::string> keyOfName;
  403. for (const auto& [key, name] : keyAndName)
  404. keyOfName.emplace (nameKey (name), key);
  405. int placed = 0;
  406. for (const auto& file : files)
  407. {
  408. auto parts = splitPath (file);
  409. if (parts.size() < 2) continue; // a preset at the top of the folder: no folder
  410. auto stem = parts.back();
  411. if (const auto dot = stem.rfind ('.'); dot != std::string::npos) stem = stem.substr (0, dot);
  412. parts.pop_back();
  413. std::string folder;
  414. for (const auto& p : parts) folder += (folder.empty() ? "" : "/") + p;
  415. const auto it = keyOfName.find (nameKey (stem));
  416. if (it == keyOfName.end() || cleanFolder (folder).empty()) continue;
  417. moveToFolder (folders, instruments, it->second, folder);
  418. ++placed;
  419. }
  420. return placed;
  421. }
  422. namespace
  423. {
  424. // letters and digits only, lower case ("Fruity X-Y Controller" -> "fruityxycontroller")
  425. std::string squash (const std::string& name)
  426. {
  427. std::string out;
  428. for (const auto c : name)
  429. if (std::isalnum ((unsigned char) c))
  430. out += (char) std::tolower ((unsigned char) c);
  431. return out;
  432. }
  433. struct CategoryList
  434. {
  435. const char* folder;
  436. std::vector<const char*> names;
  437. };
  438. const std::vector<CategoryList>& flEffectFolders()
  439. {
  440. static const std::vector<CategoryList> list {
  441. { "Controller", { "Control Surface", "Fruity Formula Controller", "Fruity Peak Controller", "Fruity X-Y Controller", "Fruity X-Y-Z Controller" } },
  442. { "Delay reverb", { "Fruity Convolver", "Fruity Delay 2", "Fruity Delay 3", "Fruity Delay Bank", "Fruity Reeverb 2", "LuxeVerb", "Multiband Delay",
  443. /* legacy */ "Fruity Delay", "Fruity Reeverb" } },
  444. { "Distortion", { "Distructor", "Fruity Blood Overdrive", "Fruity Fast Dist", "Fruity Soft Clipper", "Fruity Squeeze", "Fruity WaveShaper", "Hardcore" } },
  445. { "Dynamics", { "Emphasis", "Emphasizer", "Fruity Compressor", "Fruity Limiter", "Fruity Multiband Compressor", "Maximus", "Soundgoodizer",
  446. "Transient Processor" } },
  447. { "Filter", { "EQUO", "Frequency Splitter", "Fruity Filter", "Fruity Love Philter", "Fruity Parametric EQ 2", "Fruity Parametric EQ",
  448. /* legacy */ "Fruity 7 Band EQ", "Fruity Bass Boost", "Fruity Fast LP", "Fruity Free Filter" } },
  449. { "Flanger", { "Fruity Chorus", "Fruity Flanger", "Fruity Flangus", "Fruity Phaser", "Hyper Chorus", "Vintage Chorus", "Vintage Phaser" } },
  450. { "Gain", { "Fruity Balance", "Fruity PanOMatic", "Fruity Send", "Fruity Stereo Enhancer", "Fruity Stereo Shaper", "Spreader",
  451. /* legacy */ "Fruity Center", "Fruity Mute 2", "Fruity Phase Inverter" } },
  452. { "Misc", { "Edison", "Effector", "FL Studio Mobile Rack FX", "Frequency Shifter", "Fruity LSD", "Fruity Scratcher", "Fruity Vocoder", "Gross Beat",
  453. "Low Lifter", "Newtime", "Newtone", "Pitch Shifter", "Pitcher", "Transmitter", "Transporter", "Vocodex" } },
  454. { "Patcher", { "Patcher", "VFX Color Mapper", "VFX Envelope", "VFX Key Mapper", "VFX Keyboard Splitter", "VFX Level Scaler", "VFX Script", "VFX Sequencer" } },
  455. { "Visual", { "Fruity Big Clock", "Fruity HTML NoteBook", "Fruity NoteBook 2", "Fruity NoteBook", "Fruity Spectroman", "Fruity dB Meter", "Razer Chroma",
  456. "Tuner", "Wave Candy", "ZGameEditor Visualizer", /* LYNX's name of it */ "Visualizer" } },
  457. };
  458. return list;
  459. }
  460. const std::vector<CategoryList>& flGeneratorFolders()
  461. {
  462. static const std::vector<CategoryList> list {
  463. { "Controller", { "Fruity Envelope Controller", "Fruity Keyboard Controller" } },
  464. { "Drum", { "BassDrum", "Drumaxx", "Drumpad", "FPC", "Fruit Kick", "Fruity DrumSynth Live", "Fruity Slicer", "Fruity Slicer 2", "Slicex" } },
  465. { "MIDI", { "Dashboard", "MIDI Out" } },
  466. { "Misc", { "Audio Clip", "Automation Clip", "BooBass", "FL Keys", "FL Studio Mobile", "FL Studio Mobile Rack", "Fruity Voltage Controller", "Layer",
  467. "ReWired", "SoundFont Player" } },
  468. { "Patcher", { "Patcher", "VFX Color Mapper", "VFX Envelope", "VFX Key Mapper", "VFX Keyboard Splitter", "VFX Level Scaler", "VFX Script", "VFX Sequencer" } },
  469. { "Sampler", { "DirectWave", "Fruity Granulizer", "Sampler", "Wave Traveller" } },
  470. { "Synth classic", { "3x Osc", "FLEX", "Fruity DX10", "GMS", "Harmless", "Helix", "Kepler", "Kepler Exo", "MiniSynth", "Pocket SuperSaw", "PoiZone", "Sawer", "SimSynth", "Sytrus",
  471. "Tetra", "Toxic Biohazard", "Transistor Bass" } },
  472. // (FL lists Ogun under Drum and Synth special; one folder per plugin here: Synth special)
  473. { "Synth special", { "Autogun", "BeepMap", "Harmor", "Morphine", "Ogun", "Plucked!", "Sakura" } },
  474. { "Visual", { "Fruity Dance", "Fruity Video Player" } },
  475. };
  476. return list;
  477. }
  478. } // namespace
  479. std::string flCategory (const std::string& name, bool instruments, bool fruityPrefix)
  480. {
  481. const auto want = squash (name);
  482. if (want.empty())
  483. return {};
  484. for (const auto& folder : instruments ? flGeneratorFolders() : flEffectFolders())
  485. for (const auto* n : folder.names)
  486. if (const auto have = squash (n); have == want || (fruityPrefix && have == "fruity" + want))
  487. return folder.folder;
  488. return {};
  489. }
  490. Folders withDefaultCategories (const Folders& user, bool instruments, const std::vector<BuiltinPlugin>& builtins)
  491. {
  492. auto out = user;
  493. for (const auto& b : builtins)
  494. {
  495. if (const auto it = out.of.find (b.key); it != out.of.end() && out.kind (instruments).count (it->second))
  496. continue; // the user's folder wins
  497. if (out.hidden.count (b.key))
  498. continue; // taken out of the database by the user (round 190ba)
  499. if (out.top.count (b.key))
  500. continue; // at the top of the database, in no folder (round 190bf)
  501. auto folder = flCategory (b.name, instruments, b.fruityPrefix || b.flPlugin);
  502. if (folder.empty())
  503. folder = b.flPlugin ? "Misc" : lynxCategory;
  504. out.kind (instruments).insert (folder);
  505. out.of[b.key] = folder;
  506. }
  507. return out;
  508. }
  509. std::vector<std::string> combinedBits (const std::vector<std::pair<std::string, bool>>& items)
  510. {
  511. std::map<std::string, int> builds; // identity -> bit 1: a 32-bit build, bit 2: a 64-bit build
  512. for (const auto& [key, is32] : items)
  513. builds[key] |= is32 ? 1 : 2;
  514. std::vector<std::string> out;
  515. out.reserve (items.size());
  516. for (const auto& [key, is32] : items)
  517. {
  518. const auto both = builds[key] == 3;
  519. out.push_back (both ? (is32 ? "" : "32+64") : (is32 ? "32" : "64"));
  520. }
  521. return out;
  522. }
  523. } // namespace lynx::plugincatalog