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.

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