You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.1KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 3 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the LICENSE file.
  16. */
  17. #include <asset.hpp>
  18. #include <string.hpp>
  19. #include <system.hpp>
  20. #include <plugin/Plugin.hpp>
  21. #ifdef NDEBUG
  22. # undef DEBUG
  23. #endif
  24. #include <algorithm>
  25. #include "DistrhoUtils.hpp"
  26. namespace rack {
  27. namespace asset {
  28. std::string userDir; // ignored
  29. std::string systemDir; // points to plugin resources dir (or installed/local Rack dir)
  30. std::string bundlePath; // points to plugin manifests dir (or empty)
  31. // get rid of "res/" prefix
  32. static inline std::string& trim(std::string& s)
  33. {
  34. if (std::strncmp(s.c_str(), "res/", 4) == 0)
  35. s = s.substr(4, s.size()-4);
  36. return s;
  37. }
  38. // ignored, returns the same as `system`
  39. std::string user(std::string filename) {
  40. return system(filename);
  41. }
  42. // get system resource, trimming "res/" prefix if we are loaded as a plugin bundle
  43. std::string system(std::string filename) {
  44. // Always use dark screws
  45. if (string::endsWith(filename, "/ScrewSilver.svg"))
  46. filename = filename.substr(0, filename.size()-10) + "Black.svg";
  47. return system::join(systemDir, bundlePath.empty() ? filename : trim(filename));
  48. }
  49. // get plugin resource
  50. std::string plugin(plugin::Plugin* plugin, std::string filename) {
  51. DISTRHO_SAFE_ASSERT_RETURN(plugin != nullptr, {});
  52. // always use dark scheme
  53. if (plugin->slug == "GlueTheGiant")
  54. {
  55. if (filename == "res/BusDepot.svg"
  56. || filename == "res/BusRoute.svg"
  57. || filename == "res/EnterBus.svg"
  58. || filename == "res/ExitBus.svg"
  59. || filename == "res/GigBus.svg"
  60. || filename == "res/MetroCityBus.svg"
  61. || filename == "res/MiniBus.svg"
  62. || filename == "res/Road.svg"
  63. || filename == "res/SchoolBus.svg")
  64. {
  65. filename = filename.substr(0, filename.size()-4) + "_Night.svg";
  66. }
  67. }
  68. return system::join(plugin->path, filename);
  69. }
  70. // path to plugin manifest
  71. std::string pluginManifest(const std::string& dirname) {
  72. // no bundlePath set, assume local source build
  73. if (bundlePath.empty())
  74. return system::join(systemDir, "..", "..", "plugins", dirname, "plugin.json");
  75. // bundlePath is present, use resources from bundle
  76. return system::join(bundlePath, dirname + ".json");
  77. }
  78. // path to plugin files
  79. std::string pluginPath(const std::string& dirname) {
  80. // no bundlePath set, assume local source build
  81. if (bundlePath.empty())
  82. return system::join(systemDir, "..", "..", "plugins", "res", dirname);
  83. // bundlePath is present, use resources from bundle
  84. return system::join(systemDir, dirname);
  85. }
  86. }
  87. }