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.

140 lines
3.9KB

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