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.

136 lines
3.8KB

  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. /** Mouse wheel zooms instead of pans. */
  34. extern bool mouseWheelZoom;
  35. /** Ratio between UI pixel and physical screen pixel.
  36. 0 for auto.
  37. */
  38. extern float pixelRatio;
  39. /** Name of UI theme, specified in ui::refreshTheme() */
  40. extern std::string uiTheme;
  41. /** Opacity of cables in the range [0, 1] */
  42. extern float cableOpacity;
  43. /** Straightness of cables in the range [0, 1]. Unitless and arbitrary. */
  44. extern float cableTension;
  45. extern float rackBrightness;
  46. extern float haloBrightness;
  47. /** Allows rack to hide and lock the cursor position when dragging knobs etc. */
  48. extern bool allowCursorLock;
  49. enum KnobMode {
  50. KNOB_MODE_LINEAR,
  51. KNOB_MODE_SCALED_LINEAR,
  52. KNOB_MODE_ROTARY_ABSOLUTE,
  53. KNOB_MODE_ROTARY_RELATIVE,
  54. };
  55. extern KnobMode knobMode;
  56. extern bool knobScroll;
  57. extern float knobLinearSensitivity;
  58. extern float knobScrollSensitivity;
  59. extern float sampleRate;
  60. extern int threadCount;
  61. extern bool tooltips;
  62. extern bool cpuMeter;
  63. extern bool lockModules;
  64. extern bool squeezeModules;
  65. extern bool preferDarkPanels;
  66. /** Maximum screen redraw frequency in Hz, or 0 for unlimited. */
  67. extern float frameRateLimit;
  68. /** Interval between autosaves in seconds. */
  69. extern float autosaveInterval;
  70. extern bool skipLoadOnLaunch;
  71. extern std::list<std::string> recentPatchPaths;
  72. extern std::vector<NVGcolor> cableColors;
  73. extern std::vector<std::string> cableLabels;
  74. extern bool cableAutoRotate;
  75. extern bool autoCheckUpdates;
  76. extern bool verifyHttpsCerts;
  77. extern bool showTipsOnLaunch;
  78. extern int tipIndex;
  79. enum BrowserSort {
  80. BROWSER_SORT_UPDATED,
  81. BROWSER_SORT_LAST_USED,
  82. BROWSER_SORT_MOST_USED,
  83. BROWSER_SORT_BRAND,
  84. BROWSER_SORT_NAME,
  85. BROWSER_SORT_RANDOM,
  86. };
  87. extern BrowserSort browserSort;
  88. extern float browserZoom;
  89. extern json_t* pluginSettingsJ;
  90. struct ModuleInfo {
  91. bool enabled = true;
  92. bool favorite = false;
  93. int added = 0;
  94. double lastAdded = NAN;
  95. };
  96. /** pluginSlug -> (moduleSlug -> ModuleInfo) */
  97. extern std::map<std::string, std::map<std::string, ModuleInfo>> moduleInfos;
  98. /** Returns a ModuleInfo if exists for the given slugs.
  99. */
  100. ModuleInfo* getModuleInfo(const std::string& pluginSlug, const std::string& moduleSlug);
  101. /** The VCV JSON API returns the data structure
  102. {pluginSlug: [moduleSlugs] or true}
  103. where "true" represents that the user is subscribed to the plugin (all modules and future modules).
  104. C++ isn't weakly typed, so we need the PluginWhitelist data structure to store this information.
  105. */
  106. struct PluginWhitelist {
  107. bool subscribed = false;
  108. std::set<std::string> moduleSlugs;
  109. };
  110. extern std::map<std::string, PluginWhitelist> moduleWhitelist;
  111. bool isModuleWhitelisted(const std::string& pluginSlug, const std::string& moduleSlug);
  112. void resetCables();
  113. PRIVATE void init();
  114. PRIVATE void destroy();
  115. PRIVATE json_t* toJson();
  116. PRIVATE void fromJson(json_t* rootJ);
  117. PRIVATE void save(std::string path = "");
  118. PRIVATE void load(std::string path = "");
  119. } // namespace settings
  120. } // namespace rack