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.

142 lines
4.0KB

  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::string lastPatchDirectory;
  76. extern std::string lastSelectionDirectory;
  77. extern std::list<std::string> recentPatchPaths;
  78. extern std::vector<NVGcolor> cableColors;
  79. extern std::vector<std::string> cableLabels;
  80. extern bool cableAutoRotate;
  81. extern bool autoCheckUpdates;
  82. extern bool verifyHttpsCerts;
  83. extern bool showTipsOnLaunch;
  84. extern int tipIndex;
  85. enum BrowserSort {
  86. BROWSER_SORT_UPDATED,
  87. BROWSER_SORT_LAST_USED,
  88. BROWSER_SORT_MOST_USED,
  89. BROWSER_SORT_BRAND,
  90. BROWSER_SORT_NAME,
  91. BROWSER_SORT_RANDOM,
  92. };
  93. extern BrowserSort browserSort;
  94. extern float browserZoom;
  95. extern json_t* pluginSettingsJ;
  96. struct ModuleInfo {
  97. bool enabled = true;
  98. bool favorite = false;
  99. int added = 0;
  100. double lastAdded = NAN;
  101. };
  102. /** pluginSlug -> (moduleSlug -> ModuleInfo) */
  103. extern std::map<std::string, std::map<std::string, ModuleInfo>> moduleInfos;
  104. /** Returns a ModuleInfo if exists for the given slugs.
  105. */
  106. ModuleInfo* getModuleInfo(const std::string& pluginSlug, const std::string& moduleSlug);
  107. /** The VCV JSON API returns the data structure
  108. {pluginSlug: [moduleSlugs] or true}
  109. where "true" represents that the user is subscribed to the plugin (all modules and future modules).
  110. C++ isn't weakly typed, so we need the PluginWhitelist data structure to store this information.
  111. */
  112. struct PluginWhitelist {
  113. bool subscribed = false;
  114. std::set<std::string> moduleSlugs;
  115. };
  116. extern std::map<std::string, PluginWhitelist> moduleWhitelist;
  117. bool isModuleWhitelisted(const std::string& pluginSlug, const std::string& moduleSlug);
  118. void resetCables();
  119. PRIVATE void init();
  120. PRIVATE void destroy();
  121. PRIVATE json_t* toJson();
  122. PRIVATE void fromJson(json_t* rootJ);
  123. PRIVATE void save(std::string path = "");
  124. PRIVATE void load(std::string path = "");
  125. } // namespace settings
  126. } // namespace rack