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.

settings.hpp 3.7KB

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