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.

126 lines
3.4KB

  1. #pragma once
  2. #include <vector>
  3. #include <set>
  4. #include <map>
  5. #include <list>
  6. #include <tuple>
  7. #include <jansson.h>
  8. #include <common.hpp>
  9. #include <math.hpp>
  10. #include <color.hpp>
  11. namespace rack {
  12. /** Process-scope globals, most of which are persisted across launches */
  13. namespace settings {
  14. // Runtime state, not serialized.
  15. /** Path to settings.json */
  16. extern std::string settingsPath;
  17. extern bool devMode;
  18. extern bool headless;
  19. extern bool isPlugin;
  20. // Persistent state, serialized to settings.json.
  21. /** Launches Rack without loading plugins or the autosave patch. Always set to false when settings are saved. */
  22. extern bool safeMode;
  23. /** vcvrack.com user token */
  24. extern std::string token;
  25. /** Whether the window is maximized */
  26. extern bool windowMaximized;
  27. /** Size of window in pixels */
  28. extern math::Vec windowSize;
  29. /** Position in window in pixels */
  30. extern math::Vec windowPos;
  31. /** Reverse the zoom scroll direction */
  32. extern bool invertZoom;
  33. /** Ratio between UI pixel and physical screen pixel.
  34. 0 for auto.
  35. */
  36. extern float pixelRatio;
  37. /** Opacity of cables in the range [0, 1] */
  38. extern float cableOpacity;
  39. /** Straightness of cables in the range [0, 1]. Unitless and arbitrary. */
  40. extern float cableTension;
  41. extern float rackBrightness;
  42. extern float haloBrightness;
  43. /** Allows rack to hide and lock the cursor position when dragging knobs etc. */
  44. extern bool allowCursorLock;
  45. enum KnobMode {
  46. KNOB_MODE_LINEAR,
  47. KNOB_MODE_SCALED_LINEAR,
  48. KNOB_MODE_ROTARY_ABSOLUTE,
  49. KNOB_MODE_ROTARY_RELATIVE,
  50. };
  51. extern KnobMode knobMode;
  52. extern bool knobScroll;
  53. extern float knobLinearSensitivity;
  54. extern float knobScrollSensitivity;
  55. extern float sampleRate;
  56. extern int threadCount;
  57. extern bool tooltips;
  58. extern bool cpuMeter;
  59. extern bool lockModules;
  60. extern bool squeezeModules;
  61. /** Maximum screen redraw frequency in Hz, or 0 for unlimited. */
  62. extern float frameRateLimit;
  63. extern float autosaveInterval;
  64. extern bool skipLoadOnLaunch;
  65. extern std::list<std::string> recentPatchPaths;
  66. extern std::vector<NVGcolor> cableColors;
  67. extern bool autoCheckUpdates;
  68. extern bool showTipsOnLaunch;
  69. extern int tipIndex;
  70. enum BrowserSort {
  71. BROWSER_SORT_UPDATED,
  72. BROWSER_SORT_LAST_USED,
  73. BROWSER_SORT_MOST_USED,
  74. BROWSER_SORT_BRAND,
  75. BROWSER_SORT_NAME,
  76. BROWSER_SORT_RANDOM,
  77. };
  78. extern BrowserSort browserSort;
  79. extern float browserZoom;
  80. extern json_t* pluginSettingsJ;
  81. struct ModuleInfo {
  82. bool enabled = true;
  83. bool favorite = false;
  84. int added = 0;
  85. double lastAdded = NAN;
  86. };
  87. /** pluginSlug -> (moduleSlug -> ModuleInfo) */
  88. extern std::map<std::string, std::map<std::string, ModuleInfo>> moduleInfos;
  89. /** Returns a ModuleInfo if exists for the given slugs.
  90. */
  91. ModuleInfo* getModuleInfo(const std::string& pluginSlug, const std::string& moduleSlug);
  92. /** The VCV JSON API returns the data structure
  93. {pluginSlug: [moduleSlugs] or true}
  94. where "true" represents that the user is subscribed to the plugin (all modules and future modules).
  95. C++ isn't weakly typed, so we need the PluginWhitelist data structure to store this information.
  96. */
  97. struct PluginWhitelist {
  98. bool subscribed = false;
  99. std::set<std::string> moduleSlugs;
  100. };
  101. extern std::map<std::string, PluginWhitelist> moduleWhitelist;
  102. bool isModuleWhitelisted(const std::string& pluginSlug, const std::string& moduleSlug);
  103. PRIVATE void init();
  104. PRIVATE void destroy();
  105. PRIVATE json_t* toJson();
  106. PRIVATE void fromJson(json_t* rootJ);
  107. PRIVATE void save(std::string path = "");
  108. PRIVATE void load(std::string path = "");
  109. } // namespace settings
  110. } // namespace rack