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.

128 lines
3.8KB

  1. #pragma once
  2. #include <string>
  3. #include <list>
  4. #include "tags.hpp"
  5. namespace rack {
  6. struct ModuleWidget;
  7. struct Module;
  8. struct Model;
  9. // Subclass this and return a pointer to a new one when init() is called
  10. struct Plugin {
  11. /** A list of the models available by this plugin, add with addModel() */
  12. std::list<Model*> models;
  13. /** The file path of the plugin's directory */
  14. std::string path;
  15. /** OS-dependent library handle */
  16. void *handle = NULL;
  17. /** Must be unique. Used for patch files and the VCV store API.
  18. To guarantee uniqueness, it is a good idea to prefix the slug by your "company name" if available, e.g. "MyCompany-MyPlugin"
  19. */
  20. std::string slug;
  21. /** The version of your plugin
  22. Plugins should follow the versioning scheme described at https://github.com/VCVRack/Rack/issues/266
  23. Do not include the "v" in "v1.0" for example.
  24. */
  25. std::string version;
  26. /** Deprecated, do not use. */
  27. std::string website;
  28. std::string manual;
  29. virtual ~Plugin();
  30. void addModel(Model *model);
  31. };
  32. struct Model {
  33. Plugin *plugin = NULL;
  34. /** An identifier for the model, e.g. "VCO". Used for saving patches. The slug, manufacturerSlug pair must be unique. */
  35. std::string slug;
  36. /** Human readable name for your model, e.g. "Voltage Controlled Oscillator" */
  37. std::string name;
  38. /** The name of the manufacturer group of the module.
  39. This might be different than the plugin slug. For example, if you create multiple plugins but want them to be branded similarly, you may use the same manufacturer name in multiple plugins.
  40. You may even have multiple manufacturers in one plugin, although this would be unusual.
  41. */
  42. std::string manufacturer;
  43. /** List of tags representing the function(s) of the module (optional) */
  44. std::list<ModelTag> tags;
  45. virtual ~Model() {}
  46. /** Creates a headless Module */
  47. virtual Module *createModule() { return NULL; }
  48. /** Creates a ModuleWidget with a Module attached */
  49. virtual ModuleWidget *createModuleWidget() { return NULL; }
  50. /** Creates a ModuleWidget with no Module, useful for previews */
  51. virtual ModuleWidget *createModuleWidgetNull() { return NULL; }
  52. /** Create Model subclass which constructs a specific Module and ModuleWidget subclass */
  53. template <typename TModule, typename TModuleWidget, typename... Tags>
  54. static Model *create(std::string manufacturer, std::string slug, std::string name, Tags... tags) {
  55. struct TModel : Model {
  56. Module *createModule() override {
  57. TModule *module = new TModule();
  58. return module;
  59. }
  60. ModuleWidget *createModuleWidget() override {
  61. TModule *module = new TModule();
  62. TModuleWidget *moduleWidget = new TModuleWidget(module);
  63. moduleWidget->model = this;
  64. return moduleWidget;
  65. }
  66. ModuleWidget *createModuleWidgetNull() override {
  67. TModuleWidget *moduleWidget = new TModuleWidget(NULL);
  68. moduleWidget->model = this;
  69. return moduleWidget;
  70. }
  71. };
  72. TModel *o = new TModel();
  73. o->manufacturer = manufacturer;
  74. o->slug = slug;
  75. o->name = name;
  76. o->tags = {tags...};
  77. return o;
  78. }
  79. };
  80. void pluginInit();
  81. void pluginDestroy();
  82. void pluginLogIn(std::string email, std::string password);
  83. void pluginLogOut();
  84. /** Returns whether a new plugin is available, and downloads it unless doing a dry run */
  85. bool pluginSync(bool dryRun);
  86. void pluginCancelDownload();
  87. bool pluginIsLoggedIn();
  88. bool pluginIsDownloading();
  89. float pluginGetDownloadProgress();
  90. std::string pluginGetDownloadName();
  91. std::string pluginGetLoginStatus();
  92. Plugin *pluginGetPlugin(std::string pluginSlug);
  93. Model *pluginGetModel(std::string pluginSlug, std::string modelSlug);
  94. extern std::list<Plugin*> gPlugins;
  95. extern std::string gToken;
  96. } // namespace rack
  97. ////////////////////
  98. // Implemented by plugin
  99. ////////////////////
  100. /** Called once to initialize and return the Plugin instance.
  101. You must implement this in your plugin
  102. */
  103. extern "C"
  104. void init(rack::Plugin *plugin);