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.

159 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. struct 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 norm_value;
  29. };
  30. struct Global {
  31. bool gPaused;
  32. /** Plugins should not manipulate other modules or wires unless that is the entire purpose of the module.
  33. Your plugin needs to have a clear purpose for manipulating other modules and wires and must be done with a good UX.
  34. */
  35. std::vector<Module*> gModules;
  36. std::vector<Wire*> gWires;
  37. bool gPowerMeter;
  38. struct {
  39. bool running;
  40. float sampleRate;
  41. float sampleTime;
  42. std::mutex mutex;
  43. std::thread thread;
  44. VIPMutex vipMutex;
  45. // Parameter interpolation
  46. Module *smoothModule;
  47. int smoothParamId;
  48. float smoothValue;
  49. } engine;
  50. struct {
  51. std::string globalDir;
  52. std::string localDir;
  53. } asset;
  54. struct {
  55. KeyboardDriver *driver;
  56. } keyboard;
  57. struct {
  58. std::vector<int> driverIds;
  59. std::map<int, MidiDriver*> drivers;
  60. } midi;
  61. struct {
  62. std::list<Plugin*> gPlugins;
  63. std::string gToken;
  64. bool isDownloading;
  65. float downloadProgress;
  66. std::string downloadName;
  67. std::string loginStatus;
  68. } plugin;
  69. struct {
  70. bool gSkipAutosaveOnLaunch;
  71. } settings;
  72. struct {
  73. FILE *logFile;
  74. std::chrono::high_resolution_clock::time_point startTime;
  75. } logger;
  76. struct {
  77. uint64_t xoroshiro128plus_state[2] = {};
  78. } random;
  79. // struct {
  80. // } plugins;
  81. #ifdef USE_VST2
  82. struct {
  83. int last_seen_instance_count;
  84. const char *program_dir;
  85. float *const*inputs;
  86. float **outputs;
  87. unsigned int frame_idx;
  88. unsigned int last_seen_num_frames;
  89. VSTPluginWrapper *wrapper;
  90. VSTMidiInputDevice *midi_device;
  91. int next_unique_param_base_id;
  92. std::vector<VST2QueuedParam> queued_params;
  93. bool b_patch_loading;
  94. } vst2;
  95. #endif // USE_VST2
  96. void init(void) {
  97. gPaused = false;
  98. gPowerMeter = false;
  99. engine.running = false;
  100. engine.sampleRate = 44100.0f;
  101. engine.smoothModule = NULL;
  102. keyboard.driver = NULL;
  103. plugin.isDownloading = false;
  104. plugin.downloadProgress = 0.0;
  105. settings.gSkipAutosaveOnLaunch = false;
  106. logger.logFile = NULL;
  107. random.xoroshiro128plus_state[0] = 0;
  108. random.xoroshiro128plus_state[1] = 0;
  109. #ifdef USE_VST2
  110. vst2.midi_device = NULL;
  111. vst2.next_unique_param_base_id = 1;
  112. vst2.b_patch_loading = false;
  113. #endif
  114. }
  115. };
  116. } // namespace rack