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.

130 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.
  35. The model slug must be unique in your plugin, but it doesn't need to be unique among different plugins.
  36. */
  37. std::string slug;
  38. /** Human readable name for your model, e.g. "Voltage Controlled Oscillator" */
  39. std::string name;
  40. /** The author name of the module.
  41. 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 author in multiple plugins.
  42. You may even have multiple authors in one plugin, although this property will be moved to Plugin for Rack 1.0.
  43. */
  44. std::string author;
  45. /** List of tags representing the function(s) of the module (optional) */
  46. std::list<ModelTag> tags;
  47. virtual ~Model() {}
  48. /** Creates a headless Module */
  49. virtual Module *createModule() { return NULL; }
  50. /** Creates a ModuleWidget with a Module attached */
  51. virtual ModuleWidget *createModuleWidget() { return NULL; }
  52. /** Creates a ModuleWidget with no Module, useful for previews */
  53. virtual ModuleWidget *createModuleWidgetNull() { return NULL; }
  54. /** Create Model subclass which constructs a specific Module and ModuleWidget subclass */
  55. template <typename TModule, typename TModuleWidget, typename... Tags>
  56. static Model *create(std::string author, std::string slug, std::string name, Tags... tags) {
  57. struct TModel : Model {
  58. Module *createModule() override {
  59. TModule *module = new TModule();
  60. return module;
  61. }
  62. ModuleWidget *createModuleWidget() override {
  63. TModule *module = new TModule();
  64. TModuleWidget *moduleWidget = new TModuleWidget(module);
  65. moduleWidget->model = this;
  66. return moduleWidget;
  67. }
  68. ModuleWidget *createModuleWidgetNull() override {
  69. TModuleWidget *moduleWidget = new TModuleWidget(NULL);
  70. moduleWidget->model = this;
  71. return moduleWidget;
  72. }
  73. };
  74. TModel *o = new TModel();
  75. o->author = author;
  76. o->slug = slug;
  77. o->name = name;
  78. o->tags = {tags...};
  79. return o;
  80. }
  81. };
  82. void pluginInit(bool devMode);
  83. void pluginDestroy();
  84. void pluginLogIn(std::string email, std::string password);
  85. void pluginLogOut();
  86. /** Returns whether a new plugin is available, and downloads it unless doing a dry run */
  87. bool pluginSync(bool dryRun);
  88. void pluginCancelDownload();
  89. bool pluginIsLoggedIn();
  90. bool pluginIsDownloading();
  91. float pluginGetDownloadProgress();
  92. std::string pluginGetDownloadName();
  93. std::string pluginGetLoginStatus();
  94. Plugin *pluginGetPlugin(std::string pluginSlug);
  95. Model *pluginGetModel(std::string pluginSlug, std::string modelSlug);
  96. extern std::list<Plugin*> gPlugins;
  97. extern std::string gToken;
  98. } // namespace rack
  99. ////////////////////
  100. // Implemented by plugin
  101. ////////////////////
  102. /** Called once to initialize and return the Plugin instance.
  103. You must implement this in your plugin
  104. */
  105. extern "C"
  106. void init(rack::Plugin *plugin);