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.

161 lines
3.0KB

  1. #pragma once
  2. #include <map>
  3. #include <list>
  4. #include <vector>
  5. #include <string>
  6. #include <mutex>
  7. #include <thread>
  8. #include "util/common.hpp" // VIPMutex
  9. #ifdef USE_VST2
  10. class VSTPluginWrapper;
  11. #endif // USE_VST2
  12. namespace rack {
  13. struct Module;
  14. struct Wire;
  15. struct KeyboardDriver;
  16. struct MidiDriver;
  17. struct Plugin;
  18. #ifdef USE_VST2
  19. struct VSTMidiInputDevice;
  20. #define VST2_MAX_UNIQUE_PARAM_IDS (9999)
  21. #endif // USE_VST2
  22. //
  23. // the structure fields reflect the original file locations
  24. // (e.g. 'window' was originally located in 'window.cpp')
  25. //
  26. struct VST2QueuedParam {
  27. int unique_id;
  28. float value;
  29. bool b_normalized;
  30. };
  31. struct Global {
  32. bool gPaused;
  33. /** Plugins should not manipulate other modules or wires unless that is the entire purpose of the module.
  34. Your plugin needs to have a clear purpose for manipulating other modules and wires and must be done with a good UX.
  35. */
  36. std::vector<Module*> gModules;
  37. std::vector<Wire*> gWires;
  38. bool gPowerMeter;
  39. struct {
  40. bool running;
  41. float sampleRate;
  42. float sampleTime;
  43. // std::mutex mutex;
  44. std::recursive_mutex mutex;
  45. std::thread thread;
  46. VIPMutex vipMutex;
  47. // Parameter interpolation
  48. Module *smoothModule;
  49. int smoothParamId;
  50. float smoothValue;
  51. } engine;
  52. struct {
  53. std::string globalDir;
  54. std::string localDir;
  55. } asset;
  56. struct {
  57. KeyboardDriver *driver;
  58. } keyboard;
  59. struct {
  60. std::vector<int> driverIds;
  61. std::map<int, MidiDriver*> drivers;
  62. } midi;
  63. struct {
  64. std::list<Plugin*> gPlugins;
  65. std::string gToken;
  66. bool isDownloading;
  67. float downloadProgress;
  68. std::string downloadName;
  69. std::string loginStatus;
  70. } plugin;
  71. struct {
  72. bool gSkipAutosaveOnLaunch;
  73. } settings;
  74. struct {
  75. FILE *logFile;
  76. std::chrono::high_resolution_clock::time_point startTime;
  77. } logger;
  78. struct {
  79. uint64_t xoroshiro128plus_state[2] = {};
  80. } random;
  81. // struct {
  82. // } plugins;
  83. #ifdef USE_VST2
  84. struct {
  85. int last_seen_instance_count;
  86. const char *program_dir;
  87. float *const*inputs;
  88. float **outputs;
  89. unsigned int frame_idx;
  90. unsigned int last_seen_num_frames;
  91. VSTPluginWrapper *wrapper;
  92. VSTMidiInputDevice *midi_device;
  93. int next_unique_param_base_id;
  94. std::vector<VST2QueuedParam> queued_params;
  95. bool b_patch_loading;
  96. } vst2;
  97. #endif // USE_VST2
  98. void init(void) {
  99. gPaused = false;
  100. gPowerMeter = false;
  101. engine.running = false;
  102. engine.sampleRate = 44100.0f;
  103. engine.smoothModule = NULL;
  104. keyboard.driver = NULL;
  105. plugin.isDownloading = false;
  106. plugin.downloadProgress = 0.0;
  107. settings.gSkipAutosaveOnLaunch = false;
  108. logger.logFile = NULL;
  109. random.xoroshiro128plus_state[0] = 0;
  110. random.xoroshiro128plus_state[1] = 0;
  111. #ifdef USE_VST2
  112. vst2.midi_device = NULL;
  113. vst2.next_unique_param_base_id = 1;
  114. vst2.b_patch_loading = false;
  115. #endif
  116. }
  117. };
  118. } // namespace rack