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.

144 lines
4.1KB

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