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.

Module.hpp 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #pragma once
  2. #include "common.hpp"
  3. #include "string.hpp"
  4. #include "plugin/Model.hpp"
  5. #include "engine/Param.hpp"
  6. #include "engine/Port.hpp"
  7. #include "engine/Light.hpp"
  8. #include <vector>
  9. #include <jansson.h>
  10. namespace rack {
  11. namespace plugin {
  12. struct Model;
  13. }
  14. namespace engine {
  15. struct Module {
  16. plugin::Model *model = NULL;
  17. /** Automatically generated by the engine. */
  18. int id = -1;
  19. /** Arrays of components */
  20. std::vector<Param> params;
  21. std::vector<Output> outputs;
  22. std::vector<Input> inputs;
  23. std::vector<Light> lights;
  24. /** Access to adjacent modules */
  25. int leftModuleId = -1;
  26. Module *leftModule = NULL;
  27. void *leftProducerMessage = NULL;
  28. void *leftConsumerMessage = NULL;
  29. int rightModuleId = -1;
  30. Module *rightModule = NULL;
  31. void *rightProducerMessage = NULL;
  32. void *rightConsumerMessage = NULL;
  33. /** For CPU meter. */
  34. float cpuTime = 0.f;
  35. bool bypass = false;
  36. /** Constructs a Module with no params, inputs, outputs, and lights. */
  37. Module();
  38. /** Use config() instead. */
  39. DEPRECATED Module(int numParams, int numInputs, int numOutputs, int numLights = 0) : Module() {
  40. config(numParams, numInputs, numOutputs, numLights);
  41. }
  42. virtual ~Module() {}
  43. /** Configures the number of Params, Outputs, Inputs, and Lights. */
  44. void config(int numParams, int numInputs, int numOutputs, int numLights = 0);
  45. json_t *toJson();
  46. void fromJson(json_t *rootJ);
  47. struct ProcessArgs {
  48. float sampleRate;
  49. float sampleTime;
  50. };
  51. /** Advances the module by one audio sample.
  52. Override this method to read Inputs and Params and to write Outputs and Lights.
  53. */
  54. virtual void process(const ProcessArgs &args) {
  55. #pragma GCC diagnostic push
  56. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  57. step();
  58. #pragma GCC diagnostic pop
  59. }
  60. /** Override process(const ProcessArgs &args) instead. */
  61. DEPRECATED virtual void step() {}
  62. /** Called when the engine sample rate is changed. */
  63. virtual void onSampleRateChange() {}
  64. /** Called when user clicks Initialize in the module context menu. */
  65. virtual void onReset() {}
  66. /** Called when user clicks Randomize in the module context menu. */
  67. virtual void onRandomize() {}
  68. /** Called when the Module is added to the Engine */
  69. virtual void onAdd() {}
  70. /** Called when the Module is removed from the Engine */
  71. virtual void onRemove() {}
  72. /** Override to store extra internal data in the "data" property of the module's JSON object. */
  73. virtual json_t *dataToJson() { return NULL; }
  74. virtual void dataFromJson(json_t *root) {}
  75. };
  76. } // namespace engine
  77. } // namespace rack